Class CompoundAttribute<O>

  • All Implemented Interfaces:
    Attribute<O,​CompoundValueTuple<O>>

    public class CompoundAttribute<O>
    extends Object
    implements Attribute<O,​CompoundValueTuple<O>>
    A private implementation of Attribute used internally by CompoundIndex, which groups several other attributes.

    Note that, being like regular Attributes, 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 in CompoundValueTuple objects. The Attribute.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 a CompoundAttribute referencing a given object, depends on whether the CompoundAttribute groups only SimpleAttributes, or whether it groups any MultiValueAttributes.

    • Generating tuples for a group of SimpleAttributes
      If a compound attribute groups only SimpleAttributes, then the list of tuples generated by the CompoundAttribute is straightforward and will contain just one tuple, comprising the values from each of the fields referenced by the SimpleAttributes
    • Generating tuples for MultiValueAttributes
      If a compound attribute groups one or more MultiValueAttributes, then the determination of tuples is more complicated, and is as follows.

      MultiValueAttributes can return multiple values from a single field in an object. The purpose of MultiValueAttribute is to allow an object to be indexed separately against each of the values from this field. Given that a CompoundAttribute spans multiple attributes, the presence of one or more MultiValueAttributes means that several possible combinations of values should match the object in the index.

      To generate tuples for CompoundAttributes spanning MultiValueAttributes, the Attribute.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, using TupleCombinationGenerator.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]]
      The Attribute.getValues(Object, com.googlecode.cqengine.query.option.QueryOptions) method would then return these tuples as a list of CompoundValueTuple objects

    Author:
    Niall Gallagher