2018-02-05 16:05:59 -05:00
|
|
|
package container // import "github.com/docker/docker/container"
|
2014-04-07 14:01:35 -04:00
|
|
|
|
2016-01-15 18:55:46 -05:00
|
|
|
import "sort"
|
2014-04-07 14:01:35 -04:00
|
|
|
|
|
|
|
// History is a convenience type for storing a list of containers,
|
2016-01-15 18:55:46 -05:00
|
|
|
// sorted by creation date in descendant order.
|
|
|
|
type History []*Container
|
2014-04-07 14:01:35 -04:00
|
|
|
|
2016-01-15 18:55:46 -05:00
|
|
|
// Len returns the number of containers in the history.
|
2014-04-07 14:01:35 -04:00
|
|
|
func (history *History) Len() int {
|
|
|
|
return len(*history)
|
|
|
|
}
|
|
|
|
|
2016-01-15 18:55:46 -05:00
|
|
|
// Less compares two containers and returns true if the second one
|
|
|
|
// was created before the first one.
|
2014-04-07 14:01:35 -04:00
|
|
|
func (history *History) Less(i, j int) bool {
|
|
|
|
containers := *history
|
2014-04-14 02:54:40 -04:00
|
|
|
return containers[j].Created.Before(containers[i].Created)
|
2014-04-07 14:01:35 -04:00
|
|
|
}
|
|
|
|
|
2016-01-15 18:55:46 -05:00
|
|
|
// Swap switches containers i and j positions in the history.
|
2014-04-07 14:01:35 -04:00
|
|
|
func (history *History) Swap(i, j int) {
|
|
|
|
containers := *history
|
2015-03-24 17:11:04 -04:00
|
|
|
containers[i], containers[j] = containers[j], containers[i]
|
2014-04-07 14:01:35 -04:00
|
|
|
}
|
|
|
|
|
2016-01-15 18:55:46 -05:00
|
|
|
// sort orders the history by creation date in descendant order.
|
2015-07-30 17:01:53 -04:00
|
|
|
func (history *History) sort() {
|
2014-04-07 14:01:35 -04:00
|
|
|
sort.Sort(history)
|
|
|
|
}
|