forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_sorter.go
38 lines (32 loc) · 915 Bytes
/
container_sorter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package hijackhelpers
import (
"strings"
"github.com/concourse/atc"
)
type ContainerSorter []atc.Container
func (sorter ContainerSorter) Len() int {
return len(sorter)
}
func (sorter ContainerSorter) Swap(i, j int) {
sorter[i], sorter[j] = sorter[j], sorter[i]
}
func (sorter ContainerSorter) Less(i, j int) bool {
switch {
case sorter[i].BuildID < sorter[j].BuildID:
return true
case sorter[i].BuildID > sorter[j].BuildID:
return false
case strings.Compare(sorter[i].ResourceName, sorter[j].ResourceName) == -1:
return true
case strings.Compare(sorter[i].ResourceName, sorter[j].ResourceName) == 1:
return false
case strings.Compare(sorter[i].StepName, sorter[j].StepName) == -1:
return true
case strings.Compare(sorter[i].StepName, sorter[j].StepName) == 1:
return false
case strings.Compare(sorter[i].StepType, sorter[j].StepType) == -1:
return true
default:
return false
}
}