|
|
@@ -127,26 +127,94 @@ public class MapUtils {
|
|
|
return new MMapWrapper<>(map, getter, setter);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns read-only view which filters keys and maps them by provided function
|
|
|
+ *
|
|
|
+ * At access time it checks if provided key is accepted by "acceptor"
|
|
|
+ * At access time it maps accepted key by "function" and returns value from source map.
|
|
|
+ *
|
|
|
+ * @param content content
|
|
|
+ * @param acceptor acceptor
|
|
|
+ * @param function function
|
|
|
+ * @param <K> K
|
|
|
+ * @param <V> V
|
|
|
+ * @return view
|
|
|
+ */
|
|
|
public static <K,V> Map<K,V> keyproxy(Supplier<Map<K, V>> content, Predicate<Object> acceptor, Function<K, K> function) {
|
|
|
return new KeyMapAdapter<>(content, acceptor, function);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * It cretes read-only view of map which keys are created by provided functions.
|
|
|
+ * Maps keys at access time, before lookup.
|
|
|
+ *
|
|
|
+ * @param map map
|
|
|
+ * @param keyMapper keyMapper
|
|
|
+ * @param <TK> TK
|
|
|
+ * @param <RK> RK
|
|
|
+ * @param <V> V
|
|
|
+ * @return view
|
|
|
+ */
|
|
|
public static <TK, RK, V> Map<RK,V> view(Map<TK, ? extends V> map, Function<TK, RK> keyMapper) {
|
|
|
return view(map, keyMapper, Function.identity());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * It cretes read-only view of map which keys and values are created by provided functions.
|
|
|
+ * Maps keys at access time, before lookup.
|
|
|
+ * Maps values at access time, after lookup.
|
|
|
+ *
|
|
|
+ * @param map map
|
|
|
+ * @param keyMapper keyMapper
|
|
|
+ * @param valueMapper valueMapper
|
|
|
+ * @param <TK> TK
|
|
|
+ * @param <RK> RK
|
|
|
+ * @param <TV> TV
|
|
|
+ * @param <RV> RV
|
|
|
+ * @return view
|
|
|
+ */
|
|
|
public static <TK, RK, TV, RV> Map<RK, RV> view(Map<TK,? extends TV> map, Function<TK, RK> keyMapper, Function<TV, RV> valueMapper) {
|
|
|
return new ViewAdapter<>(map, keyMapper, valueMapper);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns synchronized MultiMap
|
|
|
+ *
|
|
|
+ * @param map map
|
|
|
+ * @param <K> K
|
|
|
+ * @param <V> V
|
|
|
+ * @return MultiMap
|
|
|
+ */
|
|
|
public static <K, V> MultiMap<K, V> synchronizedMultiMap(MultiMap<K, V> map) {
|
|
|
return new SynchronizedMultiMap<>(map);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns flattened map inserting flat result into OpenMap
|
|
|
+ * @param source
|
|
|
+ * @param joiner
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public static Map<String,Object> flat(Map<?,?> source, String joiner) {
|
|
|
return flat(new OpenMap<>(), source, joiner);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns flattened map.
|
|
|
+ *
|
|
|
+ * Every key inside provided map is converted into string.
|
|
|
+ * If source map contains any nested maps, their keys are converted to String too.
|
|
|
+ * Nested keys are concatenated using "joiner" as separator.
|
|
|
+ *
|
|
|
+ * Effectivelly, converts nested maps into flat maps with keys reflecting overall structure.
|
|
|
+ *
|
|
|
+ * Target map should be able to store any string mappings in efficient manner.
|
|
|
+ *
|
|
|
+ * @param target target
|
|
|
+ * @param source source
|
|
|
+ * @param joiner joiner
|
|
|
+ * @return map
|
|
|
+ */
|
|
|
public static Map<String,Object> flat(Map<String,Object> target, Map<?,?> source, String joiner) {
|
|
|
return flat(target, source, "", (a,b)->{
|
|
|
if(StringTraits.isEmpty(a)) {
|