Class PredicateGroup
- All Implemented Interfaces:
Cloneable,Iterable<Predicate>,Collection<Predicate>,List<Predicate>,SequencedCollection<Predicate>
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
-
Field Summary
FieldsFields 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
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends Predicate> c) booleanaddAll(Collection<? extends Predicate> c) booleanReturns whether all predicates are combined with "AND", ie.voidclear()clone()Clones this predicate group so that the returned clone can be used completely independently from this original.clone(boolean resetName) Clones this predicate group so that the returned clone can be used completely independently from this original.booleanbooleancontainsAll(Collection<?> c) static PredicateGroupConverts a map with predicates and their parameters into a predicate tree.booleanget(int index) Returns a certain predicate by itsname.Returns a certain predicate by itspath, relative to this predicate.inthashCode()intbooleanisEmpty()booleanReturns whether the result of this predicate group should be negated.iterator()intlistIterator(int index) remove(int index) booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) 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()subList(int fromIndex, int toIndex) Object[]toArray()<T> T[]toArray(T[] a) toString()Overwrites the standardObject.toString()implementation and returns a debug-friendly string including all sub predicates (via theirtoString()method).toURL()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, setIgnoredMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, replaceAll, reversed, sort, spliterator
-
Field Details
-
TYPE
- See Also:
-
-
Constructor Details
-
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
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 Details
-
create
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
Returns an URL query part containing the given group. This is the same mapping as used inandinvalid reference
#createMap(PredicateGroup). For example, the returned value could be:invalid reference
#createPredicates(Map)type=cq:Pageinvalid input: '&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
Returns a certain predicate by itsname. -
getByPath
Returns a certain predicate by itspath, relative to this predicate. -
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
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
-
hashCode
public int hashCode() -
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
-
add
-
addAll
-
addAll
-
clear
public void clear() -
contains
-
containsAll
- Specified by:
containsAllin interfaceCollection<Predicate>- Specified by:
containsAllin interfaceList<Predicate>
-
get
-
indexOf
-
isEmpty
public boolean isEmpty() -
iterator
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<Predicate>
-
listIterator
- Specified by:
listIteratorin interfaceList<Predicate>
-
listIterator
- Specified by:
listIteratorin interfaceList<Predicate>
-
remove
-
remove
-
removeAll
-
retainAll
-
set
-
size
public int size() -
subList
-
toArray
-
toArray
public <T> T[] toArray(T[] a)
-