Class RelTraitSet

    • Method Detail

      • createEmpty

        public static RelTraitSet createEmpty()
        Creates an empty trait set.

        It has a new cache, which will be shared by any trait set created from it. Thus each empty trait set is the start of a new ancestral line.

      • getTrait

        public RelTrait getTrait​(int index)
        Retrieves a RelTrait from the set.
        Parameters:
        index - 0-based index into ordered RelTraitSet
        Returns:
        the RelTrait
        Throws:
        ArrayIndexOutOfBoundsException - if index greater than or equal to size() or less than 0.
      • getTraits

        public <E extends RelMultipleTraitList<E> getTraits​(int index)
        Retrieves a list of traits from the set.
        Parameters:
        index - 0-based index into ordered RelTraitSet
        Returns:
        the RelTrait
        Throws:
        ArrayIndexOutOfBoundsException - if index greater than or equal to size() or less than 0.
      • isEnabled

        public <T extends RelTrait> boolean isEnabled​(RelTraitDef<T> traitDef)
        Returns whether a given kind of trait is enabled.
      • getTrait

        public <T extends RelTrait> T getTrait​(RelTraitDef<T> traitDef)
        Retrieves a RelTrait of the given type from the set.
        Parameters:
        traitDef - the type of RelTrait to retrieve
        Returns:
        the RelTrait, or null if not found
      • getTraits

        public <T extends RelMultipleTraitList<T> getTraits​(RelTraitDef<T> traitDef)
        Retrieves a list of traits of the given type from the set.

        Only valid for traits that support multiple entries. (E.g. collation.)

        Parameters:
        traitDef - the type of RelTrait to retrieve
        Returns:
        the RelTrait, or null if not found
      • replace

        public RelTraitSet replace​(int index,
                                   RelTrait trait)
        Replaces an existing RelTrait in the set. Returns a different trait set; does not modify this trait set.
        Parameters:
        index - 0-based index into ordered RelTraitSet
        trait - the new RelTrait
        Returns:
        the old RelTrait at the index
      • replace

        public RelTraitSet replace​(RelTrait trait)
        Returns a trait set consisting of the current set plus a new trait.

        If the set does not contain a trait of the same RelTraitDef, the trait is ignored, and this trait set is returned.

        Parameters:
        trait - the new trait
        Returns:
        New set
        See Also:
        plus(RelTrait)
      • replace

        public <T extends RelMultipleTraitRelTraitSet replace​(List<T> traits)
        Replaces the trait(s) of a given type with a list of traits of the same type.

        The list must not be empty, and all traits must be of the same type.

      • replace

        public <T extends RelMultipleTraitRelTraitSet replace​(RelTraitDef<T> def,
                                                                List<T> traits)
        Replaces the trait(s) of a given type with a list of traits of the same type.

        The list must not be empty, and all traits must be of the same type.

      • apply

        public RelTraitSet apply​(Mappings.TargetMapping mapping)
        Applies a mapping to this traitSet.
        Parameters:
        mapping - Mapping
        Returns:
        traitSet with mapping applied
      • isDefault

        public boolean isDefault()
        Returns whether all the traits are default trait value.
      • isDefaultSansConvention

        public boolean isDefaultSansConvention()
        Returns whether all the traits except Convention are default trait value.
      • equalsSansConvention

        public boolean equalsSansConvention​(RelTraitSet other)
        Returns whether all the traits except Convention equals with traits in other traitSet.
      • getDefault

        public RelTraitSet getDefault()
        Returns a new traitSet with same traitDefs with current traitSet, but each trait is the default trait value.
      • getDefaultSansConvention

        public RelTraitSet getDefaultSansConvention()
        Returns a new traitSet with same traitDefs with current traitSet, but each trait except Convention is the default trait value. Convention trait remains the same with current traitSet.
      • canonize

        public <T extends RelTrait> T canonize​(T trait)
        Converts a trait to canonical form.

        After canonization, t1.equals(t2) if and only if t1 == t2.

        Parameters:
        trait - Trait
        Returns:
        Trait in canonical form
      • satisfies

        public boolean satisfies​(RelTraitSet that)
        Returns whether this trait set satisfies another trait set.

        For that to happen, each trait satisfies the corresponding trait in the other set. In particular, each trait set satisfies itself, because each trait subsumes itself.

        Intuitively, if a relational expression is needed that has trait set S (A, B), and trait set S1 (A1, B1) subsumes S, then any relational expression R in S1 meets that need.

        For example, if we need a relational expression that has trait set S = {enumerable convention, sorted on [C1 asc]}, and R has {enumerable convention, sorted on [C3], [C1, C2]}. R has two sort keys, but one them [C1, C2] satisfies S [C1], and that is enough.

        Parameters:
        that - another RelTraitSet
        Returns:
        whether this trait set satisfies other trait set
        See Also:
        RelTrait.satisfies(RelTrait)
      • matches

        public boolean matches​(RelTraitSet that)
        Compares two RelTraitSet objects to see if they match for the purposes of firing a rule. A null RelTrait within a RelTraitSet indicates a wildcard: any RelTrait in the other RelTraitSet will match. If one RelTraitSet is smaller than the other, comparison stops when the last RelTrait from the smaller set has been examined and the remaining RelTraits in the larger set are assumed to match.
        Parameters:
        that - another RelTraitSet
        Returns:
        true if the RelTraitSets match, false otherwise
      • contains

        public boolean contains​(RelTrait trait)
        Returns whether this trait set contains a given trait.
        Parameters:
        trait - Sought trait
        Returns:
        Whether set contains given trait
      • containsIfApplicable

        public boolean containsIfApplicable​(RelTrait trait)
        Returns whether this trait set contains the given trait, or whether the trait is not present because its RelTraitDef is not enabled. Returns false if another trait of the same RelTraitDef is present.
        Parameters:
        trait - Trait
        Returns:
        Whether trait is present, or is absent because disabled
      • comprises

        public boolean comprises​(RelTrait... relTraits)
        Returns whether this trait set comprises precisely the list of given traits.
        Parameters:
        relTraits - Traits
        Returns:
        Whether this trait set's traits are the same as the argument
      • computeString

        protected String computeString()
        Outputs the traits of this set as a String. Traits are output in order, separated by periods.
      • plus

        public RelTraitSet plus​(RelTrait trait)
        Returns this trait set with a given trait added or overridden. Does not modify this trait set.
        Parameters:
        trait - Trait
        Returns:
        Trait set with given trait
      • difference

        public com.google.common.collect.ImmutableList<RelTrait> difference​(RelTraitSet traitSet)
        Returns a list of traits that are in traitSet but not in this RelTraitSet.
      • allSimple

        public boolean allSimple()
        Returns whether there are any composite traits in this set.
      • simplify

        public RelTraitSet simplify()
        Returns a trait set similar to this one but with all composite traits flattened.