### Question:
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);  }### Answer:
@Test public void testMatching1() { assertTrue(CollectionUtils.matching(list, Pet::getExp, 0L).orElse(null).getId() == 0); assertTrue(CollectionUtils.matching(list, Pet::getExp, 1L).orElse(null).getId() == 1); assertTrue(CollectionUtils.matching(list, Pet::getExp, 25L).orElse(null).getId() == 5); assertTrue(CollectionUtils.matching(list, Pet::getExp, 100000L).orElse(null).getId() == 19); }
@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); }