ソースを参照

#73 rename MapUtils and IntMapUtils methods

Ranides Atterwim 4 年 前
コミット
4862a13629

+ 185 - 159
assira.commons/src/main/java/net/ranides/assira/collection/maps/IntMapUtils.java

@@ -27,7 +27,7 @@ import java.util.function.Function;
 @UtilityClass
 public final class IntMapUtils {
 
-    // @todo #73 Review IntMapUtils put/insert
+    // @todo #73 Review IntMapUtils adapter, projection, wrapper classes
 
     /**
      * Creates view which transforms values stored inside source map.
@@ -40,12 +40,27 @@ public final class IntMapUtils {
      * @return read-only view
      */
     public static <TV, RV> IntMap<RV> map(IntMap<TV> map, Function<? super TV, ? extends RV> function) {
-        return new MapAdapter<>(map, function, null);
+        return new MapAdapterKV<>(map, function, null);
     }
 
     /**
      * Creates view which transforms values stored inside source map.
-     * Returned view supports modifications: it uses second function to apply inverted conversion.
+     * Returned view supports modifications: it uses passed projection for conversion in both directions.
+     *
+     * @param map source map
+     * @param function mapping projection
+     * @param <TV> source type
+     * @param <RV> target type
+     * @return mutable view
+     */
+    public static <TV, RV> IntMap<RV> map(IntMap<TV> map, ProjectionFunction<TV, RV> function) {
+        return new MapProjection<>(map, function);
+    }
+
+    /**
+     * Creates view which transforms values stored inside source map.
+     * Returned view supports modifications: it uses "inserter" function to change map.
+     * It passes to inserter "key" and "new value".
      *
      * @param map source map
      * @param function mapping function
@@ -54,22 +69,24 @@ public final class IntMapUtils {
      * @param <RV> target type
      * @return mutable view
      */
-    public static <TV, RV> IntMap<RV> map(IntMap<TV> map, Function<? super TV, ? extends RV> function, BiFunction<Integer, ? super RV, ? extends RV> inserter) {
-        return new MapAdapter<>(map, function, inserter);
+    public static <TV, RV> IntMap<RV> mapKV(IntMap<TV> map, Function<? super TV, ? extends RV> function, BiFunction<Integer, ? super RV, ? extends RV> inserter) {
+        return new MapAdapterKV<>(map, function, inserter);
     }
 
     /**
      * Creates view which transforms values stored inside source map.
-     * Returned view supports modifications: it uses passed projection for conversion in both directions.
+     * Returned view supports modifications: it uses "replacer" function to change map.
+     * It passes to replacer "old value" and "new value".
      *
      * @param map source map
-     * @param function mapping projection
+     * @param function function
+     * @param replacer replacer
      * @param <TV> source type
      * @param <RV> target type
      * @return mutable view
      */
-    public static <TV, RV> IntMap<RV> map(IntMap<TV> map, ProjectionFunction<TV, RV> function) {
-        return new MapProjection<>(map, function);
+    public static <TV, RV> IntMap<RV> mapVV(IntMap<TV> map, Function<? super TV, ? extends RV> function, BiFunction<? super TV, ? super RV, ? extends RV> replacer) {
+        return new MapAdapterVV<>(map, function, replacer);
     }
 
     /**
@@ -86,7 +103,24 @@ public final class IntMapUtils {
      * @return read-only view
      */
     public static <TV, RV> IntMultiMap<RV> map(IntMultiMap<TV> map, Function<? super TV, ? extends RV> function) {
-        return new MMapAdapter<>(map, function, null);
+        return new MultiMapAdapterKV<>(map, function, null);
+    }
+
+    /**
+     * Creates view which transforms values stored inside source map.
+     * Returned view supports modifications: it uses passed projection for conversion in both directions.
+     *
+     * Please note, that mapping should avoid degenerating multimap into multimap which
+     * contains more than one pair of (k,v) where BOTH k and v are equal.
+     *
+     * @param map source map
+     * @param function mapping projection
+     * @param <TV> source type
+     * @param <RV> target type
+     * @return mutable view
+     */
+    public static <TV, RV> IntMultiMap<RV> map(IntMultiMap<TV> map, ProjectionFunction<TV, RV> function) {
+        return new MultiMapProjection<>(map, function);
     }
 
     /**
@@ -103,38 +137,84 @@ public final class IntMapUtils {
      * @param <RV> target type
      * @return mutable view
      */
-    public static <TV, RV> IntMultiMap<RV> map(IntMultiMap<TV> map, Function<? super TV, ? extends RV> function, BiFunction<Integer, ? super RV, ? extends RV> inserter) {
-        return new MMapAdapter<>(map, function, inserter);
+    public static <TV, RV> IntMultiMap<RV> mapKV(IntMultiMap<TV> map, Function<? super TV, ? extends RV> function, BiFunction<Integer, ? super RV, ? extends RV> inserter) {
+        return new MultiMapAdapterKV<>(map, function, inserter);
     }
 
     /**
      * Creates view which transforms values stored inside source map.
-     * Returned view supports modifications: it uses passed projection for conversion in both directions.
+     * Returned view supports modifications: it uses "replacer" function to change map.
+     * It passes to replacer "old value" and "new value".
      *
      * Please note, that mapping should avoid degenerating multimap into multimap which
      * contains more than one pair of (k,v) where BOTH k and v are equal.
      *
      * @param map source map
-     * @param function mapping projection
+     * @param function function
+     * @param replacer replacer
      * @param <TV> source type
      * @param <RV> target type
      * @return mutable view
      */
-    public static <TV, RV> IntMultiMap<RV> map(IntMultiMap<TV> map, ProjectionFunction<TV, RV> function) {
-        return new MMapProjection<>(map, function);
+    public static <TV, RV> IntMultiMap<RV> mapVV(IntMultiMap<TV> map, Function<? super TV, ? extends RV> function, BiFunction<? super TV, ? super RV, ? extends RV> replacer) {
+        return new MultiMapAdapterVV<>(map, function, replacer);
     }
-    
-    public static <TV, RV> IntMap<RV> wrap(IntMap<TV> map, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
-        // @todo #73 what is the difference between #map?
-        return new MapWrapper<>(map, getter, setter);
+
+    private static class MultiMapAdapterKV<TV, RV> extends MapAdapterKV<TV, RV> implements IntMultiMap<RV> {
+
+        private static final long serialVersionUID = 1L;
+
+        private final IntMultiMap<TV> mcontent;
+
+        public MultiMapAdapterKV(IntMultiMap<TV> mcontent, Function<? super TV, ? extends RV> function, BiFunction<Integer, ? super RV, ? extends RV> setter) {
+            super(mcontent, function, setter);
+            this.mcontent = mcontent;
+        }
+
+        @Override
+        public Collection<RV> getAll(int key) {
+            return CollectionUtils.map(mcontent.getAll(key), function);
+        }
+
     }
-    
-    public static <K, TV, RV> IntMultiMap<RV> wrap(IntMultiMap<TV> map, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
-        // @todo #73 what is the difference between #map?
-        return new MMapWrapper<>(map, getter, setter);
+
+    private static class MultiMapAdapterVV<TV, RV> extends MapAdapterVV<TV,RV> implements IntMultiMap<RV> {
+
+        private static final long serialVersionUID = 1L;
+
+        private final IntMultiMap<TV> mcontent;
+
+        public MultiMapAdapterVV(IntMultiMap<TV> content, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
+            super(content, getter, setter);
+            this.mcontent = content;
+        }
+
+        @Override
+        public Collection<RV> getAll(int key) {
+            return CollectionUtils.map(mcontent.getAll(key), getter);
+        }
+
     }
-    
-    private static class MapAdapter<TV, RV> extends AIntMap<RV> {
+
+    private static class MultiMapProjection<TV, RV> extends MapProjection<TV,RV> implements IntMultiMap<RV> {
+
+        private static final long serialVersionUID = 1L;
+
+        private final IntMultiMap<TV> mcontent;
+
+        public MultiMapProjection(IntMultiMap<TV> content, ProjectionFunction<TV, RV> function) {
+            super(content, function);
+            this.mcontent = content;
+        }
+
+        @Override
+        public Collection<RV> getAll(int key) {
+            return CollectionUtils.map(mcontent.getAll(key), function);
+        }
+
+    }
+
+    private static class MapAdapterKV<TV, RV> extends AIntMap<RV> {
         
         private static final long serialVersionUID = 1L;
         
@@ -148,7 +228,7 @@ public final class IntMapUtils {
         protected final BiFunction<Integer, ? super RV, ? extends RV> inserter;
 
         @SuppressWarnings("unchecked")
-        public MapAdapter(IntMap<TV> content, Function<? super TV, ? extends RV> function, BiFunction<Integer, ? super RV, ? extends RV> inserter) {
+        public MapAdapterKV(IntMap<TV> content, Function<? super TV, ? extends RV> function, BiFunction<Integer, ? super RV, ? extends RV> inserter) {
             this.content = content;
             this.function = function;
             this.inserter = null != inserter ? inserter : NSE;
@@ -232,17 +312,19 @@ public final class IntMapUtils {
         }
 
     }
-    
-    private static class MapProjection<TV, RV> extends AIntMap<RV> {
-        
+
+    private static class MapAdapterVV<TV, RV> extends AIntMap<RV> implements IntMap<RV> {
+
         private static final long serialVersionUID = 1L;
 
-        protected final IntMap<TV> content;
-        protected final ProjectionFunction<TV, RV> function;
+        protected final IntMap<TV> content;        
+        protected final Function<? super TV, ? extends RV> getter;
+        protected final BiFunction<? super TV, ? super RV, ? extends RV> setter;
 
-        public MapProjection(IntMap<TV> content, ProjectionFunction<TV, RV> function) {
+        public MapAdapterVV(IntMap<TV> content, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
             this.content = content;
-            this.function = function;
+            this.getter = getter;
+            this.setter = setter;
         }
 
         @Override
@@ -254,30 +336,24 @@ public final class IntMapUtils {
         public boolean containsKey(int key) {
             return content.containsKey(key);
         }
-        
+
         @Override
-        @SuppressWarnings("unchecked")
         public boolean containsValue(Object value) {
-            Object v;
-            try {
-                v = function.invert((RV)value);
-            } catch(ClassCastException _ex) {
-                return false;
-            }
-            return content.containsValue(v);
+            return values().contains(value);
         }
 
         @Override
-        public void clear() {
-            content.clear();
+        public RV get(int key) {
+            TV var = content.get(key);
+            return null!=var ? getter.apply(var) : null;
         }
 
         @Override
-        public RV remove(int key) {
-            TV prev = content.remove(key);
-            return prev==null ? null : function.apply(prev);
+        public RV put(int key, RV value) {
+            TV var = content.get(key);
+            return null!=var ? setter.apply(var, value) : null;
         }
-
+        
         @Override
         public IntSet keySet() {
             return content.keySet();
@@ -285,129 +361,51 @@ public final class IntMapUtils {
 
         @Override
         public Collection<RV> values() {
-            return CollectionUtils.map(content.values(), function);
+            return CollectionUtils.map(content.values(), getter);
         }
         
         @Override
         public Set<IntEntry<RV>> fastEntrySet() {
-            return SetUtils.map(content.fastEntrySet(), e -> new EntryProjection(e));
-        }
-
-        @Override
-        public RV get(int key) {
-            return function.apply(content.get(key));
-        }
-
-        @Override
-        public RV put(int key, RV value) {
-            return function.apply(content.put(key, function.invert(value)));
-        }
-
-        @Override
-        @SuppressWarnings("unchecked")
-        public boolean remove(int key, Object value) {
-            Object v;
-            try {
-                v = function.invert((RV)value);
-            } catch(ClassCastException _e) {
-                return false;
-            }
-            return content.remove(key, v);
+            return SetUtils.map(content.fastEntrySet(), e -> new EntryWrapper(e));
         }
-
-        private final class EntryProjection extends AIntEntry<RV> {
+        
+        private final class EntryWrapper extends AIntEntry<RV> {
             
             private final IntEntry<TV> delegate;
 
-            public EntryProjection(IntEntry<TV> delegate) {
+            public EntryWrapper(IntEntry<TV> delegate) {
                 this.delegate = delegate;
             }
 
             @Override
             public int getIntKey() {
-                return delegate.getIntKey();
+                return delegate.getKey();
             }
 
             @Override
             public RV getValue() {
-                return function.apply(delegate.getValue());
+                return getter.apply(delegate.getValue());
             }
 
             @Override
             public RV setValue(RV value) {
-                return function.apply(content.put(getIntKey(), function.invert(value)));
+                return setter.apply(delegate.getValue(), value);
             }
 
         }
-
-    }
-    
-    private static class MMapAdapter<TV, RV> extends MapAdapter<TV, RV> implements IntMultiMap<RV> {
-        
-        private static final long serialVersionUID = 1L;
-        
-        private final IntMultiMap<TV> mcontent;
-
-        public MMapAdapter(IntMultiMap<TV> mcontent, Function<? super TV, ? extends RV> function, BiFunction<Integer, ? super RV, ? extends RV> setter) {
-            super(mcontent, function, setter);
-            this.mcontent = mcontent;
-        }
-        
-        @Override
-        public Collection<RV> getAll(int key) {
-            return CollectionUtils.map(mcontent.getAll(key), function);
-        }
         
     }
-    
-    private static class MMapProjection<TV, RV> extends MapProjection<TV,RV> implements IntMultiMap<RV> {
-        
-        private static final long serialVersionUID = 1L;
-        
-        private final IntMultiMap<TV> mcontent;
-        
-        public MMapProjection(IntMultiMap<TV> content, ProjectionFunction<TV, RV> function) {
-            super(content, function);
-            this.mcontent = content;
-        }
-        
-        @Override
-        public Collection<RV> getAll(int key) {
-            return CollectionUtils.map(mcontent.getAll(key), function);
-        }
-
-    }
-    
-    private static class MMapWrapper<TV, RV> extends MapWrapper<TV,RV> implements IntMultiMap<RV> { 
-        
-        private static final long serialVersionUID = 1L;
 
-        private final IntMultiMap<TV> mcontent;
-                
-        public MMapWrapper(IntMultiMap<TV> content, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
-            super(content, getter, setter);
-            this.mcontent = content;
-        }
-
-        @Override
-        public Collection<RV> getAll(int key) {
-            return CollectionUtils.map(mcontent.getAll(key), getter);
-        }
-        
-    }
-    
-    private static class MapWrapper<TV, RV> extends AIntMap<RV> implements IntMap<RV> { 
+    private static class MapProjection<TV, RV> extends AIntMap<RV> {
 
         private static final long serialVersionUID = 1L;
 
-        protected final IntMap<TV> content;        
-        protected final Function<? super TV, ? extends RV> getter;
-        protected final BiFunction<? super TV, ? super RV, ? extends RV> setter;
+        protected final IntMap<TV> content;
+        protected final ProjectionFunction<TV, RV> function;
 
-        public MapWrapper(IntMap<TV> content, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
+        public MapProjection(IntMap<TV> content, ProjectionFunction<TV, RV> function) {
             this.content = content;
-            this.getter = getter;
-            this.setter = setter;
+            this.function = function;
         }
 
         @Override
@@ -421,22 +419,28 @@ public final class IntMapUtils {
         }
 
         @Override
+        @SuppressWarnings("unchecked")
         public boolean containsValue(Object value) {
-            return values().contains(value);
+            Object v;
+            try {
+                v = function.invert((RV)value);
+            } catch(ClassCastException _ex) {
+                return false;
+            }
+            return content.containsValue(v);
         }
 
         @Override
-        public RV get(int key) {
-            TV var = content.get(key);
-            return null!=var ? getter.apply(var) : null;
+        public void clear() {
+            content.clear();
         }
 
         @Override
-        public RV put(int key, RV value) {
-            TV var = content.get(key);
-            return null!=var ? setter.apply(var, value) : null;
+        public RV remove(int key) {
+            TV prev = content.remove(key);
+            return prev==null ? null : function.apply(prev);
         }
-        
+
         @Override
         public IntSet keySet() {
             return content.keySet();
@@ -444,39 +448,61 @@ public final class IntMapUtils {
 
         @Override
         public Collection<RV> values() {
-            return CollectionUtils.map(content.values(), getter);
+            return CollectionUtils.map(content.values(), function);
         }
-        
+
         @Override
         public Set<IntEntry<RV>> fastEntrySet() {
-            return SetUtils.map(content.fastEntrySet(), e -> new EntryWrapper(e));
+            return SetUtils.map(content.fastEntrySet(), e -> new EntryProjection(e));
         }
-        
-        private final class EntryWrapper extends AIntEntry<RV> {
-            
+
+        @Override
+        public RV get(int key) {
+            return function.apply(content.get(key));
+        }
+
+        @Override
+        public RV put(int key, RV value) {
+            return function.apply(content.put(key, function.invert(value)));
+        }
+
+        @Override
+        @SuppressWarnings("unchecked")
+        public boolean remove(int key, Object value) {
+            Object v;
+            try {
+                v = function.invert((RV)value);
+            } catch(ClassCastException _e) {
+                return false;
+            }
+            return content.remove(key, v);
+        }
+
+        private final class EntryProjection extends AIntEntry<RV> {
+
             private final IntEntry<TV> delegate;
 
-            public EntryWrapper(IntEntry<TV> delegate) {
+            public EntryProjection(IntEntry<TV> delegate) {
                 this.delegate = delegate;
             }
 
             @Override
             public int getIntKey() {
-                return delegate.getKey();
+                return delegate.getIntKey();
             }
 
             @Override
             public RV getValue() {
-                return getter.apply(delegate.getValue());
+                return function.apply(delegate.getValue());
             }
 
             @Override
             public RV setValue(RV value) {
-                return setter.apply(delegate.getValue(), value);
+                return function.apply(content.put(getIntKey(), function.invert(value)));
             }
 
         }
-        
+
     }
     
 }

+ 190 - 178
assira.core/src/main/java/net/ranides/assira/collection/maps/MapUtils.java

@@ -32,45 +32,65 @@ public class MapUtils {
      * Returned view does not support modifications.
      *
      * @param map source map
-     * @param function mapping function
+     * @param function function
      * @param <K> K
      * @param <TV> source type
      * @param <RV> target type
      * @return read-only view
      */
     public static <K, TV, RV> Map<K,RV> map(Map<K,TV> map, Function<? super TV, ? extends RV> function) {
-        return new MapAdapter<>(map, function, null);
+        return new MapAdapterKV<>(map, function, null);
     }
 
     /**
      * Creates view which transforms values stored inside source map.
-     * Returned view supports modifications: it uses second function to apply inverted conversion.
+     * Returned view supports modifications: it uses passed projection for conversion in both directions.
+     *
+     * @param map source map
+     * @param projection projection
+     * @param <K> K
+     * @param <TV> source type
+     * @param <RV> target type
+     * @return mutable view
+     */
+    public static <K, TV, RV> Map<K,RV> map(Map<K,TV> map, ProjectionFunction<TV, RV> projection) {
+        return new MapProjection<>(map, projection);
+    }
+
+    /**
+     * Creates view which transforms values stored inside source map.
+     * Returned view supports modifications: it uses "inserter" function to change map.
+     *
+     * It passes to inserter "key" and "new value".
      *
      * @param map source map
      * @param function mapping function
-     * @param inserter inverted mapping, used for insertion
+     * @param inserter insertion function
      * @param <K> K
      * @param <TV> source type
      * @param <RV> target type
      * @return mutable view
      */
-    public static <K, TV, RV> Map<K,RV> map(Map<K,TV> map, Function<? super TV, ? extends RV> function, BiFunction<? super K, ? super RV, ? extends RV> inserter) {
-        return new MapAdapter<>(map, function, inserter);
+    public static <K, TV, RV> Map<K,RV> mapKV(Map<K,TV> map, Function<? super TV, ? extends RV> function, BiFunction<? super K, ? super RV, ? extends RV> inserter) {
+        return new MapAdapterKV<>(map, function, inserter);
     }
 
     /**
      * Creates view which transforms values stored inside source map.
-     * Returned view supports modifications: it uses passed projection for conversion in both directions.
+     * Returned view supports modifications: it uses "replacer" function to change map.
+     *
+     * It passes to replacer "previous value" and "new value".
      *
      * @param map source map
-     * @param function mapping projection
+     * @param function mapping function
+     * @param replacer insertion function
      * @param <K> K
      * @param <TV> source type
      * @param <RV> target type
      * @return mutable view
      */
-    public static <K, TV, RV> Map<K,RV> map(Map<K,TV> map, ProjectionFunction<TV, RV> function) {
-        return new MapProjection<>(map, function);
+    public static <K, TV, RV> Map<K,RV> mapVV(Map<K,TV> map, Function<? super TV, ? extends RV> function, BiFunction<? super TV, ? super RV, ? extends RV> replacer) {
+        return new MapAdapterVV<>(map, function, replacer);
     }
 
     /**
@@ -84,47 +104,59 @@ public class MapUtils {
      * @param <RV> target type
      * @return read-only view
      */
+    @SuppressWarnings("unchecked")
     public static <K, TV, RV> MultiMap<K,RV> map(MultiMap<K,TV> map, Function<? super TV, ? extends RV> function) {
-        return new MMapAdapter<>(map, function, null);
+        return new MultiMapAdapterKV<>(map, function, null);
     }
 
     /**
      * Creates view which transforms values stored inside source map.
-     * Returned view supports modifications: it uses second function to apply inverted conversion.
+     * Returned view supports modifications: it uses passed projection for conversion in both directions.
      *
      * @param map source map
-     * @param function mapping function
-     * @param inserter inverted mapping, used for insertion
+     * @param projection projection
      * @param <K> K
      * @param <TV> source type
      * @param <RV> target type
      * @return mutable view
      */
-    public static <K, TV, RV> MultiMap<K,RV> map(MultiMap<K,TV> map, Function<? super TV, ? extends RV> function, BiFunction<? super K, ? super RV, ? extends RV> inserter) {
-        return new MMapAdapter<>(map, function, inserter);
+    public static <K, TV, RV> MultiMap<K,RV> map(MultiMap<K,TV> map, ProjectionFunction<TV, RV> projection) {
+        return new MultiMapProjection<>(map, projection);
     }
 
     /**
      * Creates view which transforms values stored inside source map.
-     * Returned view supports modifications: it uses passed projection for conversion in both directions.
+     * Returned view supports modifications: it uses "inserter" function to change map.
+     * It passes to inserter "key" and "new value".
      *
      * @param map source map
-     * @param function mapping projection
+     * @param function mapping function
+     * @param inserter inverted mapping, used for insertion
      * @param <K> K
      * @param <TV> source type
      * @param <RV> target type
      * @return mutable view
      */
-    public static <K, TV, RV> MultiMap<K,RV> map(MultiMap<K,TV> map, ProjectionFunction<TV, RV> function) {
-        return new MMapProjection<>(map, function);
+    public static <K, TV, RV> MultiMap<K,RV> mapKV(MultiMap<K,TV> map, Function<? super TV, ? extends RV> function, BiFunction<? super K, ? super RV, ? extends RV> inserter) {
+        return new MultiMapAdapterKV<>(map, function, inserter);
     }
 
-    public static <K, TV, RV> Map<K,RV> wrap(Map<K,TV> map, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
-        return new MapWrapper<>(map, getter, setter);
-    }
-    
-    public static <K, TV, RV> MultiMap<K,RV> wrap(MultiMap<K,TV> map, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
-        return new MMapWrapper<>(map, getter, setter);
+    /**
+     * Creates view which transforms values stored inside source map.
+     * Returned view supports modifications: it uses "replacer" function to change map.
+     *
+     * It passes to replacer "previous value" and "new value".
+     *
+     * @param map source map
+     * @param function mapping function
+     * @param replacer inverted mapping, used for insertion
+     * @param <K> K
+     * @param <TV> source type
+     * @param <RV> target type
+     * @return mutable view
+     */
+    public static <K, TV, RV> MultiMap<K,RV> mapVV(MultiMap<K,TV> map, Function<? super TV, ? extends RV> function, BiFunction<? super TV, ? super RV, ? extends RV> replacer) {
+        return new MultiMapAdapterVV<>(map, function, replacer);
     }
 
     /**
@@ -140,8 +172,8 @@ public class MapUtils {
      * @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);
+    public static <K,V> Map<K,V> keymap(Map<K, V> content, Predicate<Object> acceptor, Function<K, K> function) {
+        return new KeyMapFilter<>(content, acceptor, function);
     }
 
     /**
@@ -155,26 +187,8 @@ public class MapUtils {
      * @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);
+    public static <TK, RK, V> Map<RK,V> keymap(Map<TK, ? extends V> map, Function<TK, RK> keyMapper) {
+        return new KeyMapAdapter<>(map, keyMapper, Function.identity());
     }
 
     /**
@@ -258,7 +272,7 @@ public class MapUtils {
         return target;
     }
 
-    private static class ViewAdapter<TK, RK, TV, RV> extends AMap<RK, RV> {
+    private static class KeyMapAdapter<TK, RK, TV, RV> extends AMap<RK, RV> {
 
         private final Map<TK,? extends TV> content;
 
@@ -266,7 +280,7 @@ public class MapUtils {
 
         private final Function<TV, RV> vmap;
 
-        public ViewAdapter(Map<TK,? extends TV> content, Function<TK, RK> kmap, Function<TV, RV> vmap) {
+        public KeyMapAdapter(Map<TK,? extends TV> content, Function<TK, RK> kmap, Function<TV, RV> vmap) {
             this.content = content;
             this.kmap = kmap;
             this.vmap = vmap;
@@ -323,13 +337,13 @@ public class MapUtils {
         }
     }
 
-    private static class MMapAdapter<K, TV, RV> extends MapAdapter<K, TV, RV> implements MultiMap<K, RV> {
+    private static class MultiMapAdapterKV<K, TV, RV> extends MapAdapterKV<K, TV, RV> implements MultiMap<K, RV> {
         
         private static final long serialVersionUID = 1L;
         
         private final MultiMap<K, TV> mcontent;
 
-        public MMapAdapter(MultiMap<K, TV> mcontent, Function<? super TV, ? extends RV> function, BiFunction<? super K, ? super RV, ? extends RV> setter) {
+        public MultiMapAdapterKV(MultiMap<K, TV> mcontent, Function<? super TV, ? extends RV> function, BiFunction<? super K, ? super RV, ? extends RV> setter) {
             super(mcontent, function, setter);
             this.mcontent = mcontent;
         }
@@ -340,21 +354,57 @@ public class MapUtils {
         }
         
     }
-    
-    private static class MapAdapter<K, TV, RV> extends AMap<K, RV> implements Map<K, RV> {
+
+    private static class MultiMapAdapterVV<K, TV, RV> extends MapAdapterVV<K,TV,RV> implements MultiMap<K, RV> {
+
+        private static final long serialVersionUID = 1L;
+
+        private final MultiMap<K, TV> mcontent;
+
+        public MultiMapAdapterVV(MultiMap<K, TV> content, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
+            super(content, getter, setter);
+            this.mcontent = content;
+        }
+
+        @Override
+        public Collection<RV> getAll(Object key) {
+            return CollectionUtils.map(mcontent.getAll(key), getter);
+        }
+
+    }
+
+    private static class MultiMapProjection<K, TV, RV> extends MapProjection<K,TV,RV> implements MultiMap<K, RV> {
         
         private static final long serialVersionUID = 1L;
         
+        private final MultiMap<K, TV> mcontent;
+        
+        public MultiMapProjection(MultiMap<K, TV> content, ProjectionFunction<TV, RV> function) {
+            super(content, function);
+            this.mcontent = content;
+        }
+        
+        @Override
+        public Collection<RV> getAll(Object key) {
+            return CollectionUtils.map(mcontent.getAll(key), function);
+        }
+
+    }
+
+    private static class MapAdapterKV<K, TV, RV> extends AMap<K, RV> implements Map<K, RV> {
+
+        private static final long serialVersionUID = 1L;
+
         private static final BiFunction NSE = (Serializable & BiFunction)(a,b) -> {
-            throw new UnsupportedOperationException(); 
+            throw new UnsupportedOperationException();
         };
-        
+
         protected final Map<K, TV> content;
         protected final Function<? super TV, ? extends RV> function;
         protected final BiFunction<? super K, ? super RV, ? extends RV> inserter;
 
         @SuppressWarnings("unchecked")
-        public MapAdapter(Map<K, TV> content, Function<? super TV, ? extends RV> function, BiFunction<? super K, ? super RV, ? extends RV> setter) {
+        public MapAdapterKV(Map<K, TV> content, Function<? super TV, ? extends RV> function, BiFunction<? super K, ? super RV, ? extends RV> setter) {
             this.content = content;
             this.function = function;
             this.inserter = null != setter ? setter : NSE;
@@ -369,7 +419,7 @@ public class MapUtils {
         public boolean containsKey(Object key) {
             return content.containsKey(key);
         }
-        
+
         @Override
         public boolean containsValue(Object value) {
             return content.values().stream().map(function).anyMatch(rv -> CompareUtils.equals(rv, value));
@@ -395,7 +445,7 @@ public class MapUtils {
         public Collection<RV> values() {
             return CollectionUtils.map(content.values(), function);
         }
-        
+
         @Override
         public Set<Entry<K, RV>> entrySet() {
             return SetUtils.map(content.entrySet(), e -> new EntryAdapter(e));
@@ -410,9 +460,9 @@ public class MapUtils {
         public RV put(K key, RV value) {
             return inserter.apply(key, value);
         }
-        
+
         private final class EntryAdapter extends AEntry<K, RV> {
-            
+
             private final Entry<K,TV> delegate;
 
             public EntryAdapter(Entry<K, TV> delegate) {
@@ -437,41 +487,19 @@ public class MapUtils {
         }
 
     }
-    
-    private static class MMapProjection<K, TV, RV> extends MapProjection<K,TV,RV> implements MultiMap<K, RV> {
-        
-        private static final long serialVersionUID = 1L;
-        
-        private final MultiMap<K, TV> mcontent;
-        
-        public MMapProjection(MultiMap<K, TV> content, ProjectionFunction<TV, RV> function) {
-            super(content, function);
-            this.mcontent = content;
-        }
-        
-        @Override
-        public Collection<RV> getAll(Object key) {
-            return CollectionUtils.map(mcontent.getAll(key), function);
-        }
 
-    }
-    
-    private static class MapProjection<K, TV, RV> extends AMap<K, RV> implements Map<K, RV> {
-        
+    private static class MapAdapterVV<K, TV, RV> extends AMap<K, RV> implements Map<K, RV> {
+
         private static final long serialVersionUID = 1L;
 
         protected final Map<K, TV> content;
+        protected final Function<? super TV, ? extends RV> getter;
+        protected final BiFunction<? super TV, ? super RV, ? extends RV> setter;
 
-        protected final ProjectionFunction<TV, RV> function;
-
-        public MapProjection(Map<K, TV> content, ProjectionFunction<TV, RV> function) {
-            this.content = content;
-            this.function = function;
-        }
-        
-        public MapProjection(MultiMap<K, TV> content, ProjectionFunction<TV, RV> function) {
+        public MapAdapterVV(Map<K,TV> content, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
             this.content = content;
-            this.function = function;
+            this.getter = getter;
+            this.setter = setter;
         }
 
         @Override
@@ -483,26 +511,22 @@ public class MapUtils {
         public boolean containsKey(Object key) {
             return content.containsKey(key);
         }
-        
-        @SuppressWarnings("unchecked")
+
         @Override
         public boolean containsValue(Object value) {
-            try {
-                return content.containsValue(function.invert((RV)value));
-            } catch(ClassCastException _ex) {
-                return false;
-            }
+            return values().contains(value);
         }
 
         @Override
-        public void clear() {
-            content.clear();
+        public RV get(Object key) {
+            TV var = content.get(key);
+            return null!=var ? getter.apply(var) : null;
         }
 
         @Override
-        public RV remove(Object key) {
-            TV prev = content.remove(key);
-            return prev==null ? null : function.apply(prev);
+        public RV put(K key, RV value) {
+            TV var = content.get(key);
+            return null!=var ? setter.apply(var, value) : null;
         }
 
         @Override
@@ -512,41 +536,19 @@ public class MapUtils {
 
         @Override
         public Collection<RV> values() {
-            return CollectionUtils.map(content.values(), function);
-        }
-        
-        @Override
-        public Set<Map.Entry<K, RV>> entrySet() {
-            return SetUtils.map(content.entrySet(), e -> new EntryProjection(e));
+            return CollectionUtils.map(content.values(), getter);
         }
 
         @Override
-        public RV get(Object key) {
-            return function.apply(content.get(key));
-        }
-        
-        @Override
-        public RV put(K key, RV value) {
-            return function.apply(content.put(key, function.invert(value)));
+        public Set<Entry<K, RV>> entrySet() {
+            return SetUtils.map(content.entrySet(), e -> new EntryWrapper(e));
         }
 
-        @Override
-        @SuppressWarnings("unchecked")
-        public boolean remove(Object key, Object value) {
-            Object v;
-            try {
-                v = function.invert((RV)value);
-            } catch(ClassCastException _e) {
-                return false;
-            }
-            return content.remove(key, v);
-        }
+        private final class EntryWrapper extends AEntry<K, RV> {
 
-        private final class EntryProjection extends AEntry<K, RV> {
-            
             private final Map.Entry<K,TV> delegate;
 
-            public EntryProjection(Map.Entry<K, TV> delegate) {
+            public EntryWrapper(Map.Entry<K, TV> delegate) {
                 this.delegate = delegate;
             }
 
@@ -557,48 +559,34 @@ public class MapUtils {
 
             @Override
             public RV getValue() {
-                return function.apply(delegate.getValue());
+                return getter.apply(delegate.getValue());
             }
 
             @Override
             public RV setValue(RV value) {
-                return function.apply(content.put(getKey(), function.invert(value)));
+                return setter.apply(delegate.getValue(), value);
             }
 
         }
 
     }
-    
-    private static class MMapWrapper<K, TV, RV> extends MapWrapper<K,TV,RV> implements MultiMap<K, RV> { 
+
+    private static class MapProjection<K, TV, RV> extends AMap<K, RV> implements Map<K, RV> {
         
         private static final long serialVersionUID = 1L;
 
-        private final MultiMap<K, TV> mcontent;
-                
-        public MMapWrapper(MultiMap<K, TV> content, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
-            super(content, getter, setter);
-            this.mcontent = content;
-        }
+        protected final Map<K, TV> content;
 
-        @Override
-        public Collection<RV> getAll(Object key) {
-            return CollectionUtils.map(mcontent.getAll(key), getter);
+        protected final ProjectionFunction<TV, RV> function;
+
+        public MapProjection(Map<K, TV> content, ProjectionFunction<TV, RV> function) {
+            this.content = content;
+            this.function = function;
         }
         
-    }
-    
-    private static class MapWrapper<K, TV, RV> extends AMap<K, RV> implements Map<K, RV> {
-
-        private static final long serialVersionUID = 1L;
-
-        protected final Map<K, TV> content;        
-        protected final Function<? super TV, ? extends RV> getter;
-        protected final BiFunction<? super TV, ? super RV, ? extends RV> setter;
-
-        public MapWrapper(Map<K,TV> content, Function<? super TV, ? extends RV> getter, BiFunction<? super TV, ? super RV, ? extends RV> setter) {
+        public MapProjection(MultiMap<K, TV> content, ProjectionFunction<TV, RV> function) {
             this.content = content;
-            this.getter = getter;
-            this.setter = setter;
+            this.function = function;
         }
 
         @Override
@@ -610,26 +598,28 @@ public class MapUtils {
         public boolean containsKey(Object key) {
             return content.containsKey(key);
         }
-
+        
+        @SuppressWarnings("unchecked")
         @Override
         public boolean containsValue(Object value) {
-            return values().contains(value);
+            try {
+                return content.containsValue(function.invert((RV)value));
+            } catch(ClassCastException _ex) {
+                return false;
+            }
         }
 
         @Override
-        public RV get(Object key) {
-            TV var = content.get(key);
-            return null!=var ? getter.apply(var) : null;
+        public void clear() {
+            content.clear();
         }
 
         @Override
-        public RV put(K key, RV value) {
-            TV var = content.get(key);
-            return null!=var ? setter.apply(var, value) : null;
+        public RV remove(Object key) {
+            TV prev = content.remove(key);
+            return prev==null ? null : function.apply(prev);
         }
-        
-        
-        
+
         @Override
         public Set<K> keySet() {
             return content.keySet();
@@ -637,19 +627,41 @@ public class MapUtils {
 
         @Override
         public Collection<RV> values() {
-            return CollectionUtils.map(content.values(), getter);
+            return CollectionUtils.map(content.values(), function);
         }
         
         @Override
-        public Set<Entry<K, RV>> entrySet() {
-            return SetUtils.map(content.entrySet(), e -> new EntryWrapper(e));
+        public Set<Map.Entry<K, RV>> entrySet() {
+            return SetUtils.map(content.entrySet(), e -> new EntryProjection(e));
+        }
+
+        @Override
+        public RV get(Object key) {
+            return function.apply(content.get(key));
         }
         
-        private final class EntryWrapper extends AEntry<K, RV> {
+        @Override
+        public RV put(K key, RV value) {
+            return function.apply(content.put(key, function.invert(value)));
+        }
+
+        @Override
+        @SuppressWarnings("unchecked")
+        public boolean remove(Object key, Object value) {
+            Object v;
+            try {
+                v = function.invert((RV)value);
+            } catch(ClassCastException _e) {
+                return false;
+            }
+            return content.remove(key, v);
+        }
+
+        private final class EntryProjection extends AEntry<K, RV> {
             
             private final Map.Entry<K,TV> delegate;
 
-            public EntryWrapper(Map.Entry<K, TV> delegate) {
+            public EntryProjection(Map.Entry<K, TV> delegate) {
                 this.delegate = delegate;
             }
 
@@ -660,18 +672,18 @@ public class MapUtils {
 
             @Override
             public RV getValue() {
-                return getter.apply(delegate.getValue());
+                return function.apply(delegate.getValue());
             }
 
             @Override
             public RV setValue(RV value) {
-                return setter.apply(delegate.getValue(), value);
+                return function.apply(content.put(getKey(), function.invert(value)));
             }
 
         }
-        
+
     }
-    
+
     static class EmptyMM<K,V> extends AMap<K,V> implements MultiMap<K, V> {
         
         private static final long serialVersionUID = 1L;
@@ -708,14 +720,14 @@ public class MapUtils {
 
     }
 
-    private static class KeyMapAdapter<K, V> extends AMap<K, V> {
+    private static class KeyMapFilter<K, V> extends AMap<K, V> {
 
         protected final Map<K, V> content;
         protected final Predicate<Object> acceptor;
         protected final Function<K, K> function;
 
-        KeyMapAdapter(Supplier<Map<K, V>> content, Predicate<Object> acceptor, Function<K, K> function) {
-            this.content = content.get();
+        KeyMapFilter(Map<K, V> content, Predicate<Object> acceptor, Function<K, K> function) {
+            this.content = content;
             this.acceptor = acceptor;
             this.function = function;
         }

+ 1 - 1
assira.core/src/main/java/net/ranides/assira/collection/query/derived/CQFilterEach.java

@@ -12,7 +12,7 @@ import java.util.stream.Stream;
 
 /**
  * Adapter query: it filters provided stream using predicate.
- * Use by {@link CQuery#filterEach(EachPredicate)} operation.
+ * Use by {@link CQuery#filterEach(Predicates.EachPredicate)} operation.
  *
  * Supports fast iterator and stream if source supports it.
  * Does not support other fast operations.

+ 1 - 1
assira.core/src/main/java/net/ranides/assira/reflection/impl/bean/RBeanModel.java

@@ -108,7 +108,7 @@ public class RBeanModel implements BeanModel, Serializable {
 
     @Override
     public Map<String, Object> properties(Object that) {
-        return MapUtils.wrap(properties, p -> p.get(that), (p,v) -> p.replace(that, v));
+        return MapUtils.mapVV(properties, p -> p.get(that), (p,v) -> p.replace(that, v));
     }
 
     @Override

+ 1 - 1
assira.core/src/main/java/net/ranides/assira/xml/impl/W3Attributes.java

@@ -66,7 +66,7 @@ public class W3Attributes extends CElements {
     
     @Override
     public MultiMap<String, String> map() {
-        return MapUtils.map(map, this::$value, map::putValue);
+        return MapUtils.mapKV(map, this::$value, map::putValue);
     }
     
     private String $value(Node node) {

+ 3 - 3
assira.core/src/test/java/net/ranides/assira/collection/maps/MapUtilsTest.java

@@ -41,9 +41,9 @@ public class MapUtilsTest {
         Map<Object,?> b = a;
         Map<?,?> c = a;
 
-        Map<String, Number> ma = MapUtils.view(a, String::valueOf);
-        Map<String, Object> mb = MapUtils.view(b, String::valueOf);
-        Map<String, Object> mc = MapUtils.view(c, String::valueOf);
+        Map<String, Number> ma = MapUtils.keymap(a, String::valueOf);
+        Map<String, Object> mb = MapUtils.keymap(b, String::valueOf);
+        Map<String, Object> mc = MapUtils.keymap(c, String::valueOf);
 
         Assert.assertNotNull(ma);
         Assert.assertNotNull(mb);