public class Predicate
extends java.lang.Object
implements java.lang.Cloneable
Predicate
is a single constraint for a Query
. It is a
pure data model object, consisting of a parameter map based on key-value
string pairs.
Each Predicate
has a type (getType()
) that is used to find
the right PredicateEvaluator
that will handle this predicate and eg.
translate it into an XPath statement.
Using the composite pattern, the subclass PredicateGroup
allows to
group multiple predicates into one. This allows the query to actually consist
of a predicate tree and reflects more complex queries that include sub-terms.
The methods getName()
, getPath()
and #getParent()
return that hierarchy information. The name/path is important, because facets
will be returned in a map with the appropriate predicate path as key (see
SearchResult.getFacets()
).
The parameters are set via the set(String, String)
method and
retrieved via get(String)
, get(String, String)
or
getParameters()
. Predicates are also Cloneable
, so that it
is easy to copy them.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
IGNORE_CASE |
static java.lang.String |
ORDER_BY |
static java.lang.String |
PARAM_CASE
Parameter on
orderby to control whether sorting is case insensitive or not. |
static java.lang.String |
PARAM_EXCERPT |
static java.lang.String |
PARAM_FACET_STRATEGY |
static java.lang.String |
PARAM_GUESS_TOTAL
If true, this allows the implementation to optimize the query and return
just a guessed
count . |
static java.lang.String |
PARAM_LIMIT |
static java.lang.String |
PARAM_OFFSET |
static java.lang.String |
PARAM_OPTIONS_INDEXTAG
Translated into Query Option 'index tag'
|
static java.lang.String |
PARAM_OPTIONS_TRAVERSAL
How to handle traversals - translated into Query Option 'traversal'.
|
static java.lang.String |
PARAM_SORT
Parameter on
orderby to control whether the sort order is ascending
(default) or descending. |
static java.lang.String |
SORT_ASCENDING |
static java.lang.String |
SORT_DESCENDING |
static java.lang.String |
TRAVERSAL_FAIL |
static java.lang.String |
TRAVERSAL_OK |
static java.lang.String |
TRAVERSAL_WARN |
Constructor and Description |
---|
Predicate(java.lang.String type)
Creates a
Predicate of the given type. |
Predicate(java.lang.String name,
java.lang.String type)
Creates a
Predicate with the given name and type. |
Modifier and Type | Method and Description |
---|---|
Predicate |
clone()
Clones this predicate so that the returned clone can be used completely
independently from this original.
|
Predicate |
clone(boolean resetName)
Clones this predicate so that the returned clone can be used completely
independently from this original.
|
boolean |
equals(java.lang.Object obj) |
java.lang.String |
get(java.lang.String parameterName)
Returns the value for the given parameter name or
null if
that parameter is not set. |
java.lang.String |
get(java.lang.String parameterName,
java.lang.String defaultValue)
Returns the value for the given parameter name or the given default value
if that parameter is not set.
|
boolean |
getBool(java.lang.String parameterName)
Returns the boolean value for the given parameter name or
false if that parameter is not set, ie. |
java.lang.String |
getName()
Returns the name of this predicate.
|
java.util.Map<java.lang.String,java.lang.String> |
getParameters()
Returns an unmodifiable map of all parameters and their values.
|
java.lang.String |
getPath()
Returns the path in a predicate tree of
PredicateGroups to this predicate, eg. |
java.lang.String |
getType()
Returns the predicate type name for finding the right
PredicateEvaluator . |
int |
hashCode() |
boolean |
hasNonEmptyValue(java.lang.String parameterName)
Returns
true when there is a parameter present with the
given name and if the string value is not empty. |
boolean |
ignored()
This is used only during evaluation and indicates that this predicate is
marked as "invisible" for any
PredicateEvaluator that will
encounter it. |
Predicate |
set(java.lang.String parameterName,
java.lang.String value)
Sets the parameter 'parameterName' to the value given by 'value'.
|
void |
setIgnored(boolean ignore)
This is used only during evaluation and marks this predicate as
"invisible" for any
PredicateEvaluator that will encounter it. |
java.lang.String |
toString()
Overwrites the standard
Object.toString() implementation and
returns a debug-friendly string representation of the predicate. |
public static final java.lang.String PARAM_OFFSET
public static final java.lang.String PARAM_LIMIT
public static final java.lang.String PARAM_EXCERPT
public static final java.lang.String PARAM_FACET_STRATEGY
public static final java.lang.String PARAM_OPTIONS_TRAVERSAL
p.traversal=ok
public static final java.lang.String TRAVERSAL_OK
public static final java.lang.String TRAVERSAL_FAIL
public static final java.lang.String TRAVERSAL_WARN
public static final java.lang.String PARAM_OPTIONS_INDEXTAG
p.indexTag=tagName
public static final java.lang.String PARAM_GUESS_TOTAL
count
. Defaults to
false, in which case the total is always accurate.public static final java.lang.String ORDER_BY
public static final java.lang.String PARAM_SORT
orderby
to control whether the sort order is ascending
(default) or descending. Possible values are asc
and desc
.
orderby.sort=desc
public static final java.lang.String SORT_ASCENDING
public static final java.lang.String SORT_DESCENDING
public static final java.lang.String PARAM_CASE
orderby
to control whether sorting is case insensitive or not.
Only the value ignore
is supported, in which case "a" comes before "B".
If empty or left out, sorting is case sensitive, e.g. "B" comes before "a".
orderby.case=ignore
public static final java.lang.String IGNORE_CASE
public Predicate(java.lang.String type)
Predicate
of the given type. Note that the type
cannot be changed later. The name will be deducted automatically,
see getName()
. Initially no parameters will be set and
no parent will be present.type
- predicate type name for finding the right
PredicateEvaluator
public Predicate(java.lang.String name, java.lang.String type)
Predicate
with the given name and type. Note that name
and type cannot be changed later. Initially no parameters will be set and
no parent will be present.
The name should not be null
- this case is reserved for a
root PredicateGroup
(using
PredicateGroup.PredicateGroup()
).
name
- identifying name for this predicatetype
- predicate type name for finding the right
PredicateEvaluator
public java.lang.String getType()
PredicateEvaluator
.public java.lang.String getName()
facet map
, in logging or other debug
output.
When a predicate is included in PredicateGroup
, the names of the
parent predicates will make up the path
, eg.
parent.child.grandchild
. The name must not be changed after
the predicate is passed to a Query
.
If no name was set previously, it will be automatically created. If this
predicate is part of a group, it will get a name of the form "N_type"
where N is the 1-based index of its position in the parent group and
"type" is it's type
. If it does not have a parent group,
the name will only consist of the type.
null
if
no name was set)public java.lang.String getPath()
PredicateGroups
to this predicate, eg.
parent.child.grandchild
. This can be null
if no
name was set. The path is used for identifying predicates in the
facet map
, in logging or other debug
output.public java.lang.String get(java.lang.String parameterName)
null
if
that parameter is not set. Parameters always have String
values.public java.lang.String get(java.lang.String parameterName, java.lang.String defaultValue)
String
values.public boolean getBool(java.lang.String parameterName)
false
if that parameter is not set, ie. it assumes
false
as the default of the boolean parameter.
Since actual parameter values are strings, it is considered
true
if the string value is either "true" or "on" (used by
HTTP forms for checkboxes).
public Predicate set(java.lang.String parameterName, java.lang.String value)
String
values.group.add(new Predicate("mytype", "type").set("type", "nt:file"));
public boolean hasNonEmptyValue(java.lang.String parameterName)
true
when there is a parameter present with the
given name and if the string value is not empty. Parameters always have
String
values.public java.util.Map<java.lang.String,java.lang.String> getParameters()
public void setIgnored(boolean ignore)
PredicateEvaluator
that will encounter it.
Don't use that method when creating a query.ignore
- true
if this predicate should be ignored by
evaluators (default is false
)public boolean ignored()
PredicateEvaluator
that will
encounter it. This method has no use for clients of the querybuilder API.true
if this predicate should be ignored by
evaluators (default is false
)public Predicate clone()
clone(false)
.clone
in class java.lang.Object
public Predicate clone(boolean resetName)
resetName
- whether to reset the name to null
so that they
will be automatically deducted (see getName()
)public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
Object.toString()
implementation and
returns a debug-friendly string representation of the predicate.toString
in class java.lang.Object
Copyright © 2010 - 2020 Adobe. All Rights Reserved