Class PredicateGroup
- java.lang.Object
-
- com.day.cq.search.Predicate
-
- com.day.cq.search.PredicateGroup
-
public class PredicateGroup extends Predicate implements List<Predicate>
APredicateGroupis aPredicatethat represents a list ofPredicates(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. IfsetAllRequired(boolean)is called withfalse, or if the parameteroris set totrue, the child predicates will be combined with "OR", ie. only one must match for the whole group to match.If the parameter
notis set totrue, the result of this group will be negated. See alsoisNegated()andsetNegated(boolean).This class extends both the
Predicateclass and implements theListinterface, backed by a standardArrayListinternally.The standard type name for predicate groups is given by
TYPE( "group"), which is also used when using the default constructor.- Since:
- 5.2
-
-
Field Summary
Fields Modifier and Type Field Description static StringTYPE-
Fields inherited from class com.day.cq.search.Predicate
IGNORE_CASE, ORDER_BY, PARAM_CASE, PARAM_EXCERPT, PARAM_FACET_STRATEGY, PARAM_GUESS_TOTAL, PARAM_LIMIT, PARAM_OFFSET, PARAM_OPTIONS_INDEXTAG, PARAM_OPTIONS_TRAVERSAL, PARAM_SORT, SORT_ASCENDING, SORT_DESCENDING, TRAVERSAL_FAIL, TRAVERSAL_OK, TRAVERSAL_WARN
-
-
Constructor Summary
Constructors Constructor Description PredicateGroup()Creates this predicate group with the group type"group", and a predicate name ofnull.PredicateGroup(String name)Creates this predicate group with the given name and the group type"group", using thePredicate(String, String)constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, Predicate element)booleanadd(Predicate o)booleanaddAll(int index, Collection<? extends Predicate> c)booleanaddAll(Collection<? extends Predicate> c)booleanallRequired()Returns whether all predicates are combined with "AND", ie.voidclear()PredicateGroupclone()Clones this predicate group so that the returned clone can be used completely independently from this original.PredicateGroupclone(boolean resetName)Clones this predicate group so that the returned clone can be used completely independently from this original.booleancontains(Object o)booleancontainsAll(Collection<?> c)static PredicateGroupcreate(Map predicateParameterMap)Converts a map with predicates and their parameters into a predicate tree.booleanequals(Object obj)Predicateget(int index)PredicategetByName(String name)Returns a certain predicate by itsname.PredicategetByPath(String path)Returns a certain predicate by itspath, relative to this predicate.inthashCode()intindexOf(Object o)booleanisEmpty()booleanisNegated()Returns whether the result of this predicate group should be negated.Iterator<Predicate>iterator()intlastIndexOf(Object o)ListIterator<Predicate>listIterator()ListIterator<Predicate>listIterator(int index)Predicateremove(int index)booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)Predicateset(int index, Predicate element)voidsetAllRequired(boolean all)Sets whether all predicates are combined with "AND", ie.voidsetNegated(boolean not)Sets whether the result of this group should be negated.intsize()List<Predicate>subList(int fromIndex, int toIndex)Object[]toArray()<T> T[]toArray(T[] a)StringtoString()Overwrites the standardObject.toString()implementation and returns a debug-friendly string including all sub predicates (via theirtoString()method).StringtoURL()Returns an URL query part containing the given group.-
Methods inherited from class com.day.cq.search.Predicate
get, get, getBool, getName, getParameters, getPath, getType, hasNonEmptyValue, ignored, set, setIgnored
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
-
-
-
Field Detail
-
TYPE
public static final String TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PredicateGroup
public PredicateGroup()
Creates this predicate group with the group type"group", and a predicate name ofnull. Use this constructor when the name should be deducted automatically (seePredicate.getName()) or for the root group of a predicate tree, because the name must benullfor that case.
-
PredicateGroup
public PredicateGroup(String name)
Creates this predicate group with the given name and the group type"group", using thePredicate(String, String)constructor. If you create a root group of a predicate tree, the name must benull(you can use the default constructorPredicateGroup()for that).
-
-
Method Detail
-
create
public static PredicateGroup create(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.
-
toURL
public 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.
-
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 istrue(AND):- Returns:
truefor "AND" (default),falsefor "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-truefor "AND",falsefor "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 isfalse.- Returns:
truefor exclusive,falsefor inclusive (default)- Since:
- 5.5
-
setNegated
public void setNegated(boolean not)
Sets whether the result of this group should be negated.- Parameters:
not-trueif the group should be negated,falseif not (default)- Since:
- 5.5
-
getByPath
public Predicate getByPath(String path)
Returns a certain predicate by itspath, 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.
-
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:
clonein classPredicate- Parameters:
resetName- whether to reset the name and child predicate names tonullso that they will be automatically deducted (seePredicate.getName())
-
equals
public boolean equals(Object obj)
-
hashCode
public int hashCode()
-
toString
public String toString()
Overwrites the standardObject.toString()implementation and returns a debug-friendly string including all sub predicates (via theirtoString()method). The final string is multi-lined and indented for easy readability of the inherent tree structure.
-
add
public boolean add(Predicate o)
-
addAll
public boolean addAll(Collection<? extends Predicate> c)
-
addAll
public boolean addAll(int index, Collection<? extends Predicate> c)
-
clear
public void clear()
-
contains
public boolean contains(Object o)
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<Predicate>- Specified by:
containsAllin interfaceList<Predicate>
-
isEmpty
public boolean isEmpty()
-
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOfin interfaceList<Predicate>
-
listIterator
public ListIterator<Predicate> listIterator()
- Specified by:
listIteratorin interfaceList<Predicate>
-
listIterator
public ListIterator<Predicate> listIterator(int index)
- Specified by:
listIteratorin interfaceList<Predicate>
-
remove
public boolean remove(Object o)
-
removeAll
public boolean removeAll(Collection<?> c)
-
retainAll
public boolean retainAll(Collection<?> c)
-
size
public int size()
-
toArray
public Object[] toArray()
-
-