CombinedComparatorImpl implements CombinedComparator<ENTITY> { @Override public Comparator<ENTITY> thenComparingLong(ToLongFunction<? super ENTITY> keyExtractor) { if (keyExtractor instanceof Getter) { @SuppressWarnings("unchecked") final Getter<ENTITY> getter = (Getter<ENTITY>) keyExtractor; final Optional<Comparator<ENTITY>> result = then(getter); if (result.isPresent()) { return result.get(); } } return (a, b) -> { final int c = compare(a, b); if (c == 0) { final long oa = keyExtractor.applyAsLong(a); final long ob = keyExtractor.applyAsLong(b); return Long.compare(oa, ob); } else return c; }; } CombinedComparatorImpl(
            final List<FieldComparator<? super ENTITY>> comparators); @Override Stream<FieldComparator<? super ENTITY>> stream(); @Override int size(); @Override int compare(ENTITY o1, ENTITY o2); @Override CombinedComparator<ENTITY> reversed(); @Override Comparator<ENTITY> thenComparing(Comparator<? super ENTITY> other); @Override Comparator<ENTITY> thenComparing(
            final Function<? super ENTITY, ? extends U> keyExtractor,
            final Comparator<? super U> keyComparator); @Override Comparator<ENTITY> thenComparing(Function<? super ENTITY, ? extends U> keyExtractor); @Override Comparator<ENTITY> thenComparingInt(ToIntFunction<? super ENTITY> keyExtractor); @Override Comparator<ENTITY> thenComparingLong(ToLongFunction<? super ENTITY> keyExtractor); @Override Comparator<ENTITY> thenComparingDouble(ToDoubleFunction<? super ENTITY> keyExtractor); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test void thenComparingLong() throws Exception { comparatorsAndReverses().forEachOrdered(comp1 -> { final Comparator<Entity> mock1 = mockComparator( comp1.getField(), comp1.getNullOrder(), comp1.isReversed() ); final Comparator<Entity> mock = mock1.thenComparingLong(Entity.LONG.getter()); final Comparator<Entity> comp = comp1.thenComparingLong(Entity.LONG.getter()); final List<Entity> expected = list.stream().sorted(mock).collect(toList()); final List<Entity> actual = list.stream().sorted(comp).collect(toList()); assertEquals(actual, expected, format("Compare %s then %s using %s", comp1.getField().identifier().getColumnId(), Entity.LONG.identifier().getColumnId(), comp ) ); }); }