Пример #1
0
 @SuppressWarnings("unchecked")
 @Override
 public Array<T> sorted(Comparator<? super T> comparator) {
   final Object[] arr = toArray(this);
   Arrays.sort(arr, (o1, o2) -> comparator.compare((T) o1, (T) o2));
   return wrap(arr);
 }
Пример #2
0
 @Override
 public <U> Array<T> sortBy(
     Comparator<? super U> comparator, Function<? super T, ? extends U> mapper) {
   final Function<? super T, ? extends U> domain = Function1.of(mapper::apply).memoized();
   return toJavaStream()
       .sorted((e1, e2) -> comparator.compare(domain.apply(e1), domain.apply(e2)))
       .collect(collector());
 }
Пример #3
0
 private static Comparator<Integer> composedComparator() {
   final Comparator<Integer> bitCountComparator =
       (o1, o2) -> Integer.compare(bitCount(o1), bitCount(o2));
   return bitCountComparator.thenComparing(naturalComparator());
 }