Class CompoundAttribute<O>
- java.lang.Object
-
- com.googlecode.cqengine.index.compound.support.CompoundAttribute<O>
-
- All Implemented Interfaces:
Attribute<O,CompoundValueTuple<O>>
public class CompoundAttribute<O> extends Object implements Attribute<O,CompoundValueTuple<O>>
A private implementation ofAttribute
used internally byCompoundIndex
, which groups several other attributes. Note that, being like regularAttribute
s, objects of this type do not represent values but rather the means to obtain values from fields in an object. Values for compound attributes are encapsulated separately inCompoundValueTuple
objects. TheAttribute.getValues(Object, com.googlecode.cqengine.query.option.QueryOptions)
method returns a list of these tuples for a given object. Algorithm to generate tuples
The list of tuples generated for aCompoundAttribute
referencing a given object, depends on whether theCompoundAttribute
groups onlySimpleAttribute
s, or whether it groups anyMultiValueAttribute
s.-
Generating tuples for a group of
SimpleAttribute
s
If a compound attribute groups onlySimpleAttribute
s, then the list of tuples generated by theCompoundAttribute
is straightforward and will contain just one tuple, comprising the values from each of the fields referenced by theSimpleAttribute
s -
Generating tuples for
MultiValueAttribute
s
If a compound attribute groups one or moreMultiValueAttribute
s, then the determination of tuples is more complicated, and is as follows.MultiValueAttribute
s can return multiple values from a single field in an object. The purpose ofMultiValueAttribute
is to allow an object to be indexed separately against each of the values from this field. Given that aCompoundAttribute
spans multiple attributes, the presence of one or moreMultiValueAttribute
s means that several possible combinations of values should match the object in the index. To generate tuples forCompoundAttribute
s spanningMultiValueAttribute
s, theAttribute.getValues(Object, com.googlecode.cqengine.query.option.QueryOptions)
method will retrieve a list of values from the object for each of the component attributes. It will then generate all possible combinations of values between these lists as tuples, usingTupleCombinationGenerator.generateCombinations(java.util.List)
. Example:
If we have the following lists of values from attributes:
Values from first attribute:1
Values from second attribute:"bar", "baz"
Values from third attribute:2.0, 3.0, 4.0
The following tuples will be generated:
[[1, bar, 2.0], [1, bar, 3.0], [1, bar, 4.0], [1, baz, 2.0], [1, baz, 3.0], [1, baz, 4.0]]
TheAttribute.getValues(Object, com.googlecode.cqengine.query.option.QueryOptions)
method would then return these tuples as a list ofCompoundValueTuple
objects
- Author:
- Niall Gallagher
-
-
Constructor Summary
Constructors Constructor Description CompoundAttribute(List<Attribute<O,?>> attributes)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
String
getAttributeName()
Returns the name of the attribute, as supplied to the constructor.Class<CompoundValueTuple<O>>
getAttributeType()
Returns the type of the attribute.Class<O>
getObjectType()
Returns the type of the object which contains the attribute.Iterable<CompoundValueTuple<O>>
getValues(O object, QueryOptions queryOptions)
Returns a list ofCompoundValueTuple
objects for the given object, containing all possible combinations of attribute values against which the object can be indexed.int
hashCode()
int
size()
String
toString()
-
-
-
Method Detail
-
size
public int size()
-
getObjectType
public Class<O> getObjectType()
Description copied from interface:Attribute
Returns the type of the object which contains the attribute.- Specified by:
getObjectType
in interfaceAttribute<O,CompoundValueTuple<O>>
- Returns:
- the type of the object which contains the attribute
-
getAttributeType
public Class<CompoundValueTuple<O>> getAttributeType()
Description copied from interface:Attribute
Returns the type of the attribute.- Specified by:
getAttributeType
in interfaceAttribute<O,CompoundValueTuple<O>>
- Returns:
- the type of the attribute
-
getAttributeName
public String getAttributeName()
Description copied from interface:Attribute
Returns the name of the attribute, as supplied to the constructor.- Specified by:
getAttributeName
in interfaceAttribute<O,CompoundValueTuple<O>>
- Returns:
- the name of the attribute, as supplied to the constructor
-
getValues
public Iterable<CompoundValueTuple<O>> getValues(O object, QueryOptions queryOptions)
Returns a list ofCompoundValueTuple
objects for the given object, containing all possible combinations of attribute values against which the object can be indexed. See documentation on this class itself for details of the algorithm used to generate these tuples.- Specified by:
getValues
in interfaceAttribute<O,CompoundValueTuple<O>>
- Parameters:
object
- The object from which allCompoundValueTuple
s are requiredqueryOptions
-- Returns:
- tuples representing all possible combinations of attribute values against which the object can be indexed
-
-