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