Class PredicateGroup

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Iterable<Predicate>, java.util.Collection<Predicate>, java.util.List<Predicate>

    public class PredicateGroup
    extends Predicate
    implements java.util.List<Predicate>
    A PredicateGroup is a Predicate that represents a list of Predicates (following the composite pattern). This allows to build predicate trees for reflecting complex queries that include sub-terms.

    The predicates in a group are by default all required to match, ie. they will be combined with "AND" in a lower-level query language, which is indicated by allRequired() returning true. If setAllRequired(boolean) is called with false, or if the parameter or is set to true, the child predicates will be combined with "OR", ie. only one must match for the whole group to match.

    If the parameter not is set to true, the result of this group will be negated. See also isNegated() and setNegated(boolean).

    This class extends both the Predicate class and implements the List interface, backed by a standard ArrayList internally.

    The standard type name for predicate groups is given by TYPE ( "group"), which is also used when using the default constructor.

    Since:
    5.2
    • Constructor Detail

      • PredicateGroup

        public PredicateGroup()
        Creates this predicate group with the group type "group", and a predicate name of null. Use this constructor when the name should be deducted automatically (see Predicate.getName()) or for the root group of a predicate tree, because the name must be null for that case.
      • PredicateGroup

        public PredicateGroup​(java.lang.String name)
        Creates this predicate group with the given name and the group type "group", using the Predicate(String, String) constructor. If you create a root group of a predicate tree, the name must be null (you can use the default constructor PredicateGroup() for that).
    • Method Detail

      • create

        public static PredicateGroup create​(java.util.Map predicateParameterMap)
        Converts a map with predicates and their parameters into a predicate tree. Accepts a map with strings as keys and either simple strings as values or string arrays as values. In the array case, the first value will be chosen.

        Same as PredicateConverter.createPredicates(Map).

      • toURL

        public java.lang.String toURL()
        Returns an URL query part containing the given group. This is the same mapping as used in #createMap(PredicateGroup) and #createPredicates(Map). For example, the returned value could be: type=cq:Page&path=/content. Note that this won't be a complete URL, just a list of parameters for an URL query part. The keys and values will be properly escaped for use in an URL.

        Same as PredicateConverter.toURL(PredicateGroup).

      • allRequired

        public boolean allRequired()
        Returns whether all predicates are combined with "AND", ie. only nodes are found that match all predicates in this group. The default value is true (AND):
        Returns:
        true for "AND" (default), false for "OR"
      • setAllRequired

        public void setAllRequired​(boolean all)
        Sets whether all predicates are combined with "AND", ie. only nodes are found that match all predicates in this group, or if they are combined with "OR".
        Parameters:
        all - true for "AND", false for "OR"
      • isNegated

        public boolean isNegated()
        Returns whether the result of this predicate group should be negated. Ie. only nodes that do not match this group should be included in the results. The default value is false.
        Returns:
        true for exclusive, false for inclusive (default)
        Since:
        5.5
      • setNegated

        public void setNegated​(boolean not)
        Sets whether the result of this group should be negated.
        Parameters:
        not - true if the group should be negated, false if not (default)
        Since:
        5.5
      • getByName

        public Predicate getByName​(java.lang.String name)
        Returns a certain predicate by its name.
      • getByPath

        public Predicate getByPath​(java.lang.String path)
        Returns a certain predicate by its path, relative to this predicate.
      • clone

        public PredicateGroup clone()
        Clones this predicate group so that the returned clone can be used completely independently from this original. All child predicates will hence also be cloned.
        Overrides:
        clone in class Predicate
      • clone

        public PredicateGroup clone​(boolean resetName)
        Clones this predicate group so that the returned clone can be used completely independently from this original. All child predicates will hence also be cloned. A new name for the clone can be passed.
        Overrides:
        clone in class Predicate
        Parameters:
        resetName - whether to reset the name and child predicate names to null so that they will be automatically deducted (see Predicate.getName())
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Collection<Predicate>
        Specified by:
        equals in interface java.util.List<Predicate>
        Overrides:
        equals in class Predicate
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<Predicate>
        Specified by:
        hashCode in interface java.util.List<Predicate>
        Overrides:
        hashCode in class Predicate
      • toString

        public java.lang.String toString()
        Overwrites the standard Object.toString() implementation and returns a debug-friendly string including all sub predicates (via their toString() method). The final string is multi-lined and indented for easy readability of the inherent tree structure.
        Overrides:
        toString in class Predicate
      • add

        public boolean add​(Predicate o)
        Specified by:
        add in interface java.util.Collection<Predicate>
        Specified by:
        add in interface java.util.List<Predicate>
      • add

        public void add​(int index,
                        Predicate element)
        Specified by:
        add in interface java.util.List<Predicate>
      • addAll

        public boolean addAll​(java.util.Collection<? extends Predicate> c)
        Specified by:
        addAll in interface java.util.Collection<Predicate>
        Specified by:
        addAll in interface java.util.List<Predicate>
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends Predicate> c)
        Specified by:
        addAll in interface java.util.List<Predicate>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<Predicate>
        Specified by:
        clear in interface java.util.List<Predicate>
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<Predicate>
        Specified by:
        contains in interface java.util.List<Predicate>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<Predicate>
        Specified by:
        containsAll in interface java.util.List<Predicate>
      • get

        public Predicate get​(int index)
        Specified by:
        get in interface java.util.List<Predicate>
      • indexOf

        public int indexOf​(java.lang.Object o)
        Specified by:
        indexOf in interface java.util.List<Predicate>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<Predicate>
        Specified by:
        isEmpty in interface java.util.List<Predicate>
      • iterator

        public java.util.Iterator<Predicate> iterator()
        Specified by:
        iterator in interface java.util.Collection<Predicate>
        Specified by:
        iterator in interface java.lang.Iterable<Predicate>
        Specified by:
        iterator in interface java.util.List<Predicate>
      • lastIndexOf

        public int lastIndexOf​(java.lang.Object o)
        Specified by:
        lastIndexOf in interface java.util.List<Predicate>
      • listIterator

        public java.util.ListIterator<Predicate> listIterator()
        Specified by:
        listIterator in interface java.util.List<Predicate>
      • listIterator

        public java.util.ListIterator<Predicate> listIterator​(int index)
        Specified by:
        listIterator in interface java.util.List<Predicate>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<Predicate>
        Specified by:
        remove in interface java.util.List<Predicate>
      • remove

        public Predicate remove​(int index)
        Specified by:
        remove in interface java.util.List<Predicate>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<Predicate>
        Specified by:
        removeAll in interface java.util.List<Predicate>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<Predicate>
        Specified by:
        retainAll in interface java.util.List<Predicate>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<Predicate>
        Specified by:
        size in interface java.util.List<Predicate>
      • subList

        public java.util.List<Predicate> subList​(int fromIndex,
                                                 int toIndex)
        Specified by:
        subList in interface java.util.List<Predicate>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<Predicate>
        Specified by:
        toArray in interface java.util.List<Predicate>
      • toArray

        public <T> T[] toArray​(T[] a)
        Specified by:
        toArray in interface java.util.Collection<Predicate>
        Specified by:
        toArray in interface java.util.List<Predicate>