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>
APredicateGroup
is aPredicate
that 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 parameteror
is set totrue
, 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 totrue
, the result of this group will be negated. See alsoisNegated()
andsetNegated(boolean)
.This class extends both the
Predicate
class and implements theList
interface, backed by a standardArrayList
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
Fields Modifier and Type Field Description static java.lang.String
TYPE
-
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 void
add(int index, Predicate element)
boolean
add(Predicate o)
boolean
addAll(int index, java.util.Collection<? extends Predicate> c)
boolean
addAll(java.util.Collection<? extends Predicate> c)
boolean
allRequired()
Returns whether all predicates are combined with "AND", ie.void
clear()
PredicateGroup
clone()
Clones this predicate group so that the returned clone can be used completely independently from this original.PredicateGroup
clone(boolean resetName)
Clones this predicate group so that the returned clone can be used completely independently from this original.boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
static PredicateGroup
create(java.util.Map predicateParameterMap)
Converts a map with predicates and their parameters into a predicate tree.boolean
equals(java.lang.Object obj)
Predicate
get(int index)
Predicate
getByName(java.lang.String name)
Returns a certain predicate by itsname
.Predicate
getByPath(java.lang.String path)
Returns a certain predicate by itspath
, relative to this predicate.int
hashCode()
int
indexOf(java.lang.Object o)
boolean
isEmpty()
boolean
isNegated()
Returns whether the result of this predicate group should be negated.java.util.Iterator<Predicate>
iterator()
int
lastIndexOf(java.lang.Object o)
java.util.ListIterator<Predicate>
listIterator()
java.util.ListIterator<Predicate>
listIterator(int index)
Predicate
remove(int index)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
retainAll(java.util.Collection<?> c)
Predicate
set(int index, Predicate element)
void
setAllRequired(boolean all)
Sets whether all predicates are combined with "AND", ie.void
setNegated(boolean not)
Sets whether the result of this group should be negated.int
size()
java.util.List<Predicate>
subList(int fromIndex, int toIndex)
java.lang.Object[]
toArray()
<T> T[]
toArray(T[] a)
java.lang.String
toString()
Overwrites the standardObject.toString()
implementation and returns a debug-friendly string including all sub predicates (via theirtoString()
method).java.lang.String
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, 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 benull
for 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:
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 isfalse
.- 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 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:
clone
in classPredicate
- Parameters:
resetName
- whether to reset the name and child predicate names tonull
so 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:
add
in 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:
addAll
in 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:
indexOf
in 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:
lastIndexOf
in interfacejava.util.List<Predicate>
-
listIterator
public java.util.ListIterator<Predicate> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<Predicate>
-
listIterator
public java.util.ListIterator<Predicate> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<Predicate>
-
remove
public boolean remove(java.lang.Object o)
-
remove
public Predicate remove(int index)
- Specified by:
remove
in 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:
set
in interfacejava.util.List<Predicate>
-
size
public int size()
-
subList
public java.util.List<Predicate> subList(int fromIndex, int toIndex)
- Specified by:
subList
in interfacejava.util.List<Predicate>
-
toArray
public java.lang.Object[] toArray()
-
-