Class SearchOperator
$-search operator — its $-name, arity, the value types
it applies to, and its popup help text.
A custom operator always carries its own help text; the help text of a built-in (SearchOperatorSet.standard())
operator is owned by the browser runtime, so help() is SearchPredicate the in-memory context calls when it hits
that $-name — Juneau never invents one. Anything else a downstream module (for example a SQL
renderer) needs to attach lives in the typed extension slot: it is keyed by the
extension's own Class, so this module (commons) never needs to depend on that module's types (design
§5.3).
Instances are built with SearchOperator.Builder: create(String, String) starts a new custom operator, and
copy() starts a modified copy of an existing one (built-in or custom).
Combinators vs. leaves
$and/$or/$not are combinators: their children are sub-expressions,
not literal value arguments, and they apply to every type. Every other operator is a leaf whose arguments are
literal values and whose applicability is a fixed type set (an empty type set
means "applies to all types").
Example (custom operator, with a typed extension):
SearchOperator
- Since:
- 10.0.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbooleanacceptsArgCount(int count) Whether the specified argument count satisfies this operator's arity.booleanappliesTo(SearchType type) Whether this operator applies to the specified value type.copy()Starts aSearchOperator.Builderpre-filled with this operator's current state, for building a modified copy.static SearchOperator.BuilderStarts a new custom (application-defined) leaf operator.boolean<X> Optional<X>Looks up a typed extension previously attached withSearchOperator.Builder.extension(Class, Object).inthashCode()help()The human-readable help text for this operator, shown in the column-search popup.booleanWhether this is a combinator ($and/$or/$not) whose children are sub-expressions.booleanisCustom()Whether this is an application-defined custom operator (vs. a built-in).intmaxArgs()The maximum argument count (inclusive), or-1for unbounded.intminArgs()The minimum argument count (inclusive).name()The operator name, including the leading$(e.g.The in-memory evaluator for a custom operator, if one was supplied.toString()booleanWhether this operator's SQL renderer should be giventyped valuesrather thanliteral strings.types()The value types this operator applies to (combinators apply to all types regardless of this set).
-
Method Details
-
create
Starts a new custom (application-defined) leaf operator.Defaults: arity
1..*(one or more arguments), applies to all value types (an empty type set), no predicate, no extensions. Narrow it withSearchOperator.Builder.minArgs(int)/SearchOperator.Builder.maxArgs(int)/SearchOperator.Builder.types(SearchType...)and attach an evaluator withSearchOperator.Builder.predicate(SearchPredicate)(in-memory) and/or a typedSearchOperator.Builder.extension(Class, Object)(for example, a SQL renderer).- Parameters:
name- The operator name, including the leading$(e.g."$near"). Must not benull or blank and must start with$.helpText- The popup help text: what the operator accepts and a short example. Must not benull or blank.- Returns:
- A new
SearchOperator.Builderpre-filled withname/helpTextand the defaults above. - Throws:
IllegalArgumentException- Ifnameis not a valid$-name orhelpTextis blank.
-
copy
Starts aSearchOperator.Builderpre-filled with this operator's current state, for building a modified copy.The returned builder is fully independent of this instance: mutating it (or the
SearchOperatorit eventuallybuilds) never affects this instance.Renaming is only legal for a copy of a custom operator. Both evaluation engines dispatch a built-in purely by its
name()— the in-memory engine's leaf switch andSqlDialect#builtinRenderer(String)alike — sochanging the nameon a copy of a custom operator (one with its ownpredicate/extension) is fine and gives it a fresh identity, but doing the same to a copy of a built-in operator throwsIllegalArgumentExceptionfrombuild(). A built-in's copy may still have itshelp textchanged freely; only its name is fixed.- Returns:
- A new builder seeded from this operator.
-
name
The operator name, including the leading$(e.g."$eq").- Returns:
- The operator name.
-
help
The human-readable help text for this operator, shown in the column-search popup.Built-in operators return
null : their help text is owned byjuneau-search.js , which the popup falls back to. Custom operators always return non-blank text, becauseSearchOperator.Builder.build()rejects a custom operator without it.Example:
SearchOperator
near = SearchOperator.create ("$near" ,"Within N units. Example: $near(5)" ).build();near .help();// "Within N units. Example: $near(5)" SearchOperatorSet.standard ().get("$eq" ).help();// null - Returns:
- The help text, or
null for a built-in operator.
-
isCustom
Whether this is an application-defined custom operator (vs. a built-in).- Returns:
true if custom.
-
isCombinator
Whether this is a combinator ($and/$or/$not) whose children are sub-expressions.- Returns:
true if a combinator.
-
minArgs
The minimum argument count (inclusive).- Returns:
- The minimum arity.
-
maxArgs
The maximum argument count (inclusive), or-1for unbounded.- Returns:
- The maximum arity, or
-1.
-
predicate
The in-memory evaluator for a custom operator, if one was supplied.- Returns:
- The predicate, or
null for built-ins and for customs with no predicate.
-
types
The value types this operator applies to (combinators apply to all types regardless of this set).- Returns:
- An unmodifiable view of the applicable types; empty means "applies to all types".
-
appliesTo
Whether this operator applies to the specified value type.- Parameters:
type- The column value type. Can benull .- Returns:
true if this operator is offered for that type (combinators, and operators with an emptytype set, apply to every type).
-
acceptsArgCount
Whether the specified argument count satisfies this operator's arity.- Parameters:
count- The number of arguments supplied.- Returns:
true ifcountis within[minArgs, maxArgs](upper bound ignored when unbounded).
-
typedArgs
Whether this operator's SQL renderer should be giventyped valuesrather thanliteral strings. Never affects the in-memorypredicate, which always receives literal strings.- Returns:
true if typed (seeSearchOperator.Builder.typedArgs(boolean)).
-
extension
Looks up a typed extension previously attached withSearchOperator.Builder.extension(Class, Object).This is how a downstream module (for example
juneau-beanquery-sql's SQL renderer) attaches its own metadata to a custom operator without this module (commons) ever depending on that module's types: the extension is keyed by its ownClass, so retrieval is type-safe with no cast (design §5.3).- Type Parameters:
X- The extension type.- Parameters:
type- The extension's class, used as the lookup key. Must not benull .- Returns:
- The extension, or
Optional.empty()if none was attached under that type.
-
equals
-
hashCode
-
toString
-