Package com.jalios.util
Class MapUtils
- java.lang.Object
-
- com.jalios.util.MapUtils
-
public final class MapUtils extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MapUtils.ConcurrentMapBuilder<K,V>
static class
MapUtils.MapBuilder<K,V>
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
MapUtils.MapBuilder<K,V>builder()
Create a new MapBuilder.static <K,V>
MapUtils.MapBuilder<K,V>builder(java.util.Map<K,V> map)
Create a new MapBuilder initialized with the given Map.
Usage :static <K,V>
MapUtils.ConcurrentMapBuilder<K,V>concurrentBuilder()
Create a new ConcurrentMapBuilder.static <K,V>
MapUtils.ConcurrentMapBuilder<K,V>concurrentBuilder(java.util.concurrent.ConcurrentMap<K,V> map)
Create a new ConcurrentMapBuilder initialized with the given ConcurrentMap.static <K,V>
java.util.Map<K,V>filterMap(java.util.Map<K,V> map, java.util.function.Predicate<java.util.Map.Entry<K,V>> predicate)
Filter the given map according to the condition defined by the given Predicate.
Usage:
-
-
-
Method Detail
-
filterMap
public static <K,V> java.util.Map<K,V> filterMap(java.util.Map<K,V> map, java.util.function.Predicate<java.util.Map.Entry<K,V>> predicate)
Filter the given map according to the condition defined by the given Predicate.
Usage:Map<Integer, String> map = MapUtils<Integer, String>.builder() .put(new Integer(1), "January") .put(new Integer(2), "February") .put(new Integer(3), "March") .put(new Integer(4), "April") .put(new Integer(5), "May") .put(new Integer(6), "June") .put(new Integer(7), "July") .put(new Integer(8), "August") .put(new Integer(9), "September") .put(new Integer(10), "October") .put(new Integer(11), "November") .put(new Integer(12), "December") .build(); Map<Integer, String> filterMap1 = MapUtils.filterMap(mapBuilder.build(), (entry) -> { } String v = entry.getValue(); return v.length() == 4; ); Map<Integer, String> filterMap2 = MapUtils.filterMap(mapBuilder.build(), (entry) -> { } Integer k = entry.getKey(); return k > 4 && k < 8; );
- filterMap1:
{6=June, 7=July}
- filterMap2:
{5=May, 6=June, 7=July}
- Parameters:
map
- map to filterpredicate
- Predicate- Returns:
- Filtered Map
- filterMap1:
-
builder
public static <K,V> MapUtils.MapBuilder<K,V> builder()
Create a new MapBuilder. The type ofMap
implementation used is HashMap.
Usage :Map<Integer, String> map = MapUtils.<Integer, String>builder() .put(new Integer(1), "January") .put(new Integer(2), "February") .put(new Integer(3), "March") .put(new Integer(4), "April") .put(new Integer(5), "May") .put(new Integer(6), "June") .put(new Integer(7), "July") .put(new Integer(8), "August") .put(new Integer(9), "September") .put(new Integer(10), "October") .put(new Integer(11), "November") .put(new Integer(12), "December") .build();
- Returns:
- MapBuilder
-
builder
public static <K,V> MapUtils.MapBuilder<K,V> builder(java.util.Map<K,V> map)
Create a new MapBuilder initialized with the given Map.
Usage :Map<Integer, String> map = MapUtils.<Integer, String>builder(new LinkedHashMap<>()) .put(new Integer(1), "January") .put(new Integer(2), "February") .put(new Integer(3), "March") .put(new Integer(4), "April") .put(new Integer(5), "May") .put(new Integer(6), "June") .put(new Integer(7), "July") .put(new Integer(8), "August") .put(new Integer(9), "September") .put(new Integer(10), "October") .put(new Integer(11), "November") .put(new Integer(12), "December") .build();
- Parameters:
map
- Map to initialize the MapBuilder with a specific Map- Returns:
- MapBuilder
-
concurrentBuilder
public static <K,V> MapUtils.ConcurrentMapBuilder<K,V> concurrentBuilder()
Create a new ConcurrentMapBuilder. The type ofMap
implementation used is ConcurrentHashMap.- Returns:
- ConcurrentMapBuilder
-
concurrentBuilder
public static <K,V> MapUtils.ConcurrentMapBuilder<K,V> concurrentBuilder(java.util.concurrent.ConcurrentMap<K,V> map)
Create a new ConcurrentMapBuilder initialized with the given ConcurrentMap.- Parameters:
map
- Map to initialize the MapBuilder with a specific ConcurrentMap- Returns:
- ConcurrentMapBuilder
-
-