Collections.js 666 B

1234567891011121314151617181920212223242526272829303132333435
  1. import Arrays from './Arrays'
  2. import ArrayList from './ArrayList'
  3. const Collections = {
  4. reverseOrder: function() {
  5. return {
  6. compare(a, b) {
  7. return b.compareTo(a)
  8. }
  9. }
  10. },
  11. min: function(l) {
  12. Collections.sort(l)
  13. return l.get(0)
  14. },
  15. sort: function(l, c) {
  16. const a = l.toArray()
  17. if (c)
  18. Arrays.sort(a, c)
  19. else
  20. Arrays.sort(a)
  21. const i = l.iterator()
  22. for (let pos = 0, alen = a.length; pos < alen; pos++) {
  23. i.next()
  24. i.set(a[pos])
  25. }
  26. },
  27. singletonList: function(o) {
  28. const arrayList = new ArrayList()
  29. arrayList.add(o)
  30. return arrayList
  31. }
  32. }
  33. export default Collections