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