@Test public void testMatching2() { assertTrue(CollectionUtils.matching(list, Pet::getLevel, 0).orElse(null).getId() == 0); assertTrue(CollectionUtils.matching(list, Pet::getLevel, 1).orElse(null).getId() == 0); assertTrue(CollectionUtils.matching(list, Pet::getLevel, 25).orElse(null).getId() == 12); assertTrue(CollectionUtils.matching(list, Pet::getLevel, 100000).orElse(null).getId() == 19); }
public static <V> Optional<V> matching(final Collection<V> collection, Function<V, ? extends Long> keyMapper, long value) { return collection.stream().filter(v -> keyMapper.apply(v) <= value).max(Comparator.comparing(keyMapper)); }
CollectionUtils { public static <V> Optional<V> matching(final Collection<V> collection, Function<V, ? extends Long> keyMapper, long value) { return collection.stream().filter(v -> keyMapper.apply(v) <= value).max(Comparator.comparing(keyMapper)); } }
CollectionUtils { public static <V> Optional<V> matching(final Collection<V> collection, Function<V, ? extends Long> keyMapper, long value) { return collection.stream().filter(v -> keyMapper.apply(v) <= value).max(Comparator.comparing(keyMapper)); }  }
CollectionUtils { public static <V> Optional<V> matching(final Collection<V> collection, Function<V, ? extends Long> keyMapper, long value) { return collection.stream().filter(v -> keyMapper.apply(v) <= value).max(Comparator.comparing(keyMapper)); }  static boolean isEmpty(final Collection<?> collection); static boolean isNotEmpty(final Collection<?> collection); static Map<K, List<V>> groupingBy(final Collection<V> collection, Function<? super V, ? extends K> keyMapper); static PairMap<L, R, List<V>> groupingBy(final Collection<V> collection, Function<? super V, ? extends L> leftMapper, Function<? super V, ? extends R> rightMapper); static Optional<V> matching(final Collection<V> collection, Function<V, ? extends Long> keyMapper, long value); static Optional<V> matching(final Collection<V> collection, Function<V, ? extends Integer> keyMapper, int value); static int sumByInt(Collection<Integer> collection); static long sumByLong(Collection<Long> collection); }
CollectionUtils { public static <V> Optional<V> matching(final Collection<V> collection, Function<V, ? extends Long> keyMapper, long value) { return collection.stream().filter(v -> keyMapper.apply(v) <= value).max(Comparator.comparing(keyMapper)); }  static boolean isEmpty(final Collection<?> collection); static boolean isNotEmpty(final Collection<?> collection); static Map<K, List<V>> groupingBy(final Collection<V> collection, Function<? super V, ? extends K> keyMapper); static PairMap<L, R, List<V>> groupingBy(final Collection<V> collection, Function<? super V, ? extends L> leftMapper, Function<? super V, ? extends R> rightMapper); static Optional<V> matching(final Collection<V> collection, Function<V, ? extends Long> keyMapper, long value); static Optional<V> matching(final Collection<V> collection, Function<V, ? extends Integer> keyMapper, int value); static int sumByInt(Collection<Integer> collection); static long sumByLong(Collection<Long> collection);  }