@Test public void testGetOrMaxKey() { Map<Integer, Integer> map = new HashMap<>(16); map.put(1, 10); map.put(2, 15); map.put(3, 20); map.put(4, 25); map.put(5, 30); map.put(10, 100); assertTrue(MapUtils.getOrMaxKey(map, 1) == 10); assertTrue(MapUtils.getOrMaxKey(map, 2) == 15); assertTrue(MapUtils.getOrMaxKey(map, 4) == 25); assertTrue(MapUtils.getOrMaxKey(map, 5) == 30); assertTrue(MapUtils.getOrMaxKey(map, 6) == 30); assertTrue(MapUtils.getOrMaxKey(map, 12) == 100); }
public static <V> V getOrMaxKey(final Map<Integer, V> map, Integer key) { V v = map.get(key); if (v != null) { return v; } return map.entrySet().stream().filter(x -> x.getKey() < key).max(Comparator.comparing(Map.Entry::getKey)).map(Map.Entry::getValue).orElse(null); }
MapUtils { public static <V> V getOrMaxKey(final Map<Integer, V> map, Integer key) { V v = map.get(key); if (v != null) { return v; } return map.entrySet().stream().filter(x -> x.getKey() < key).max(Comparator.comparing(Map.Entry::getKey)).map(Map.Entry::getValue).orElse(null); } }
MapUtils { public static <V> V getOrMaxKey(final Map<Integer, V> map, Integer key) { V v = map.get(key); if (v != null) { return v; } return map.entrySet().stream().filter(x -> x.getKey() < key).max(Comparator.comparing(Map.Entry::getKey)).map(Map.Entry::getValue).orElse(null); }  }
MapUtils { public static <V> V getOrMaxKey(final Map<Integer, V> map, Integer key) { V v = map.get(key); if (v != null) { return v; } return map.entrySet().stream().filter(x -> x.getKey() < key).max(Comparator.comparing(Map.Entry::getKey)).map(Map.Entry::getValue).orElse(null); }  static boolean isEmpty(final Map<?, ?> map); static boolean isNotEmpty(final Map<?, ?> map); static HashMap<K, V> of(K key, V value); static V getOrMaxKey(final Map<Integer, V> map, Integer key); @Deprecated static void add(Map<K, Integer> source, Map<K, Integer> value); static void addByIntValue(Map<K, Integer> source, Map<K, Integer> value); static void addByLongValue(Map<K, Long> source, Map<K, Long> value); static Integer addValue(Map<K, Integer> source, K key, int value); static Long addValue(Map<K, Long> source, K key, long value); static Float addValue(Map<K, Float> source, K key, float value); static Double addValue(Map<K, Double> source, K key, double value); @SafeVarargs static double getRatioValue(Map<K, Long> map, double ratio, K... keys); @SafeVarargs static double getPermillageValue(Map<K, Long> map, K... keys); @SafeVarargs static double getPercentageValue(Map<K, Long> map, K... keys); }
MapUtils { public static <V> V getOrMaxKey(final Map<Integer, V> map, Integer key) { V v = map.get(key); if (v != null) { return v; } return map.entrySet().stream().filter(x -> x.getKey() < key).max(Comparator.comparing(Map.Entry::getKey)).map(Map.Entry::getValue).orElse(null); }  static boolean isEmpty(final Map<?, ?> map); static boolean isNotEmpty(final Map<?, ?> map); static HashMap<K, V> of(K key, V value); static V getOrMaxKey(final Map<Integer, V> map, Integer key); @Deprecated static void add(Map<K, Integer> source, Map<K, Integer> value); static void addByIntValue(Map<K, Integer> source, Map<K, Integer> value); static void addByLongValue(Map<K, Long> source, Map<K, Long> value); static Integer addValue(Map<K, Integer> source, K key, int value); static Long addValue(Map<K, Long> source, K key, long value); static Float addValue(Map<K, Float> source, K key, float value); static Double addValue(Map<K, Double> source, K key, double value); @SafeVarargs static double getRatioValue(Map<K, Long> map, double ratio, K... keys); @SafeVarargs static double getPermillageValue(Map<K, Long> map, K... keys); @SafeVarargs static double getPercentageValue(Map<K, Long> map, K... keys);  }