Class CompoundIndex<O>
- java.lang.Object
-
- com.googlecode.cqengine.index.support.AbstractAttributeIndex<A,O>
-
- com.googlecode.cqengine.index.support.AbstractMapBasedAttributeIndex<CompoundValueTuple<O>,O,ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>>
-
- com.googlecode.cqengine.index.compound.CompoundIndex<O>
-
- All Implemented Interfaces:
ModificationListener<O>
,AttributeIndex<CompoundValueTuple<O>,O>
,Index<O>
,OnHeapTypeIndex
,KeyStatisticsAttributeIndex<CompoundValueTuple<O>,O>
,KeyStatisticsIndex<CompoundValueTuple<O>,O>
public class CompoundIndex<O> extends AbstractMapBasedAttributeIndex<CompoundValueTuple<O>,O,ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>> implements KeyStatisticsAttributeIndex<CompoundValueTuple<O>,O>, OnHeapTypeIndex
An index backed by aConcurrentHashMap
which indexesCompoundAttribute
s, storingCompoundValueTuple
objects as keys. Supports query types: The constructor of this index acceptsFactory
objects, from which it will create the map and value sets it uses internally. This allows the application to "tune" the construction parameters of these maps/sets, by supplying custom factories. For default settings, supplyCompoundIndex.DefaultIndexMapFactory
andCompoundIndex.DefaultValueSetFactory
.- Author:
- Niall Gallagher
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CompoundIndex.DefaultIndexMapFactory<O>
Creates an index map using default settings.static class
CompoundIndex.DefaultValueSetFactory<O>
Creates a value set using default settings.
-
Field Summary
Fields Modifier and Type Field Description protected CompoundAttribute<O>
attribute
protected static int
INDEX_RETRIEVAL_COST
-
Fields inherited from class com.googlecode.cqengine.index.support.AbstractMapBasedAttributeIndex
indexMap, indexMapFactory, valueSetFactory
-
Fields inherited from class com.googlecode.cqengine.index.support.AbstractAttributeIndex
supportedQueries
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CompoundIndex(Factory<ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>> indexMapFactory, Factory<StoredResultSet<O>> valueSetFactory, CompoundAttribute<O> attribute)
Package-private constructor, used by static factory methods.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ResultSet<O>
filterForQuantization(ResultSet<O> storedResultSet, Query<O> query, QueryOptions queryOptions)
CompoundAttribute<O>
getAttribute()
Returns the attribute which was supplied to the constructor.Integer
getCountForKey(CompoundValueTuple<O> key, QueryOptions queryOptions)
Integer
getCountOfDistinctKeys(QueryOptions queryOptions)
Returns the count of distinct keys in the index.CloseableIterable<CompoundValueTuple<O>>
getDistinctKeys(QueryOptions queryOptions)
Index<O>
getEffectiveIndex()
Returns the effective index, which Persistence objects will use to determine the identity of the index making persistence requests.CloseableIterable<KeyValue<CompoundValueTuple<O>,O>>
getKeysAndValues(QueryOptions queryOptions)
Returns the keys and corresponding values for those keys in the index.CloseableIterable<KeyStatistics<CompoundValueTuple<O>>>
getStatisticsForDistinctKeys(QueryOptions queryOptions)
Returns the statisticsKeyStatistics
for all distinct keys in the indexboolean
isMutable()
Indicates if objects can be added to or removed from the index after the index has been built.static <O> CompoundIndex<O>
onAttributes(Attribute<O,?>... attributes)
Creates a newCompoundIndex
on the given combination of attributes.static <O> CompoundIndex<O>
onAttributes(Factory<ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>> indexMapFactory, Factory<StoredResultSet<O>> valueSetFactory, Attribute<O,?>... attributes)
Creates a newCompoundIndex
on the given combination of attributes.ResultSet<O>
retrieve(Query<O> query, QueryOptions queryOptions)
Returns aResultSet
which when iterated will return objects from the index matching the query supplied.boolean
supportsQuery(Query<O> query, QueryOptions queryOptions)
Returns true if the givenQuery
is based on the same list of attributes as theCompoundAttribute
on which this compound index is based.static <O> CompoundIndex<O>
withQuantizerOnAttributes(Factory<ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>> indexMapFactory, Factory<StoredResultSet<O>> valueSetFactory, Quantizer<CompoundValueTuple<O>> quantizer, Attribute<O,?>... attributes)
Creates a newCompoundIndex
using the givenQuantizer
on the given combination of attributes.static <O> CompoundIndex<O>
withQuantizerOnAttributes(Quantizer<CompoundValueTuple<O>> quantizer, Attribute<O,?>... attributes)
Creates a newCompoundIndex
using the givenQuantizer
on the given combination of attributes.-
Methods inherited from class com.googlecode.cqengine.index.support.AbstractMapBasedAttributeIndex
addAll, clear, destroy, getCountForKey, getDistinctKeys, getKeysAndValues, getQuantizedValue, init, isQuantized, removeAll, wrapNonCloseable
-
Methods inherited from class com.googlecode.cqengine.index.support.AbstractAttributeIndex
equals, hashCode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.googlecode.cqengine.index.Index
isQuantized
-
-
-
-
Field Detail
-
INDEX_RETRIEVAL_COST
protected static final int INDEX_RETRIEVAL_COST
- See Also:
- Constant Field Values
-
attribute
protected final CompoundAttribute<O> attribute
-
-
Constructor Detail
-
CompoundIndex
protected CompoundIndex(Factory<ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>> indexMapFactory, Factory<StoredResultSet<O>> valueSetFactory, CompoundAttribute<O> attribute)
Package-private constructor, used by static factory methods. Creates a new HashIndex initialized to index the supplied attribute.- Parameters:
indexMapFactory
- A factory used to create the main map-based data structure used by the indexvalueSetFactory
- A factory used to create sets to store values in the indexattribute
- The attribute on which the index will be built
-
-
Method Detail
-
supportsQuery
public boolean supportsQuery(Query<O> query, QueryOptions queryOptions)
Returns true if the givenQuery
is based on the same list of attributes as theCompoundAttribute
on which this compound index is based.- Specified by:
supportsQuery
in interfaceIndex<O>
- Overrides:
supportsQuery
in classAbstractAttributeIndex<CompoundValueTuple<O>,O>
- Parameters:
query
- AQuery
to testqueryOptions
- Optional parameters for the query- Returns:
- True if the given
Query
is based on the same list of attributes as theCompoundAttribute
on which this compound index is based, otherwise false
-
getAttribute
public CompoundAttribute<O> getAttribute()
Description copied from class:AbstractAttributeIndex
Returns the attribute which was supplied to the constructor.- Specified by:
getAttribute
in interfaceAttributeIndex<CompoundValueTuple<O>,O>
- Overrides:
getAttribute
in classAbstractAttributeIndex<CompoundValueTuple<O>,O>
- Returns:
- the attribute which was supplied to the constructor
-
isMutable
public boolean isMutable()
Indicates if objects can be added to or removed from the index after the index has been built. This index is mutable.
-
getEffectiveIndex
public Index<O> getEffectiveIndex()
Description copied from interface:Index
Returns the effective index, which Persistence objects will use to determine the identity of the index making persistence requests. Most Index implementations will typically return a reference to themselves ('this'). However in advanced cases when one index delegates to another, the implementation of the wrapping index will create a subclass the delegate index, and override this method in the delegate index so that when the delegate index interacts with the persistence, it will identify itself as the outer or "effective" index.- Specified by:
getEffectiveIndex
in interfaceIndex<O>
- Returns:
- The effective index, in the case that this index is wrapped by another index.
-
retrieve
public ResultSet<O> retrieve(Query<O> query, QueryOptions queryOptions)
Returns aResultSet
which when iterated will return objects from the index matching the query supplied. UsuallyResultSet
s are lazy which means that they don't actually do any work, or encapsulate or materialize matching objects, but rather they encapsulate logic to fetch matching objects from the index on-the-fly as the application iterates through theResultSet
.- Specified by:
retrieve
in interfaceIndex<O>
- Parameters:
query
- An object which specifies some restriction on an attribute of an objectqueryOptions
- Optional parameters for the query- Returns:
- A set of objects with attributes matching the restriction imposed by the query
- See Also:
Index.supportsQuery(Query, QueryOptions)
-
getDistinctKeys
public CloseableIterable<CompoundValueTuple<O>> getDistinctKeys(QueryOptions queryOptions)
- Specified by:
getDistinctKeys
in interfaceKeyStatisticsIndex<CompoundValueTuple<O>,O>
- Parameters:
queryOptions
- Optional parameters for the query- Returns:
- The distinct keys in the index
-
getCountForKey
public Integer getCountForKey(CompoundValueTuple<O> key, QueryOptions queryOptions)
- Specified by:
getCountForKey
in interfaceKeyStatisticsIndex<CompoundValueTuple<O>,O>
- Parameters:
key
- A key which may be contained in the indexqueryOptions
- Optional parameters for the query- Returns:
- The number of objects stored in the bucket in the index with the given key
-
getCountOfDistinctKeys
public Integer getCountOfDistinctKeys(QueryOptions queryOptions)
Description copied from interface:KeyStatisticsIndex
Returns the count of distinct keys in the index.- Specified by:
getCountOfDistinctKeys
in interfaceKeyStatisticsIndex<CompoundValueTuple<O>,O>
- Overrides:
getCountOfDistinctKeys
in classAbstractMapBasedAttributeIndex<CompoundValueTuple<O>,O,ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>>
- Parameters:
queryOptions
- Optional parameters for the query- Returns:
- The count of distinct keys in the index.
-
getStatisticsForDistinctKeys
public CloseableIterable<KeyStatistics<CompoundValueTuple<O>>> getStatisticsForDistinctKeys(QueryOptions queryOptions)
Description copied from interface:KeyStatisticsIndex
Returns the statisticsKeyStatistics
for all distinct keys in the index- Specified by:
getStatisticsForDistinctKeys
in interfaceKeyStatisticsIndex<CompoundValueTuple<O>,O>
- Overrides:
getStatisticsForDistinctKeys
in classAbstractMapBasedAttributeIndex<CompoundValueTuple<O>,O,ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>>
- Parameters:
queryOptions
- Optional parameters for the query- Returns:
- The statistics
KeyStatistics
for all distinct keys in the index
-
getKeysAndValues
public CloseableIterable<KeyValue<CompoundValueTuple<O>,O>> getKeysAndValues(QueryOptions queryOptions)
Description copied from interface:KeyStatisticsIndex
Returns the keys and corresponding values for those keys in the index. Note the same key will be returned multiple times if more than one object has the same key. Also the same value might be returned multiple times, each time for a different key, if the index is built on a multi-value attribute.- Specified by:
getKeysAndValues
in interfaceKeyStatisticsIndex<CompoundValueTuple<O>,O>
- Parameters:
queryOptions
- Optional parameters for the query- Returns:
- The keys and corresponding values for those keys in the index
-
filterForQuantization
protected ResultSet<O> filterForQuantization(ResultSet<O> storedResultSet, Query<O> query, QueryOptions queryOptions)
A no-op method which can be overridden by a subclass to return aResultSet
which filters objects from the givenResultSet
, to return only those objects matching the query, for the case that the index is using aQuantizer
. This default implementation simply returns the givenResultSet
unmodified.- Parameters:
storedResultSet
- AResultSet
stored against a quantized key in the indexquery
- The query against which results should be matchedqueryOptions
- Optional parameters for the query- Returns:
- A
ResultSet
which filters objects from the givenResultSet
, to return only those objects matching the query
-
onAttributes
public static <O> CompoundIndex<O> onAttributes(Attribute<O,?>... attributes)
Creates a newCompoundIndex
on the given combination of attributes.- Type Parameters:
O
- The type of the object containing the attributes- Parameters:
attributes
- The combination of simple attributes on which index will be built- Returns:
- A
CompoundIndex
based on these attributes
-
onAttributes
public static <O> CompoundIndex<O> onAttributes(Factory<ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>> indexMapFactory, Factory<StoredResultSet<O>> valueSetFactory, Attribute<O,?>... attributes)
Creates a newCompoundIndex
on the given combination of attributes.- Type Parameters:
O
- The type of the object containing the attributes- Parameters:
indexMapFactory
- A factory used to create the main map-based data structure used by the indexvalueSetFactory
- A factory used to create sets to store values in the indexattributes
- The combination of simple attributes on which index will be built- Returns:
- A
CompoundIndex
based on these attributes
-
withQuantizerOnAttributes
public static <O> CompoundIndex<O> withQuantizerOnAttributes(Quantizer<CompoundValueTuple<O>> quantizer, Attribute<O,?>... attributes)
Creates a newCompoundIndex
using the givenQuantizer
on the given combination of attributes.- Type Parameters:
O
- The type of the object containing the attributes- Parameters:
attributes
- The combination of simple attributes on which index will be builtquantizer
- AQuantizer
to use in this index- Returns:
- A
CompoundIndex
based on these attributes
-
withQuantizerOnAttributes
public static <O> CompoundIndex<O> withQuantizerOnAttributes(Factory<ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>> indexMapFactory, Factory<StoredResultSet<O>> valueSetFactory, Quantizer<CompoundValueTuple<O>> quantizer, Attribute<O,?>... attributes)
Creates a newCompoundIndex
using the givenQuantizer
on the given combination of attributes.- Type Parameters:
O
- The type of the object containing the attributes- Parameters:
indexMapFactory
- A factory used to create the main map-based data structure used by the indexvalueSetFactory
- A factory used to create sets to store values in the indexattributes
- The combination of simple attributes on which index will be builtquantizer
- AQuantizer
to use in this index- Returns:
- A
CompoundIndex
based on these attributes
-
-