From 04d6ac74e3ce983a2e701fa84f2ab95c486e97d7 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 8 Jan 2008 00:49:07 +0000 Subject: Support ExistsFilter. --- .../com/amazon/carbonado/qe/FilteringScore.java | 15 +++++++++--- .../amazon/carbonado/qe/PropertyFilterList.java | 28 +++++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') diff --git a/src/main/java/com/amazon/carbonado/qe/FilteringScore.java b/src/main/java/com/amazon/carbonado/qe/FilteringScore.java index 3831b3e..5efb219 100644 --- a/src/main/java/com/amazon/carbonado/qe/FilteringScore.java +++ b/src/main/java/com/amazon/carbonado/qe/FilteringScore.java @@ -112,7 +112,7 @@ public class FilteringScore { // operations are last. PropertyFilterList originalFilterList = PropertyFilterList.get(filter); - // Copy so it so that matching elements can be removed. + // Copy it so that matching elements can be removed. List> filterList = new ArrayList>(originalFilterList); // First find the identity matches. @@ -209,6 +209,15 @@ public class FilteringScore { indexProperties[indexPropPos].getDirection() == Direction.DESCENDING; } + List> remainderFilters; + if (originalFilterList.getExistsFilters().size() == 0) { + remainderFilters = filterList; + } else { + remainderFilters = new ArrayList>(filterList); + // Java "generics" suck. Note the stupid cast to make this work. + ((List) remainderFilters).addAll(originalFilterList.getExistsFilters()); + } + return new FilteringScore(indexProperties, clustered, unique, @@ -217,7 +226,7 @@ public class FilteringScore { rangeEndFilters, arrangementScore, preferenceScore, - filterList, + remainderFilters, shouldReverseRange); } @@ -303,7 +312,7 @@ public class FilteringScore { List> rangeEndFilters, int arrangementScore, BigInteger preferenceScore, - List> remainderFilters, + List> remainderFilters, boolean shouldReverseRange) { mIndexProperties = indexProperties; diff --git a/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java b/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java index 497a620..279430c 100644 --- a/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java +++ b/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java @@ -30,6 +30,7 @@ import org.cojen.util.SoftValuedHashMap; import com.amazon.carbonado.Storable; +import com.amazon.carbonado.filter.ExistsFilter; import com.amazon.carbonado.filter.Filter; import com.amazon.carbonado.filter.OrFilter; import com.amazon.carbonado.filter.PropertyFilter; @@ -68,20 +69,30 @@ class PropertyFilterList extends AbstractList> list; Map, Integer> posMap; + List> existsList; if (filter == null) { list = Collections.emptyList(); posMap = Collections.emptyMap(); + existsList = Collections.emptyList(); } else if (filter instanceof PropertyFilter) { list = Collections.singletonList((PropertyFilter) filter); posMap = Collections.singletonMap((PropertyFilter) filter, 0); + existsList = Collections.emptyList(); } else { list = new ArrayList>(); + existsList = new ArrayList>(); final List> flist = list; + final List> fexistsList = existsList; filter.accept(new Visitor() { public Object visit(OrFilter filter, Object param) { - throw new IllegalArgumentException("Logical 'or' not allowed"); + throw new IllegalArgumentException("OrFilter not allowed"); + } + + public Object visit(ExistsFilter filter, Object param) { + fexistsList.add(filter); + return null; } public Object visit(PropertyFilter filter, Object param) { @@ -99,9 +110,10 @@ class PropertyFilterList extends AbstractList(list, posMap); + plist = new PropertyFilterList(list, posMap, existsList); synchronized (cCache) { cCache.put(filter, plist); @@ -112,12 +124,15 @@ class PropertyFilterList extends AbstractList> mList; private final Map, Integer> mPosMap; + private final List> mExistsList; private PropertyFilterList(List> list, - Map, Integer> posMap) + Map, Integer> posMap, + List> existsList) { mList = list; mPosMap = posMap; + mExistsList = existsList; } public Integer getOriginalPosition(PropertyFilter filter) { @@ -132,6 +147,13 @@ class PropertyFilterList extends AbstractList> getExistsFilters() { + return mExistsList; + } + private static class PFComparator implements Comparator> { -- cgit v1.2.3