Mariusz Sieroń 9 tahun lalu
induk
melakukan
a68b37b651

+ 0 - 81
assira/src/main/java/net/ranides/assira/collection/maps/AIndexMap.java

@@ -1,81 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira.drafts
- */
-package net.ranides.assira.collection.maps;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import net.ranides.assira.collection.maps.IndexMap;
-import net.ranides.assira.collection.maps.IndexQuery;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public abstract class AIndexMap<V> implements IndexMap<V> {
-
-    @Override
-    public abstract AIndexQuery<V> find();
-    
-    @Override
-    public final IndexQuery<V> find(Comparator<V> index, V value) {
-        return find().eq(index, value);
-    }
-
-    @Override
-    public <T> IndexQuery<V> find(Function<V, T> index, T value) {
-        return find().eq(index, value);
-    }
-    
-    @SuppressWarnings("unchecked")
-    @Override
-    public final IndexQuery<V> find(String index, Object value) {
-        return find().eq(index, value);
-    }
-    
-    @Override
-    public final void put(Collection<? extends V> values) {
-        for(V value : values) {
-            put(value);
-        }
-    }
-    
-    @Override
-    public final void remove(Comparator<V> index, V value) {
-        find().eq(index, value).remove();
-    }
-
-    @Override
-    public <T> void remove(Function<V, T> index, T value) {
-        find().eq(index, value).remove();
-    }
-    
-    @Override
-    public final void remove(String index, Object value) {
-        find().eq(index, value).remove();
-    }
-
-    @Override
-    public void removeAll(Collection<V> values) {
-        for(V item : values) {
-            remove(item);
-        }
-    }
-    
-    @Override
-    public void update(V value, Consumer<? super V> consumer) {
-        remove(value);
-        consumer.accept(value);
-        put(value);
-    }
-    
-    protected abstract <T> Function<V,T> mindex(String name);
-    
-    protected abstract Comparator<V> sindex(String name);
-    
-}

+ 0 - 69
assira/src/main/java/net/ranides/assira/collection/maps/AIndexQuery.java

@@ -1,69 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira.drafts
- */
-package net.ranides.assira.collection.maps;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import net.ranides.assira.collection.query.CQueryAbstract;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public abstract class AIndexQuery<V> extends CQueryAbstract<V> implements IndexQuery<V> {
-    
-    protected abstract AIndexMap<V> parent();
-    
-    @SuppressWarnings("unchecked")
-    @Override
-    public final IndexQuery<V> eq(String index, Object value) {
-        return filter(index, a -> eq(a,value), a -> eq(a,(V)value));
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public final IndexQuery<V> lt(String index, Object value) {
-        return filter(index, a -> lt(a,value), a -> lt(a,(V)value));
-    }
-    
-    @SuppressWarnings("unchecked")
-    @Override
-    public final IndexQuery<V> gt(String index, Object value) {
-        return filter(index, a -> gt(a,value), a -> gt(a,(V)value));
-    }
-    
-    @SuppressWarnings("unchecked")
-    @Override
-    public final IndexQuery<V> in(String index, Object begin, Object end) {
-        return filter(index, a -> in(a,begin,end), a -> in(a,(V)begin,(V)end));
-    }
-
-    @Override
-    public void update(Consumer<? super V> consumer) {
-        select().forEach(v -> parent().update(v, consumer));
-    }
-    
-    protected abstract Collection<V> select();
-    
-    private IndexQuery<V> filter(
-            String index, 
-            Function<Function<V, Object>, IndexQuery<V>> mf, 
-            Function<Comparator<V>, IndexQuery<V>> sf
-    ) {
-        Function<V, Object> mi = parent().mindex(index);
-        if(mi != null) {
-            return mf.apply(mi);
-        }
-        Comparator<V> si = parent().sindex(index);
-        if(si != null) {
-            return sf.apply(si);
-        }
-        throw new IllegalArgumentException("Unknown index: " + index);
-    }
-}

+ 0 - 63
assira/src/main/java/net/ranides/assira/collection/maps/IndexQuery.java

@@ -1,63 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira.drafts
- */
-package net.ranides.assira.collection.maps;
-
-import java.util.Comparator;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import net.ranides.assira.collection.query.CQuery;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public interface IndexQuery<V> extends CQuery<V> {
-    
-    
-    IndexQuery<V> require();
-    
-    IndexQuery<V> optional();
-    
-    
-
-    IndexQuery<V> eq(Comparator<V> index, V value);
-    
-    <T> IndexQuery<V> eq(Function<V,T> index, T value);
-
-    IndexQuery<V> eq(String index, Object value);
-    
-
-    
-    IndexQuery<V> gt(Comparator<V> index, V value);
-    
-    <T> IndexQuery<V> gt(Function<V,T> index, T value);
-
-    IndexQuery<V> gt(String index, Object value);
-    
-    
-    
-    IndexQuery<V> lt(Comparator<V> index, V value);
-    
-    <T> IndexQuery<V> lt(Function<V,T> index, T value);
-
-    IndexQuery<V> lt(String index, Object value);
-    
-    
-
-    IndexQuery<V> in(Comparator<V> index, V begin, V end);
-    
-    <T> IndexQuery<V> in(Function<V,T> index, T begin, T end);
-
-    IndexQuery<V> in(String index, Object begin, Object end);
-
-    
-    
-    void remove();
-
-    void update(Consumer<? super V> consumer);
-
-}

+ 63 - 0
assira/src/main/java/net/ranides/assira/index/IQuery.java

@@ -0,0 +1,63 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira.drafts
+ */
+package net.ranides.assira.index;
+
+import java.util.Comparator;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import net.ranides.assira.collection.query.CQuery;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public interface IQuery<V> extends CQuery<V> {
+    
+    
+    IQuery<V> require();
+    
+    IQuery<V> optional();
+    
+    
+
+    IQuery<V> eq(Comparator<V> index, V value);
+    
+    <T> IQuery<V> eq(Function<V,T> index, T value);
+
+    IQuery<V> eq(String index, Object value);
+    
+
+    
+    IQuery<V> gt(Comparator<V> index, V value);
+    
+    <T> IQuery<V> gt(Function<V,T> index, T value);
+
+    IQuery<V> gt(String index, Object value);
+    
+    
+    
+    IQuery<V> lt(Comparator<V> index, V value);
+    
+    <T> IQuery<V> lt(Function<V,T> index, T value);
+
+    IQuery<V> lt(String index, Object value);
+    
+    
+
+    IQuery<V> in(Comparator<V> index, V begin, V end);
+    
+    <T> IQuery<V> in(Function<V,T> index, T begin, T end);
+
+    IQuery<V> in(String index, Object begin, Object end);
+
+    
+    
+    void remove();
+
+    void update(Consumer<? super V> consumer);
+    
+}

+ 140 - 0
assira/src/main/java/net/ranides/assira/index/IQueryAbstract.java

@@ -0,0 +1,140 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira.drafts
+ */
+package net.ranides.assira.index;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Stream;
+import net.ranides.assira.collection.query.CQueryAbstract;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public abstract class IQueryAbstract<V> extends CQueryAbstract<V> implements IQuery<V> {
+    
+    protected abstract Collection<V> select();
+    
+    protected abstract <T> Function<V,T> mindex(String name);
+    
+    protected abstract Comparator<V> sindex(String name);
+    
+    @Override
+    public Stream<V> stream() {
+        return select().stream();
+    }
+
+    @Override
+    public int size() {
+        return select().size();
+    }
+
+    @Override
+    public Iterator<V> iterator() {
+        return select().iterator();
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    public final IQuery<V> eq(String index, Object value) {
+        return filter(index, a -> eq(a,value), a -> eq(a,(V)value));
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public final IQuery<V> lt(String index, Object value) {
+        return filter(index, a -> lt(a,value), a -> lt(a,(V)value));
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    public final IQuery<V> gt(String index, Object value) {
+        return filter(index, a -> gt(a,value), a -> gt(a,(V)value));
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    public final IQuery<V> in(String index, Object begin, Object end) {
+        return filter(index, a -> in(a,begin,end), a -> in(a,(V)begin,(V)end));
+    }
+
+    private IQuery<V> filter(
+            String index, 
+            Function<Function<V, Object>, IQuery<V>> mf, 
+            Function<Comparator<V>, IQuery<V>> sf
+    ) {
+        Function<V, Object> mi = mindex(index);
+        if(mi != null) {
+            return mf.apply(mi);
+        }
+        Comparator<V> si = sindex(index);
+        if(si != null) {
+            return sf.apply(si);
+        }
+        throw new IllegalArgumentException("Unknown index: " + index);
+    }
+    
+    public static abstract class IQMap<V> implements IQueryMap<V> {
+
+        @Override
+        public final IQuery<V> find(Comparator<V> index, V value) {
+            return find().eq(index, value);
+        }
+
+        @Override
+        public <T> IQuery<V> find(Function<V, T> index, T value) {
+            return find().eq(index, value);
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public final IQuery<V> find(String index, Object value) {
+            return find().eq(index, value);
+        }
+
+        @Override
+        public final void put(Collection<? extends V> values) {
+            for(V value : values) {
+                put(value);
+            }
+        }
+
+        @Override
+        public final void remove(Comparator<V> index, V value) {
+            find().eq(index, value).remove();
+        }
+
+        @Override
+        public <T> void remove(Function<V, T> index, T value) {
+            find().eq(index, value).remove();
+        }
+
+        @Override
+        public final void remove(String index, Object value) {
+            find().eq(index, value).remove();
+        }
+
+        @Override
+        public void removeAll(Collection<V> values) {
+            for(V item : values) {
+                remove(item);
+            }
+        }
+
+        @Override
+        public void update(V value, Consumer<? super V> consumer) {
+            remove(value);
+            consumer.accept(value);
+            put(value);
+        }
+
+    }
+    
+}

+ 8 - 8
assira/src/main/java/net/ranides/assira/collection/maps/IndexMap.java

@@ -4,7 +4,7 @@
  * @license WTFPL
  * @url http://ranides.net/projects/assira.drafts
  */
-package net.ranides.assira.collection.maps;
+package net.ranides.assira.index;
 
 import java.util.Collection;
 import java.util.Comparator;
@@ -15,21 +15,21 @@ import java.util.function.Function;
  *
  * @author Ranides Atterwim <ranides@gmail.com>
  */
-public interface IndexMap<V> {
+public interface IQueryMap<V> {
 
-    IndexMap<V> index(String name, Comparator<V> index);
+    IQueryMap<V> index(String name, Comparator<V> index);
     
-    <T> IndexMap<V> index(String name, Function<V,T> index);
+    <T> IQueryMap<V> index(String name, Function<V,T> index);
     
     
     
-    IndexQuery<V> find();
+    IQuery<V> find();
 
-    IndexQuery<V> find(Comparator<V> index, V value);
+    IQuery<V> find(Comparator<V> index, V value);
     
-    <T> IndexQuery<V> find(Function<V,T> index, T value);
+    <T> IQuery<V> find(Function<V,T> index, T value);
 
-    IndexQuery<V> find(String index, Object value);
+    IQuery<V> find(String index, Object value);
     
         
     

+ 78 - 108
assira/src/main/java/net/ranides/assira/collection/maps/IndexTreeMap.java

@@ -4,7 +4,7 @@
  * @license WTFPL
  * @url http://ranides.net/projects/assira.drafts
  */
-package net.ranides.assira.collection.maps;
+package net.ranides.assira.index;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -17,11 +17,15 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.SortedMap;
 import java.util.SortedSet;
+import java.util.function.Consumer;
 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.MultiMap;
+import net.ranides.assira.collection.maps.RBTreeMultiMap;
 import net.ranides.assira.collection.sets.ASortedSet;
 import net.ranides.assira.collection.sets.IdentSet;
+import net.ranides.assira.collection.sets.MultiSet;
 import net.ranides.assira.collection.sets.RBTreeMultiSet;
 
 import net.ranides.assira.generic.CompareUtils;
@@ -30,7 +34,7 @@ import net.ranides.assira.generic.CompareUtils;
  *
  * @author Ranides Atterwim <ranides@gmail.com>
  */
-public class IndexTreeMap<V> extends AIndexMap<V> {
+public class IQueryMapTree<V> extends IQueryAbstract.IQMap<V> {
     
     private final Map<String, Comparator> name2sindex = new HashMap<>();
     
@@ -41,7 +45,7 @@ public class IndexTreeMap<V> extends AIndexMap<V> {
     private final Map<Function, RBTreeMultiMap<Object, V>> mindexes = new HashMap<>();
 
     @Override
-    public IndexMap<V> index(String name, Comparator<V> index) {
+    public IQueryMap<V> index(String name, Comparator<V> index) {
         RBTreeMultiSet<V> set = new RBTreeMultiSet<>(index);
         cindexes.put(index, set);
         name2sindex.put(name, index);
@@ -52,7 +56,7 @@ public class IndexTreeMap<V> extends AIndexMap<V> {
     }
 
     @Override
-    public <T> IndexMap<V> index(String name, Function<V, T> index) {
+    public <T> IQueryMap<V> index(String name, Function<V, T> index) {
         RBTreeMultiMap<Object,V> map = new RBTreeMultiMap<>();
         mindexes.put(index, map);
         name2mindex.put(name, index);
@@ -62,22 +66,10 @@ public class IndexTreeMap<V> extends AIndexMap<V> {
         return this;
     }
 
-    @SuppressWarnings("unchecked")
-    @Override
-    protected <T> Function<V, T> mindex(String name) {
-        return name2mindex.get(name);
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    protected Comparator<V> sindex(String name) {
-        return name2sindex.get(name);
-    }
-    
     @Override
     public void remove(V value) {
         for(SortedSet<V> index : cindexes.values()) {
-            IndexTreeMap.this.iremove(index, value);
+            IQueryMapTree.this.iremove(index, value);
         }
         for(SortedMap<Object,V> index : mindexes.values()) {
             iremove(index, value);
@@ -131,11 +123,10 @@ public class IndexTreeMap<V> extends AIndexMap<V> {
             }
         }
     }
-
     
     @Override
-    public AIndexQuery<V> find() {
-        return new CHQuery();
+    public IQueryAbstract<V> find() {
+        return new TreeQuery();
     }
 
     @SuppressWarnings("unchecked")
@@ -156,6 +147,9 @@ public class IndexTreeMap<V> extends AIndexMap<V> {
         for(SortedSet<V> index : cindexes.values()) {
             index.clear();
         }
+        for(SortedMap<Object,V> index : mindexes.values()) {
+            index.clear();
+        }
     }
     
     private Collection<V> values() {
@@ -164,6 +158,16 @@ public class IndexTreeMap<V> extends AIndexMap<V> {
         }
         return cindexes.values().iterator().next();
     }
+    
+    private static <T> Collection<T> tail(ASortedMap<Object, T> mi, Object value) {
+        Object last = after(mi,value);
+        return last==null ? Collections.emptyList() : mi.tailMap(last).values();
+    }
+    
+    private static <T> Collection<T> tail(ASortedSet<T> ci, T value) {
+        T last = after(ci,value);
+        return last==null ? Collections.emptyList() : ci.tailSet(last);
+    }
 
     private static Object after(ASortedMap<Object, ?> map, Object value) {
         Comparator<Object> cmp = CompareUtils.comparator();
@@ -189,168 +193,134 @@ public class IndexTreeMap<V> extends AIndexMap<V> {
         return null;
     }
     
-    private Collection<V> merge(Collection<V> a, Collection<V> b) {
-        Collection<V> out = new IdentSet<>(a.size() + b.size());
+    private static <T> Collection<T> merge(Collection<T> a, Collection<T> b) {
+        Collection<T> out = new IdentSet<>(a.size() + b.size());
         out.addAll(a);
         out.addAll(b);
         return out;
     }
 
     
-    private final class CHQuery extends AIndexQuery<V> {
+    private final class TreeQuery extends IQueryAbstract<V> {
         
         private final List<Supplier<Collection<V>>> selectors;
         
         private final boolean require;
 
-        public CHQuery() {
+        public TreeQuery() {
             this.selectors = Collections.emptyList();
             this.require = true;
         }
         
-        public CHQuery(CHQuery query, Supplier<Collection<V>> selector) {
+        public TreeQuery(TreeQuery query, Supplier<Collection<V>> selector) {
             this.selectors = new ArrayList<>(query.selectors.size()+1);
             this.selectors.addAll(query.selectors);
             this.selectors.add(selector);
             this.require = true;
         }
         
-        public CHQuery(CHQuery query, boolean require) {
+        public TreeQuery(TreeQuery query, boolean require) {
             this.selectors = new ArrayList<>(query.selectors);
             this.require = require;
         }
-
+        
+        @SuppressWarnings("unchecked")
         @Override
-        public IndexQuery<V> require() {
-            return new CHQuery(this, true);
+        protected <T> Function<V, T> mindex(String name) {
+            return name2mindex.get(name);
         }
 
+        @SuppressWarnings("unchecked")
         @Override
-        public IndexQuery<V> optional() {
-            return new CHQuery(this, false);
+        protected Comparator<V> sindex(String name) {
+            return name2sindex.get(name);
         }
-        
+
         @Override
-        protected AIndexMap<V> parent() {
-            return IndexTreeMap.this;
+        public IQuery<V> require() {
+            return new TreeQuery(this, true);
         }
 
         @Override
-        public Stream<V> stream() {
-            return select().stream();
+        public IQuery<V> optional() {
+            return new TreeQuery(this, false);
         }
 
         @Override
-        public int size() {
-            return select().size();
+        public IQuery<V> eq(Comparator<V> index, V value) {
+            RBTreeMultiSet<V> ci = cindexes.get(index);
+            return select(ci, () -> ci.getAll(value));
         }
 
         @Override
-        public Iterator<V> iterator() {
-            return select().iterator();
+        public <T> IQuery<V> eq(Function<V, T> index, T value) {
+            RBTreeMultiMap<Object, V> mi = mindexes.get(index);
+            return select(mi, () -> mi.getAll(value));
         }
 
         @Override
-        public IndexQuery<V> eq(Comparator<V> index, V value) {
+        public IQuery<V> gt(Comparator<V> index, V value) {
             RBTreeMultiSet<V> ci = cindexes.get(index);
-            if(require) {
-                return new CHQuery(this, () -> ci.getAll(value));
-            } else {
-                return new CHQuery(this, () -> {
-                    return merge(ci.getAll(value), ci.getAll(null));
-                });
-            }
+            return select(ci, () -> tail(ci, value));
         }
 
+        
         @Override
-        public <T> IndexQuery<V> eq(Function<V, T> index, T value) {
+        public <T> IQuery<V> gt(Function<V, T> index, T value) {
             RBTreeMultiMap<Object, V> mi = mindexes.get(index);
-            if(require) {
-                return new CHQuery(this, () -> mi.getAll(value));
-            } else {
-                return new CHQuery(this, () -> {
-                    return merge(mi.getAll(value), mi.getAll(null));
-                });
-            }
+            return select(mi, () -> tail(mi, value));
         }
 
         @Override
-        public IndexQuery<V> gt(Comparator<V> index, V value) {
+        public IQuery<V> lt(Comparator<V> index, V value) {
             RBTreeMultiSet<V> ci = cindexes.get(index);
-            if(require) {
-                return new CHQuery(this, () -> {
-                    V last = after(ci,value);
-                    return last==null ? Collections.emptyList() : ci.tailSet(last);
-                });
-            } else {
-                return new CHQuery(this, () -> {
-                    V last = after(ci,value);
-                    return last==null ? ci.getAll(null) : merge(ci.tailSet(last), ci.getAll(null));
-                });
-            }
+            return select(ci, () -> ci.headSet(value));
         }
 
         @Override
-        public <T> IndexQuery<V> gt(Function<V, T> index, T value) {
+        public <T> IQuery<V> lt(Function<V, T> index, T value) {
             RBTreeMultiMap<Object, V> mi = mindexes.get(index);
-            if(require) {
-                return new CHQuery(this, () -> {
-                    Object last = after(mi,value);
-                    return last==null ? Collections.emptyList() : mi.tailMap(last).values();
-                });
-            } else {
-                return new CHQuery(this, () -> {
-                    Object last = after(mi,value);
-                    return last==null ? mi.getAll(null) : merge(mi.tailMap(last).values(), mi.getAll(null));
-                });
-            }
+            return select(mi, () -> mi.headMap(value).values());
         }
 
         @Override
-        public IndexQuery<V> lt(Comparator<V> index, V value) {
+        public IQuery<V> in(Comparator<V> index, V begin, V end) {
             RBTreeMultiSet<V> ci = cindexes.get(index);
-            if(require) {
-                return new CHQuery(this, () -> ci.headSet(value));
-            } else {
-                return new CHQuery(this, () -> merge(ci.headSet(value), ci.getAll(null)));
-            }
+            return select(ci, () -> ci.subSet(begin, end));
         }
 
         @Override
-        public <T> IndexQuery<V> lt(Function<V, T> index, T value) {
+        public <T> IQuery<V> in(Function<V, T> index, T begin, T end) {
             RBTreeMultiMap<Object, V> mi = mindexes.get(index);
-            if(require) {
-                return new CHQuery(this, () -> mi.headMap(value).values());
-            } else {
-                return new CHQuery(this, () -> merge(mi.headMap(value).values(), mi.getAll(null)));
-            }
+            return select(mi, () -> mi.subMap(begin, end).values());
         }
-
+        
         @Override
-        public IndexQuery<V> in(Comparator<V> index, V begin, V end) {
-            RBTreeMultiSet<V> ci = cindexes.get(index);
+        public void update(Consumer<? super V> consumer) {
+            select().forEach(v -> IQueryMapTree.this.update(v, consumer));
+        }
+        
+        @Override
+        public void remove() {
+            removeAll(select());
+        }
+        
+        private <T> IQuery<V> select(MultiSet<V> ci, Supplier<Collection<V>> f) {
             if(require) {
-                return new CHQuery(this, () -> ci.subSet(begin, end));
+                return new TreeQuery(this, f);
             } else {
-                return new CHQuery(this, () -> merge(ci.subSet(begin, end), ci.getAll(null)));
+                return new TreeQuery(this, () -> merge(f.get(), ci.getAll(null)));
             }
         }
 
-        @Override
-        public <T> IndexQuery<V> in(Function<V, T> index, T begin, T end) {
-            RBTreeMultiMap<Object, V> mi = mindexes.get(index);
+        private <T> IQuery<V> select(MultiMap<Object, V> mi, Supplier<Collection<V>> f) {
             if(require) {
-                return new CHQuery(this, () -> mi.subMap(begin, end).values());
+                return new TreeQuery(this, f);
             } else {
-                return new CHQuery(this, () -> merge(mi.subMap(begin, end).values(), mi.getAll(null)));
+                return new TreeQuery(this, () -> merge(f.get(), mi.getAll(null)));
             }
         }
         
-        @Override
-        public void remove() {
-            removeAll(select());
-        }
-        
         @Override
         protected Collection<V> select() {
             int psize = 0;

+ 8 - 5
assira/src/test/java/net/ranides/assira/collection/maps/IndexTreeMapTest.java

@@ -6,10 +6,13 @@
  */
 package net.ranides.assira.collection.maps;
 
+import net.ranides.assira.index.IQueryMapTree;
 import java.util.Objects;
 import net.ranides.assira.generic.CompareUtils;
 import org.junit.Test;
 import static org.junit.Assert.*;
+import net.ranides.assira.index.IQuery;
+import net.ranides.assira.index.IQueryMap;
 
 /**
  *
@@ -20,7 +23,7 @@ public class IndexTreeMapTest {
     @Test
     public void testSetIndex() {
         
-        IndexMap<Person> db = new IndexTreeMap<>();
+        IQueryMap<Person> db = new IQueryMapTree<>();
         
         db.index("name", (a,b) -> CompareUtils.cmp(a.name, b.name));
         db.index("surname", (a,b) -> CompareUtils.cmp(a.surname, b.surname));
@@ -66,7 +69,7 @@ public class IndexTreeMapTest {
     @Test
     public void testMapIndex() {
         
-        IndexMap<Person> db = new IndexTreeMap<>();
+        IQueryMap<Person> db = new IQueryMapTree<>();
         
         db.index("name", a -> a.name);
         db.index("surname", a -> a.surname);
@@ -112,7 +115,7 @@ public class IndexTreeMapTest {
     @Test
     public void testMapIndexOptional() {
         
-        IndexMap<Person> db = new IndexTreeMap<>();
+        IQueryMap<Person> db = new IQueryMapTree<>();
         
         db.index("name", a -> a.name);
         db.index("surname", a -> a.surname);
@@ -138,11 +141,11 @@ public class IndexTreeMapTest {
         );
     }
     
-    private static void assertQueryEquals(String expected, IndexQuery<Person> query) {
+    private static void assertQueryEquals(String expected, IQuery<Person> query) {
         assertEquals(expected, query.sort().list().toString());
     }
 
-    private static void putData(IndexMap<Person> db) {
+    private static void putData(IQueryMap<Person> db) {
         db.put(new Person("Tom", "A", 17));
         db.put(new Person("Tom", "B", 23));
         db.put(new Person("Joe", "A", 20));