2014-04-17 17:43:01 -04:00
|
|
|
package daemon
|
2014-04-07 14:01:35 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
2015-11-12 14:55:17 -05:00
|
|
|
|
|
|
|
"github.com/docker/docker/container"
|
2014-04-07 14:01:35 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// History is a convenience type for storing a list of containers,
|
|
|
|
// ordered by creation date.
|
2015-11-12 14:55:17 -05:00
|
|
|
type History []*container.Container
|
2014-04-07 14:01:35 -04:00
|
|
|
|
|
|
|
func (history *History) Len() int {
|
|
|
|
return len(*history)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-07-30 17:01:53 -04:00
|
|
|
// Add the given container to history.
|
2015-11-12 14:55:17 -05:00
|
|
|
func (history *History) Add(container *container.Container) {
|
2014-04-07 14:01:35 -04:00
|
|
|
*history = append(*history, container)
|
2014-05-14 07:17:58 -04:00
|
|
|
}
|
|
|
|
|
2015-07-30 17:01:53 -04:00
|
|
|
func (history *History) sort() {
|
2014-04-07 14:01:35 -04:00
|
|
|
sort.Sort(history)
|
|
|
|
}
|