Match
- public abstract class BaseMatcher<Match extends IPatternMatch> extends org.eclipse.viatra.query.runtime.internal.apiimpl.QueryResultWrapper implements ViatraQueryMatcher<Match>
Modifier and Type | Field and Description |
---|---|
protected ViatraQueryEngine |
engine |
protected IQuerySpecification<? extends BaseMatcher<Match>> |
querySpecification |
Constructor and Description |
---|
BaseMatcher(IQuerySpecification<? extends BaseMatcher<Match>> querySpecification) |
Modifier and Type | Method and Description |
---|---|
protected abstract Match |
arrayToMatch(java.lang.Object[] parameters)
Converts the array representation of a pattern match to an immutable Match object.
|
protected abstract Match |
arrayToMatchMutable(java.lang.Object[] parameters)
Converts the array representation of a pattern match to a mutable Match object.
|
int |
countMatches()
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 java.lang.Object[] |
emptyArray() |
void |
forEachMatch(java.util.function.Consumer<? super Match> processor)
Executes the given processor on each match of the pattern.
|
void |
forEachMatch(Match match,
java.util.function.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(java.util.function.Consumer<? super Match> processor)
Executes the given processor on an arbitrarily chosen match of the pattern.
|
boolean |
forOneArbitraryMatch(Match partialMatch,
java.util.function.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.
|
java.util.Collection<Match> |
getAllMatches()
Returns the set of all pattern matches.
|
java.util.Collection<Match> |
getAllMatches(Match partialMatch)
Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
|
java.util.Set<java.lang.Object> |
getAllValues(java.lang.String parameterName)
Retrieve the set of values that occur in matches for the given parameterName.
|
java.util.Set<java.lang.Object> |
getAllValues(java.lang.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.
|
IMatcherCapability |
getCapabilities() |
ViatraQueryEngine |
getEngine()
Returns the engine that the matcher uses.
|
java.util.Optional<Match> |
getOneArbitraryMatch()
Returns an arbitrarily chosen pattern match.
|
java.util.Optional<Match> |
getOneArbitraryMatch(Match partialMatch)
Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
|
java.util.List<java.lang.String> |
getParameterNames()
Returns the array of symbolic parameter names.
|
java.lang.String |
getPatternName()
Fully qualified name of the pattern.
|
java.lang.Integer |
getPositionOfParameter(java.lang.String parameterName)
Returns the index of the symbolic parameter with the given name.
|
IQuerySpecification<? extends BaseMatcher<Match>> |
getSpecification()
The pattern that will be matched.
|
boolean |
hasMatch()
Indicates whether the query has any kind of matches.
|
boolean |
hasMatch(Match partialMatch)
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 java.lang.Object[] |
matchToArray(Match partialMatch)
Converts the Match object of a pattern match to the array representation.
|
Match |
newEmptyMatch()
Returns an empty, mutable Match for the matcher.
|
Match |
newMatch(java.lang.Object... parameters)
Returns a new (partial) Match object for the matcher.
|
protected <T> void |
rawAccumulateAllValues(int position,
java.lang.Object[] parameters,
java.util.Set<T> accumulator)
Uses an existing set to accumulate all values of the parameter with the given name.
|
protected int |
rawCountMatches(java.lang.Object[] parameters)
Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
|
protected void |
rawForEachMatch(java.lang.Object[] parameters,
java.util.function.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(java.lang.Object[] parameters,
java.util.function.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.
|
protected java.util.Optional<Match> |
rawGetOneArbitraryMatch(java.lang.Object[] parameters)
Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
|
protected boolean |
rawHasMatch(java.lang.Object[] parameters)
Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, under
any possible substitution of the unspecified parameters.
|
protected java.util.stream.Stream<Match> |
rawStreamAllMatches(java.lang.Object[] parameters)
Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
|
protected java.util.stream.Stream<java.lang.Object> |
rawStreamAllValues(int position,
java.lang.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(ViatraQueryEngine engine,
IQueryResultProvider resultProvider,
IMatcherCapability capabilities) |
java.util.stream.Stream<Match> |
streamAllMatches()
Returns a stream of all pattern matches.
|
java.util.stream.Stream<Match> |
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 |
tupleToMatch(Tuple t) |
protected ViatraQueryEngine engine
protected IQuerySpecification<? extends BaseMatcher<Match extends IPatternMatch>> querySpecification
public BaseMatcher(IQuerySpecification<? extends BaseMatcher<Match>> querySpecification)
protected void setBackend(ViatraQueryEngine engine, IQueryResultProvider resultProvider, IMatcherCapability capabilities)
setBackend
in class org.eclipse.viatra.query.runtime.internal.apiimpl.QueryResultWrapper
protected abstract Match arrayToMatch(java.lang.Object[] parameters)
protected abstract Match arrayToMatchMutable(java.lang.Object[] parameters)
protected java.lang.Object[] matchToArray(Match partialMatch)
protected java.lang.Object[] emptyArray()
public java.lang.Integer getPositionOfParameter(java.lang.String parameterName)
ViatraQueryMatcher
getPositionOfParameter
in interface ViatraQueryMatcher<Match extends IPatternMatch>
public java.util.List<java.lang.String> getParameterNames()
ViatraQueryMatcher
getParameterNames
in interface ViatraQueryMatcher<Match extends IPatternMatch>
public java.util.Collection<Match> getAllMatches()
ViatraQueryMatcher
getAllMatches
in interface ViatraQueryMatcher<Match extends IPatternMatch>
public java.util.stream.Stream<Match> streamAllMatches()
ViatraQueryMatcher
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 ViatraQueryMatcher.getAllMatches()
or collect the results of the
stream in end-user code.
streamAllMatches
in interface ViatraQueryMatcher<Match extends IPatternMatch>
protected java.util.stream.Stream<Match> rawStreamAllMatches(java.lang.Object[] parameters)
parameters
- array where each non-null element binds the corresponding pattern parameter to a fixed value.public java.util.Collection<Match> getAllMatches(Match partialMatch)
ViatraQueryMatcher
getAllMatches
in interface ViatraQueryMatcher<Match extends IPatternMatch>
partialMatch
- a partial match of the pattern where each non-null field binds the corresponding pattern parameter to
a fixed value.public java.util.stream.Stream<Match> streamAllMatches(Match partialMatch)
ViatraQueryMatcher
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 ViatraQueryMatcher.getAllMatches()
or collect the results of the
stream in end-user code.
streamAllMatches
in interface ViatraQueryMatcher<Match extends IPatternMatch>
partialMatch
- a partial match of the pattern where each non-null field binds the corresponding pattern parameter to
a fixed value.public java.util.Optional<Match> getOneArbitraryMatch()
ViatraQueryMatcher
getOneArbitraryMatch
in interface ViatraQueryMatcher<Match extends IPatternMatch>
protected java.util.Optional<Match> rawGetOneArbitraryMatch(java.lang.Object[] parameters)
parameters
- array where each non-null element binds the corresponding pattern parameter to a fixed value.public java.util.Optional<Match> getOneArbitraryMatch(Match partialMatch)
ViatraQueryMatcher
getOneArbitraryMatch
in interface ViatraQueryMatcher<Match extends IPatternMatch>
partialMatch
- a partial match of the pattern where each non-null field binds the corresponding pattern parameter to
a fixed value.protected boolean rawHasMatch(java.lang.Object[] parameters)
parameters
- array where each non-null element binds the corresponding pattern parameter to a fixed value.public boolean hasMatch()
ViatraQueryMatcher
hasMatch
in interface ViatraQueryMatcher<Match extends IPatternMatch>
public boolean hasMatch(Match partialMatch)
ViatraQueryMatcher
hasMatch
in interface ViatraQueryMatcher<Match extends IPatternMatch>
partialMatch
- a (partial) match of the pattern where each non-null field binds the corresponding pattern parameter
to a fixed value.public int countMatches()
ViatraQueryMatcher
countMatches
in interface ViatraQueryMatcher<Match extends IPatternMatch>
protected int rawCountMatches(java.lang.Object[] parameters)
parameters
- array where each non-null element binds the corresponding pattern parameter to a fixed value.public int countMatches(Match partialMatch)
ViatraQueryMatcher
countMatches
in interface ViatraQueryMatcher<Match extends IPatternMatch>
partialMatch
- a partial match of the pattern where each non-null field binds the corresponding pattern parameter to
a fixed value.protected void rawForEachMatch(java.lang.Object[] parameters, java.util.function.Consumer<? super Match> processor)
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.public void forEachMatch(java.util.function.Consumer<? super Match> processor)
ViatraQueryMatcher
forEachMatch
in interface ViatraQueryMatcher<Match extends IPatternMatch>
processor
- the action that will process each pattern match.public void forEachMatch(Match match, java.util.function.Consumer<? super Match> processor)
ViatraQueryMatcher
forEachMatch
in interface ViatraQueryMatcher<Match extends IPatternMatch>
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.public boolean forOneArbitraryMatch(java.util.function.Consumer<? super Match> processor)
ViatraQueryMatcher
forOneArbitraryMatch
in interface ViatraQueryMatcher<Match extends IPatternMatch>
processor
- the action that will process the selected match.public boolean forOneArbitraryMatch(Match partialMatch, java.util.function.Consumer<? super Match> processor)
ViatraQueryMatcher
forOneArbitraryMatch
in interface ViatraQueryMatcher<Match extends IPatternMatch>
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.protected boolean rawForOneArbitraryMatch(java.lang.Object[] parameters, java.util.function.Consumer<? super Match> processor)
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.public Match newEmptyMatch()
ViatraQueryMatcher
newEmptyMatch
in interface ViatraQueryMatcher<Match extends IPatternMatch>
public Match newMatch(java.lang.Object... parameters)
ViatraQueryMatcher
The returned match will be immutable. Use ViatraQueryMatcher.newEmptyMatch()
to obtain a mutable match object.
newMatch
in interface ViatraQueryMatcher<Match extends IPatternMatch>
parameters
- the fixed value of pattern parameters, or null if not bound.public java.util.Set<java.lang.Object> getAllValues(java.lang.String parameterName)
ViatraQueryMatcher
getAllValues
in interface ViatraQueryMatcher<Match extends IPatternMatch>
parameterName
- name of the parameter for which values are returnedpublic java.util.Set<java.lang.Object> getAllValues(java.lang.String parameterName, Match partialMatch)
ViatraQueryMatcher
getAllValues
in interface ViatraQueryMatcher<Match extends IPatternMatch>
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.protected java.util.stream.Stream<java.lang.Object> rawStreamAllValues(int position, java.lang.Object[] 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.java.lang.IllegalArgumentException
- if length of parameters array does not equal to number of parametersjava.lang.IndexOutOfBoundsException
- if position is not appropriate for the current parameter sizeprotected <T> void rawAccumulateAllValues(int position, java.lang.Object[] parameters, java.util.Set<T> accumulator)
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 valuespublic ViatraQueryEngine getEngine()
ViatraQueryMatcher
getEngine
in interface ViatraQueryMatcher<Match extends IPatternMatch>
public IQuerySpecification<? extends BaseMatcher<Match>> getSpecification()
ViatraQueryMatcher
getSpecification
in interface ViatraQueryMatcher<Match extends IPatternMatch>
public java.lang.String getPatternName()
ViatraQueryMatcher
getPatternName
in interface ViatraQueryMatcher<Match extends IPatternMatch>
public IMatcherCapability getCapabilities()