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 aConcurrentHashMapwhich indexesCompoundAttributes, storingCompoundValueTupleobjects as keys. Supports query types: The constructor of this index acceptsFactoryobjects, 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.DefaultIndexMapFactoryandCompoundIndex.DefaultValueSetFactory.- Author:
- Niall Gallagher
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCompoundIndex.DefaultIndexMapFactory<O>Creates an index map using default settings.static classCompoundIndex.DefaultValueSetFactory<O>Creates a value set using default settings.
-
Field Summary
Fields Modifier and Type Field Description protected CompoundAttribute<O>attributeprotected static intINDEX_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 protectedCompoundIndex(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.IntegergetCountForKey(CompoundValueTuple<O> key, QueryOptions queryOptions)IntegergetCountOfDistinctKeys(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 statisticsKeyStatisticsfor all distinct keys in the indexbooleanisMutable()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 newCompoundIndexon 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 newCompoundIndexon the given combination of attributes.ResultSet<O>retrieve(Query<O> query, QueryOptions queryOptions)Returns aResultSetwhich when iterated will return objects from the index matching the query supplied.booleansupportsQuery(Query<O> query, QueryOptions queryOptions)Returns true if the givenQueryis based on the same list of attributes as theCompoundAttributeon 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 newCompoundIndexusing the givenQuantizeron the given combination of attributes.static <O> CompoundIndex<O>withQuantizerOnAttributes(Quantizer<CompoundValueTuple<O>> quantizer, Attribute<O,?>... attributes)Creates a newCompoundIndexusing the givenQuantizeron 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 givenQueryis based on the same list of attributes as theCompoundAttributeon which this compound index is based.- Specified by:
supportsQueryin interfaceIndex<O>- Overrides:
supportsQueryin classAbstractAttributeIndex<CompoundValueTuple<O>,O>- Parameters:
query- AQueryto testqueryOptions- Optional parameters for the query- Returns:
- True if the given
Queryis based on the same list of attributes as theCompoundAttributeon which this compound index is based, otherwise false
-
getAttribute
public CompoundAttribute<O> getAttribute()
Description copied from class:AbstractAttributeIndexReturns the attribute which was supplied to the constructor.- Specified by:
getAttributein interfaceAttributeIndex<CompoundValueTuple<O>,O>- Overrides:
getAttributein 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:IndexReturns 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:
getEffectiveIndexin 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 aResultSetwhich when iterated will return objects from the index matching the query supplied. UsuallyResultSets 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:
retrievein 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:
getDistinctKeysin 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:
getCountForKeyin 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:KeyStatisticsIndexReturns the count of distinct keys in the index.- Specified by:
getCountOfDistinctKeysin interfaceKeyStatisticsIndex<CompoundValueTuple<O>,O>- Overrides:
getCountOfDistinctKeysin 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:KeyStatisticsIndexReturns the statisticsKeyStatisticsfor all distinct keys in the index- Specified by:
getStatisticsForDistinctKeysin interfaceKeyStatisticsIndex<CompoundValueTuple<O>,O>- Overrides:
getStatisticsForDistinctKeysin classAbstractMapBasedAttributeIndex<CompoundValueTuple<O>,O,ConcurrentMap<CompoundValueTuple<O>,StoredResultSet<O>>>- Parameters:
queryOptions- Optional parameters for the query- Returns:
- The statistics
KeyStatisticsfor all distinct keys in the index
-
getKeysAndValues
public CloseableIterable<KeyValue<CompoundValueTuple<O>,O>> getKeysAndValues(QueryOptions queryOptions)
Description copied from interface:KeyStatisticsIndexReturns 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:
getKeysAndValuesin 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 aResultSetwhich 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 givenResultSetunmodified.- Parameters:
storedResultSet- AResultSetstored against a quantized key in the indexquery- The query against which results should be matchedqueryOptions- Optional parameters for the query- Returns:
- A
ResultSetwhich 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 newCompoundIndexon 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
CompoundIndexbased 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 newCompoundIndexon 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
CompoundIndexbased on these attributes
-
withQuantizerOnAttributes
public static <O> CompoundIndex<O> withQuantizerOnAttributes(Quantizer<CompoundValueTuple<O>> quantizer, Attribute<O,?>... attributes)
Creates a newCompoundIndexusing the givenQuantizeron 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- AQuantizerto use in this index- Returns:
- A
CompoundIndexbased 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 newCompoundIndexusing the givenQuantizeron 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- AQuantizerto use in this index- Returns:
- A
CompoundIndexbased on these attributes
-
-