Class BaseMatcher<Match extends IPatternMatch>
java.lang.Object
tools.refinery.interpreter.internal.apiimpl.QueryResultWrapper
tools.refinery.interpreter.api.impl.BaseMatcher<Match>
- Type Parameters:
Match
-
- All Implemented Interfaces:
InterpreterMatcher<Match>
- Direct Known Subclasses:
GenericPatternMatcher
public abstract class BaseMatcher<Match extends IPatternMatch>
extends QueryResultWrapper
implements InterpreterMatcher<Match>
Base implementation of ViatraQueryMatcher.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected InterpreterEngine
protected IQuerySpecification
<? extends BaseMatcher<Match>> Fields inherited from class tools.refinery.interpreter.internal.apiimpl.QueryResultWrapper
backend
-
Constructor Summary
ConstructorsConstructorDescriptionBaseMatcher
(IQuerySpecification<? extends BaseMatcher<Match>> querySpecification) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Match
arrayToMatch
(Object[] parameters) Converts the array representation of a pattern match to an immutable Match object.protected abstract Match
arrayToMatchMutable
(Object[] parameters) Converts the array representation of a pattern match to a mutable Match object.int
Returns the number of all pattern matches.int
countMatches
(Match partialMatch) Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.protected Object[]
void
forEachMatch
(Consumer<? super Match> processor) Executes the given processor on each match of the pattern.void
forEachMatch
(Match match, Consumer<? super Match> processor) Executes the given processor on each match of the pattern that conforms to the given fixed values of some parameters.boolean
forOneArbitraryMatch
(Consumer<? super Match> processor) Executes the given processor on an arbitrarily chosen match of the pattern.boolean
forOneArbitraryMatch
(Match partialMatch, Consumer<? super Match> processor) Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.Returns the set of all pattern matches.getAllMatches
(Match partialMatch) Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.getAllValues
(String parameterName) Retrieve the set of values that occur in matches for the given parameterName.getAllValues
(String parameterName, Match partialMatch) Retrieve the set of values that occur in matches for the given parameterName, that conforms to the given fixed values of some parameters.Returns the engine that the matcher uses.Returns an arbitrarily chosen pattern match.getOneArbitraryMatch
(Match partialMatch) Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.Returns the array of symbolic parameter names.Fully qualified name of the pattern.getPositionOfParameter
(String parameterName) Returns the index of the symbolic parameter with the given name.IQuerySpecification
<? extends BaseMatcher<Match>> The pattern that will be matched.boolean
hasMatch()
Indicates whether the query has any kind of matches.boolean
Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, under any possible substitution of the unspecified parameters (if any).protected Object[]
matchToArray
(Match partialMatch) Converts the Match object of a pattern match to the array representation.Returns an empty, mutable Match for the matcher.Returns a new (partial) Match object for the matcher.protected <T> void
rawAccumulateAllValues
(int position, Object[] parameters, Set<T> accumulator) Uses an existing set to accumulate all values of the parameter with the given name.protected int
rawCountMatches
(Object[] parameters) Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.protected void
rawForEachMatch
(Object[] parameters, Consumer<? super Match> processor) Executes the given processor on each match of the pattern that conforms to the given fixed values of some parameters.protected boolean
rawForOneArbitraryMatch
(Object[] parameters, Consumer<? super Match> processor) Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.rawGetOneArbitraryMatch
(Object[] parameters) Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.protected boolean
rawHasMatch
(Object[] parameters) Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, under any possible substitution of the unspecified parameters.rawStreamAllMatches
(Object[] parameters) Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.rawStreamAllValues
(int position, Object[] parameters) Retrieve a stream of values that occur in matches for the given parameterName, that conforms to the given fixed values of some parameters.protected void
setBackend
(InterpreterEngine engine, IQueryResultProvider resultProvider, IMatcherCapability capabilities) Returns a stream of all pattern matches.streamAllMatches
(Match partialMatch) Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.protected abstract Match
-
Field Details
-
engine
-
querySpecification
protected IQuerySpecification<? extends BaseMatcher<Match extends IPatternMatch>> querySpecification
-
-
Constructor Details
-
BaseMatcher
- Since:
- 1.4
-
-
Method Details
-
setBackend
protected void setBackend(InterpreterEngine engine, IQueryResultProvider resultProvider, IMatcherCapability capabilities) - Specified by:
setBackend
in classQueryResultWrapper
- Since:
- 1.4
-
arrayToMatch
Converts the array representation of a pattern match to an immutable Match object. -
arrayToMatchMutable
Converts the array representation of a pattern match to a mutable Match object. -
matchToArray
Converts the Match object of a pattern match to the array representation. -
tupleToMatch
-
emptyArray
-
getPositionOfParameter
Description copied from interface:InterpreterMatcher
Returns the index of the symbolic parameter with the given name.- Specified by:
getPositionOfParameter
in interfaceInterpreterMatcher<Match extends IPatternMatch>
-
getParameterNames
Description copied from interface:InterpreterMatcher
Returns the array of symbolic parameter names.- Specified by:
getParameterNames
in interfaceInterpreterMatcher<Match extends IPatternMatch>
-
getAllMatches
Description copied from interface:InterpreterMatcher
Returns the set of all pattern matches.- Specified by:
getAllMatches
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Returns:
- matches represented as a Match object.
-
streamAllMatches
Description copied from interface:InterpreterMatcher
Returns a stream of all pattern matches.WARNING If the result set changes while the stream is evaluated, the set of matches included in the stream are unspecified. In such cases, either rely on
InterpreterMatcher.getAllMatches()
or collect the results of the stream in end-user code.- Specified by:
streamAllMatches
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Returns:
- matches represented as a Match object.
-
rawStreamAllMatches
Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.- Parameters:
parameters
- array where each non-null element binds the corresponding pattern parameter to a fixed value.- Returns:
- matches represented as a Match object.
- Since:
- 2.0
-
getAllMatches
Description copied from interface:InterpreterMatcher
Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.- Specified by:
getAllMatches
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
partialMatch
- a partial match of the pattern where each non-null field binds the corresponding pattern parameter to a fixed value.- Returns:
- matches represented as a Match object.
-
streamAllMatches
Description copied from interface:InterpreterMatcher
Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.WARNING If the result set changes while the stream is evaluated, the set of matches included in the stream are unspecified. In such cases, either rely on
InterpreterMatcher.getAllMatches()
or collect the results of the stream in end-user code.- Specified by:
streamAllMatches
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
partialMatch
- a partial match of the pattern where each non-null field binds the corresponding pattern parameter to a fixed value.- Returns:
- matches represented as a Match object.
-
getOneArbitraryMatch
Description copied from interface:InterpreterMatcher
Returns an arbitrarily chosen pattern match. Neither determinism nor randomness of selection is guaranteed.- Specified by:
getOneArbitraryMatch
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Returns:
- a match represented as a Match object, or an empty Optional if no match is found.
-
rawGetOneArbitraryMatch
Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. Neither determinism nor randomness of selection is guaranteed.- Parameters:
parameters
- array where each non-null element binds the corresponding pattern parameter to a fixed value.- Returns:
- a match represented as a Match object, or null if no match is found.
- Since:
- 2.0
-
getOneArbitraryMatch
Description copied from interface:InterpreterMatcher
Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. Neither determinism nor randomness of selection is guaranteed.- Specified by:
getOneArbitraryMatch
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
partialMatch
- a partial match of the pattern where each non-null field binds the corresponding pattern parameter to a fixed value.- Returns:
- a match represented as a Match object, or an empty Optional if no match is found.
-
rawHasMatch
Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, under any possible substitution of the unspecified parameters.- Parameters:
parameters
- array where each non-null element binds the corresponding pattern parameter to a fixed value.- Returns:
- true if the input is a valid (partial) match of the pattern.
-
hasMatch
public boolean hasMatch()Description copied from interface:InterpreterMatcher
Indicates whether the query has any kind of matches.- Specified by:
hasMatch
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Returns:
- true if there exists a valid match of the pattern.
-
hasMatch
Description copied from interface:InterpreterMatcher
Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, under any possible substitution of the unspecified parameters (if any).- Specified by:
hasMatch
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
partialMatch
- a (partial) match of the pattern where each non-null field binds the corresponding pattern parameter to a fixed value.- Returns:
- true if the input is a valid (partial) match of the pattern.
-
countMatches
public int countMatches()Description copied from interface:InterpreterMatcher
Returns the number of all pattern matches.- Specified by:
countMatches
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Returns:
- the number of pattern matches found.
-
rawCountMatches
Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.- Parameters:
parameters
- array where each non-null element binds the corresponding pattern parameter to a fixed value.- Returns:
- the number of pattern matches found.
-
countMatches
Description copied from interface:InterpreterMatcher
Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.- Specified by:
countMatches
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
partialMatch
- a partial match of the pattern where each non-null field binds the corresponding pattern parameter to a fixed value.- Returns:
- the number of pattern matches found.
-
rawForEachMatch
Executes the given processor on each match of the pattern that conforms to the given fixed values of some parameters.- Parameters:
parameters
- array where each non-null element binds the corresponding pattern parameter to a fixed value.action
- the action that will process each pattern match.- Since:
- 2.0
-
forEachMatch
Description copied from interface:InterpreterMatcher
Executes the given processor on each match of the pattern.- Specified by:
forEachMatch
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
processor
- the action that will process each pattern match.
-
forEachMatch
Description copied from interface:InterpreterMatcher
Executes the given processor on each match of the pattern that conforms to the given fixed values of some parameters.- Specified by:
forEachMatch
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
match
- array where each non-null element binds the corresponding pattern parameter to a fixed value.processor
- the action that will process each pattern match.
-
forOneArbitraryMatch
Description copied from interface:InterpreterMatcher
Executes the given processor on an arbitrarily chosen match of the pattern. Neither determinism nor randomness of selection is guaranteed.- Specified by:
forOneArbitraryMatch
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
processor
- the action that will process the selected match.- Returns:
- true if the pattern has at least one match, false if the processor was not invoked
-
forOneArbitraryMatch
Description copied from interface:InterpreterMatcher
Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. Neither determinism nor randomness of selection is guaranteed.- Specified by:
forOneArbitraryMatch
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
partialMatch
- array where each non-null element binds the corresponding pattern parameter to a fixed value.processor
- the action that will process the selected match.- Returns:
- true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
-
rawForOneArbitraryMatch
Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. Neither determinism nor randomness of selection is guaranteed.- Parameters:
parameters
- array where each non-null element binds the corresponding pattern parameter to a fixed value.processor
- the action that will process the selected match.- Returns:
- true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
- Since:
- 2.0
-
newEmptyMatch
Description copied from interface:InterpreterMatcher
Returns an empty, mutable Match for the matcher. Fields of the mutable match can be filled to create a partial match, usable as matcher input. This can be used to call the matcher with a partial match even if the specific class of the matcher or the match is unknown.- Specified by:
newEmptyMatch
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Returns:
- the empty match
-
newMatch
Description copied from interface:InterpreterMatcher
Returns a new (partial) Match object for the matcher. This can be used e.g. to call the matcher with a partial match.The returned match will be immutable. Use
InterpreterMatcher.newEmptyMatch()
to obtain a mutable match object.- Specified by:
newMatch
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
parameters
- the fixed value of pattern parameters, or null if not bound.- Returns:
- the (partial) match object.
-
getAllValues
Description copied from interface:InterpreterMatcher
Retrieve the set of values that occur in matches for the given parameterName.- Specified by:
getAllValues
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
parameterName
- name of the parameter for which values are returned- Returns:
- the Set of all values for the given parameter, null if the parameter with the given name does not exists, empty set if there are no matches
-
getAllValues
Description copied from interface:InterpreterMatcher
Retrieve the set of values that occur in matches for the given parameterName, that conforms to the given fixed values of some parameters.- Specified by:
getAllValues
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Parameters:
parameterName
- name of the parameter for which values are returnedpartialMatch
- a partial match of the pattern where each non-null field binds the corresponding pattern parameter to a fixed value.- Returns:
- the Set of all values for the given parameter, null if the parameter with the given name does not exists or if the parameter with the given name is set in partialMatch, empty set if there are no matches
-
rawStreamAllValues
Retrieve a stream of values that occur in matches for the given parameterName, that conforms to the given fixed values of some parameters.- Parameters:
position
- position of the parameter for which values are returnedparameters
- a parameter array corresponding to a partial match of the pattern where each non-null field binds the corresponding pattern parameter to a fixed value.- Returns:
- the stream of all values in the given position
- Throws:
IllegalArgumentException
- if length of parameters array does not equal to number of parametersIndexOutOfBoundsException
- if position is not appropriate for the current parameter size- Since:
- 2.0
-
rawAccumulateAllValues
Uses an existing set to accumulate all values of the parameter with the given name. Since it is a protected method, no error checking or input validation is performed!- Parameters:
position
- position of the parameter for which values are returnedparameters
- a parameter array corresponding to a partial match of the pattern where each non-null field binds the corresponding pattern parameter to a fixed value.accumulator
- the existing set to fill with the values
-
getEngine
Description copied from interface:InterpreterMatcher
Returns the engine that the matcher uses.- Specified by:
getEngine
in interfaceInterpreterMatcher<Match extends IPatternMatch>
- Returns:
- the engine
-
getSpecification
Description copied from interface:InterpreterMatcher
The pattern that will be matched.- Specified by:
getSpecification
in interfaceInterpreterMatcher<Match extends IPatternMatch>
-
getPatternName
Description copied from interface:InterpreterMatcher
Fully qualified name of the pattern.- Specified by:
getPatternName
in interfaceInterpreterMatcher<Match extends IPatternMatch>
-
getCapabilities
- Since:
- 1.4
-