public static < T, V1 extends Comparable<? super V1>, V2 extends Comparable<? super V2>, V3 extends Comparable<? super V3>> SerializableComparator<T> fromFunctions( Function<? super T, ? extends V1> one, Function<? super T, ? extends V2> two, Function<? super T, ? extends V3> three) { return Comparators.chain( Comparators.<T, V1>byFunction(one), Comparators.<T, V2>byFunction(two), Comparators.<T, V3>byFunction(three)); }
@Override @Test public void toSortedBagBy() { ImmutableBag<String> immutableBag = this.newBag(); MutableSortedBag<String> sortedBag = immutableBag.toSortedBagBy(String::valueOf); TreeBag<Object> expectedBag = TreeBag.newBag(Comparators.byFunction(String::valueOf)); Verify.assertSortedBagsEqual(expectedBag, sortedBag); }
@Test public void toSortedBagBy_empty() { ImmutableBag<Integer> immutableBag = Bags.immutable.of(); Function<Integer, Integer> function = object -> object * -1; MutableSortedBag<Integer> sortedBag = immutableBag.toSortedBagBy(function); sortedBag.addOccurrences(1, 3); sortedBag.addOccurrences(10, 2); Verify.assertSortedBagsEqual( TreeBag.newBagWith(Comparators.byFunction(function), 10, 10, 1, 1, 1), sortedBag); }
public static <T, V extends Comparable<? super V>> SerializableComparator<T> byFunction( Function<? super T, ? extends V> function) { if (function instanceof IntFunction) { return Functions.toIntComparator((IntFunction<T>) function); } if (function instanceof DoubleFunction) { return Functions.toDoubleComparator((DoubleFunction<T>) function); } if (function instanceof LongFunction) { return Functions.toLongComparator((LongFunction<T>) function); } return Comparators.byFunction(function, naturalOrder()); }
public <V extends Comparable<? super V>> T maxBy(Function<? super T, ? extends V> function) { return Iterate.max(this, Comparators.byFunction(function)); }
public <V extends Comparable<? super V>> MutableSortedSet<T> toSortedSetBy( Function<? super T, ? extends V> function) { return this.toSortedSet(Comparators.byFunction(function)); }
public static <T, V extends Comparable<? super V>> SerializableComparator<T> fromFunctions( Function<? super T, ? extends V> one) { return Comparators.byFunction(one); }