Explorar o código

IndexMap: interface

Ranides Atterwim %!s(int64=9) %!d(string=hai) anos
pai
achega
01d4112b95

+ 0 - 18
assira.drafts/src/main/java/net/ranides/assira/collections/map/IndexComparator.java

@@ -1,18 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira.drafts
- */
-package net.ranides.assira.collections.map;
-
-import java.util.function.Function;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public interface IndexComparator<V,T> extends Function<V,T>  {
-
-    
-}

+ 4 - 3
assira.drafts/src/main/java/net/ranides/assira/collections/map/IndexMap.java

@@ -9,6 +9,7 @@ package net.ranides.assira.collections.map;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.function.Consumer;
+import java.util.function.Function;
 
 /**
  *
@@ -18,7 +19,7 @@ public interface IndexMap<V> {
 
     IndexMap<V> index(String name, Comparator<V> index);
     
-    <T> IndexMap<V> index(String name, IndexComparator<V,T> index);
+    <T> IndexMap<V> index(String name, Function<V,T> index);
     
     
     
@@ -26,7 +27,7 @@ public interface IndexMap<V> {
 
     IndexQuery<V> find(Comparator<V> index, V value);
     
-    <T> IndexQuery<V> find(IndexComparator<V,T> index, T value);
+    <T> IndexQuery<V> find(Function<V,T> index, T value);
 
     IndexQuery<V> find(String index, V value);
 
@@ -44,7 +45,7 @@ public interface IndexMap<V> {
     
     void remove(Comparator<V> index, V value);
     
-    <T> void remove(IndexComparator<V,T> index, T value);
+    <T> void remove(Function<V,T> index, T value);
 
     void remove(String index, V value);
     

+ 5 - 4
assira.drafts/src/main/java/net/ranides/assira/collections/map/IndexQuery.java

@@ -8,6 +8,7 @@ package net.ranides.assira.collections.map;
 
 import java.util.Comparator;
 import java.util.function.Consumer;
+import java.util.function.Function;
 import net.ranides.assira.collection.query.CQuery;
 
 /**
@@ -19,7 +20,7 @@ public interface IndexQuery<V> extends CQuery<V> {
 
     IndexQuery<V> eq(Comparator<V> index, V value);
     
-    <T> IndexQuery<V> eq(IndexComparator<V,T> index, T value);
+    <T> IndexQuery<V> eq(Function<V,T> index, T value);
 
     IndexQuery<V> eq(String index, Object value);
     
@@ -27,7 +28,7 @@ public interface IndexQuery<V> extends CQuery<V> {
     
     IndexQuery<V> gt(Comparator<V> index, V value);
     
-    <T> IndexQuery<V> gt(IndexComparator<V,T> index, T value);
+    <T> IndexQuery<V> gt(Function<V,T> index, T value);
 
     IndexQuery<V> gt(String index, Object value);
     
@@ -35,7 +36,7 @@ public interface IndexQuery<V> extends CQuery<V> {
     
     IndexQuery<V> lt(Comparator<V> index, V value);
     
-    <T> IndexQuery<V> lt(IndexComparator<V,T> index, T value);
+    <T> IndexQuery<V> lt(Function<V,T> index, T value);
 
     IndexQuery<V> lt(String index, Object value);
     
@@ -43,7 +44,7 @@ public interface IndexQuery<V> extends CQuery<V> {
 
     IndexQuery<V> in(Comparator<V> index, V begin, V end);
     
-    <T> IndexQuery<V> in(IndexComparator<V,T> index, T begin, T end);
+    <T> IndexQuery<V> in(Function<V,T> index, T begin, T end);
 
     IndexQuery<V> in(String index, Object begin, Object end);
 

+ 4 - 4
assira.drafts/src/main/java/net/ranides/assira/collections/map/impl/AIndexMap.java

@@ -9,7 +9,7 @@ package net.ranides.assira.collections.map.impl;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.function.Consumer;
-import net.ranides.assira.collections.map.IndexComparator;
+import java.util.function.Function;
 import net.ranides.assira.collections.map.IndexMap;
 import net.ranides.assira.collections.map.IndexQuery;
 
@@ -28,7 +28,7 @@ public abstract class AIndexMap<V> implements IndexMap<V> {
     }
 
     @Override
-    public <T> IndexQuery<V> find(IndexComparator<V, T> index, T value) {
+    public <T> IndexQuery<V> find(Function<V, T> index, T value) {
         return find().eq(index, value);
     }
     
@@ -51,7 +51,7 @@ public abstract class AIndexMap<V> implements IndexMap<V> {
     }
 
     @Override
-    public <T> void remove(IndexComparator<V, T> index, T value) {
+    public <T> void remove(Function<V, T> index, T value) {
         find().eq(index, value).remove();
     }
     
@@ -74,7 +74,7 @@ public abstract class AIndexMap<V> implements IndexMap<V> {
         put(value);
     }
     
-    protected abstract <T> IndexComparator<V,T> mindex(String name);
+    protected abstract <T> Function<V,T> mindex(String name);
     
     protected abstract Comparator<V> sindex(String name);
     

+ 2 - 3
assira.drafts/src/main/java/net/ranides/assira/collections/map/impl/AIndexQuery.java

@@ -12,7 +12,6 @@ import net.ranides.assira.collections.map.IndexQuery;
 import java.util.function.Consumer;
 import java.util.function.Function;
 import net.ranides.assira.collection.query.CQueryAbstract;
-import net.ranides.assira.collections.map.IndexComparator;
 
 /**
  *
@@ -55,10 +54,10 @@ public abstract class AIndexQuery<V> extends CQueryAbstract<V> implements IndexQ
     
     private IndexQuery<V> filter(
             String index, 
-            Function<IndexComparator<V, Object>, IndexQuery<V>> mf, 
+            Function<Function<V, Object>, IndexQuery<V>> mf, 
             Function<Comparator<V>, IndexQuery<V>> sf
     ) {
-        IndexComparator<V, Object> mi = parent().mindex(index);
+        Function<V, Object> mi = parent().mindex(index);
         if(mi != null) {
             return mf.apply(mi);
         }

+ 14 - 13
assira.drafts/src/main/java/net/ranides/assira/collections/map/impl/CIndexTreeMap.java

@@ -17,13 +17,14 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.SortedMap;
 import java.util.SortedSet;
+import java.util.function.Function;
 import java.util.function.Supplier;
 import java.util.stream.Stream;
 import net.ranides.assira.collection.maps.ASortedMap;
 import net.ranides.assira.collection.maps.RBTreeMultiMap;
 import net.ranides.assira.collection.sets.ASortedSet;
 import net.ranides.assira.collection.sets.RBTreeMultiSet;
-import net.ranides.assira.collections.map.IndexComparator;
+
 import net.ranides.assira.collections.map.IndexMap;
 import net.ranides.assira.collections.map.IndexQuery;
 import net.ranides.assira.generic.CompareUtils;
@@ -36,11 +37,11 @@ public class CIndexTreeMap<V> extends AIndexMap<V> {
     
     private final Map<String, Comparator> name2sindex = new HashMap<>();
     
-    private final Map<String, IndexComparator> name2mindex = new HashMap<>();
+    private final Map<String, Function> name2mindex = new HashMap<>();
     
     private final Map<Comparator, RBTreeMultiSet<V>> cindexes = new HashMap<>();
     
-    private final Map<IndexComparator, RBTreeMultiMap<Object, V>> mindexes = new HashMap<>();
+    private final Map<Function, RBTreeMultiMap<Object, V>> mindexes = new HashMap<>();
 
     @Override
     public IndexMap<V> index(String name, Comparator<V> index) {
@@ -54,7 +55,7 @@ public class CIndexTreeMap<V> extends AIndexMap<V> {
     }
 
     @Override
-    public <T> IndexMap<V> index(String name, IndexComparator<V, T> index) {
+    public <T> IndexMap<V> index(String name, Function<V, T> index) {
         RBTreeMultiMap<Object,V> map = new RBTreeMultiMap<>();
         mindexes.put(index, map);
         name2mindex.put(name, index);
@@ -66,7 +67,7 @@ public class CIndexTreeMap<V> extends AIndexMap<V> {
 
     @SuppressWarnings("unchecked")
     @Override
-    protected <T> IndexComparator<V, T> mindex(String name) {
+    protected <T> Function<V, T> mindex(String name) {
         return name2mindex.get(name);
     }
 
@@ -124,8 +125,8 @@ public class CIndexTreeMap<V> extends AIndexMap<V> {
             index.clear();
             index.addAll(items);
         }
-        for(Entry<IndexComparator, RBTreeMultiMap<Object,V>> entry : mindexes.entrySet()) {
-            IndexComparator fun = entry.getKey();
+        for(Entry<Function, RBTreeMultiMap<Object,V>> entry : mindexes.entrySet()) {
+            Function fun = entry.getKey();
             RBTreeMultiMap<Object, V> index = entry.getValue();
             index.clear();
             for(V item : items) {
@@ -146,8 +147,8 @@ public class CIndexTreeMap<V> extends AIndexMap<V> {
         for(SortedSet<V> index : cindexes.values()) {
             index.add(value);
         }
-        for(Entry<IndexComparator, RBTreeMultiMap<Object,V>> entry : mindexes.entrySet()) {
-            IndexComparator fun = entry.getKey();
+        for(Entry<Function, RBTreeMultiMap<Object,V>> entry : mindexes.entrySet()) {
+            Function fun = entry.getKey();
             RBTreeMultiMap<Object, V> index = entry.getValue();
             index.put(fun.apply(value), value);
         }
@@ -231,7 +232,7 @@ public class CIndexTreeMap<V> extends AIndexMap<V> {
         }
 
         @Override
-        public <T> IndexQuery<V> eq(IndexComparator<V, T> index, T value) {
+        public <T> IndexQuery<V> eq(Function<V, T> index, T value) {
             return new CHQuery(this, () -> mindexes.get(index).getAll(value));
         }
 
@@ -245,7 +246,7 @@ public class CIndexTreeMap<V> extends AIndexMap<V> {
         }
 
         @Override
-        public <T> IndexQuery<V> gt(IndexComparator<V, T> index, T value) {
+        public <T> IndexQuery<V> gt(Function<V, T> index, T value) {
             RBTreeMultiMap<Object, V> map = mindexes.get(index);
             return new CHQuery(this, () -> {
                 Object last = after(map,value);
@@ -259,7 +260,7 @@ public class CIndexTreeMap<V> extends AIndexMap<V> {
         }
 
         @Override
-        public <T> IndexQuery<V> lt(IndexComparator<V, T> index, T value) {
+        public <T> IndexQuery<V> lt(Function<V, T> index, T value) {
             return new CHQuery(this, () -> mindexes.get(index).headMap(value).values());
         }
 
@@ -269,7 +270,7 @@ public class CIndexTreeMap<V> extends AIndexMap<V> {
         }
 
         @Override
-        public <T> IndexQuery<V> in(IndexComparator<V, T> index, T begin, T end) {
+        public <T> IndexQuery<V> in(Function<V, T> index, T begin, T end) {
             return new CHQuery(this, () -> mindexes.get(index).subMap(begin, end).values());
         }