Class PredicateGroup
- java.lang.Object
-
- com.day.cq.search.Predicate
-
- com.day.cq.search.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>
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 java.lang.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(java.lang.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, java.util.Collection<? extends Predicate> c)booleanaddAll(java.util.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(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)static PredicateGroupcreate(java.util.Map predicateParameterMap)Converts a map with predicates and their parameters into a predicate tree.booleanequals(java.lang.Object obj)Predicateget(int index)PredicategetByName(java.lang.String name)Returns a certain predicate by itsname.PredicategetByPath(java.lang.String path)Returns a certain predicate by itspath, relative to this predicate.inthashCode()intindexOf(java.lang.Object o)booleanisEmpty()booleanisNegated()Returns whether the result of this predicate group should be negated.java.util.Iterator<Predicate>iterator()intlastIndexOf(java.lang.Object o)java.util.ListIterator<Predicate>listIterator()java.util.ListIterator<Predicate>listIterator(int index)Predicateremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.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()java.util.List<Predicate>subList(int fromIndex, int toIndex)java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()Overwrites the standardObject.toString()implementation and returns a debug-friendly string including all sub predicates (via theirtoString()method).java.lang.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
-
-
-
-
Field Detail
-
TYPE
public static final java.lang.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(java.lang.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(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.
-
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.
-
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
-
getByName
public Predicate getByName(java.lang.String name)
Returns a certain predicate by itsname.
-
getByPath
public Predicate getByPath(java.lang.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(java.lang.Object obj)
-
hashCode
public int hashCode()
-
toString
public java.lang.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)
-
add
public void add(int index, Predicate element)- Specified by:
addin interfacejava.util.List<Predicate>
-
addAll
public boolean addAll(java.util.Collection<? extends Predicate> c)
-
addAll
public boolean addAll(int index, java.util.Collection<? extends Predicate> c)- Specified by:
addAllin interfacejava.util.List<Predicate>
-
clear
public void clear()
-
contains
public boolean contains(java.lang.Object o)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOfin interfacejava.util.List<Predicate>
-
isEmpty
public boolean isEmpty()
-
iterator
public java.util.Iterator<Predicate> iterator()
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOfin interfacejava.util.List<Predicate>
-
listIterator
public java.util.ListIterator<Predicate> listIterator()
- Specified by:
listIteratorin interfacejava.util.List<Predicate>
-
listIterator
public java.util.ListIterator<Predicate> listIterator(int index)
- Specified by:
listIteratorin interfacejava.util.List<Predicate>
-
remove
public boolean remove(java.lang.Object o)
-
remove
public Predicate remove(int index)
- Specified by:
removein interfacejava.util.List<Predicate>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
set
public Predicate set(int index, Predicate element)
- Specified by:
setin interfacejava.util.List<Predicate>
-
size
public int size()
-
subList
public java.util.List<Predicate> subList(int fromIndex, int toIndex)
- Specified by:
subListin interfacejava.util.List<Predicate>
-
toArray
public java.lang.Object[] toArray()
-
-