Class Search<A>
- Type Parameters:
A
- the target type.
- All Implemented Interfaces:
Serializable
,Cloneable
Subclasses must implement the initAlternatives(A)
and
nextAlternative()
methods.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.bandm.tools.paisley.Pattern
Pattern.Either<A>
-
Field Summary
Modifier and TypeFieldDescriptionThe current alternative.protected A
The target for the current alternative.Fields inherited from class eu.bandm.tools.paisley.Pattern
_left_matched, _target_save, none
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
initAlternatives
(A target) Sets up the dynamic enumeration of alternatives for a target.boolean
Checks whether this pattern is deterministic.boolean
Attempts to match this pattern against a given object.boolean
Attempts to re-match this pattern against a previously matched object.protected abstract boolean
Enumerates an alternative.Methods inherited from class eu.bandm.tools.paisley.Pattern
all, all, all, all, all, and, andThen, andThen, any, aside, binds, both, clear, clear, clone, compile, compileClear, compileClear, compileCut, compileCut, compileIsDeterministic, compileMatch, compileMatchAgain, compileSubPattern, compileThis, compileUpTo, cut, cut, DEBUG, either, enPassant, flatten, limit, main, matchOnce, matchVar, narrow, newAll, noMatch, none, of, or, orElse, orElse, preserves, preserves, repeat, some, some, some, some, someMatch, startCompile, uniquely, variable, variable
-
Field Details
-
alt
The current alternative. -
arg
The target for the current alternative.
-
-
Constructor Details
-
Search
public Search()
-
-
Method Details
-
initAlternatives
Sets up the dynamic enumeration of alternatives for a target.- Parameters:
target
- the object to be matched against.
-
nextAlternative
protected abstract boolean nextAlternative()Enumerates an alternative. Must be called only afterinitAlternatives(A)
.If an alternative is found,
alt
andarg
must be set to non-null
values accordingly.- Returns:
true
if an(other) alternative has been found;false
otherwise.
-
match
Attempts to match this pattern against a given object. If the class of this pattern imposes a specific order on matches, the first one is chosen.This implementation uses
initAlternatives(A)
andnextAlternative()
to find the first matching alternative for the target, and succeeds if one is found. Alternative matching is done byalt.match(arg)
. -
matchAgain
public boolean matchAgain()Attempts to re-match this pattern against a previously matched object. If the class of this pattern imposes a specific order on matches, they are chosen in that order, beginning with the second one. The behaviour of this method is unspecified if the last matching attempt of this pattern has not been successful.Patterns classes that do not override this method are deterministic. Pattern classes that overwrite this method to provide additional matches should also override
Pattern.isDeterministic()
.This implementation first tries to match the last m,atching alternative again. On failure it uses
nextAlternative()
to find the next matching alternative for the target, and succeeds if one is found. Alternative matching is done byalt.match(arg)
.- Overrides:
matchAgain
in classPattern<A>
- Returns:
true
if the matching is successful,false
if it fails. WhichVariable
s are bound by a successful match depends. The default implementation always returnsfalse
.- See Also:
-
isDeterministic
public boolean isDeterministic()Checks whether this pattern is deterministic.The default implementation returns
true
.This implementation returns
false
.- Overrides:
isDeterministic
in classPattern<A>
- Returns:
true
if this pattern is guaranteed to match any object at most once,false
otherwise.- See Also:
-