collection.go 729 B

123456789101112131415161718192021222324
  1. package semver
  2. // Collection is a collection of Version instances and implements the sort
  3. // interface. See the sort package for more details.
  4. // https://golang.org/pkg/sort/
  5. type Collection []*Version
  6. // Len returns the length of a collection. The number of Version instances
  7. // on the slice.
  8. func (c Collection) Len() int {
  9. return len(c)
  10. }
  11. // Less is needed for the sort interface to compare two Version objects on the
  12. // slice. If checks if one is less than the other.
  13. func (c Collection) Less(i, j int) bool {
  14. return c[i].LessThan(c[j])
  15. }
  16. // Swap is needed for the sort interface to replace the Version objects
  17. // at two different positions in the slice.
  18. func (c Collection) Swap(i, j int) {
  19. c[i], c[j] = c[j], c[i]
  20. }