Class Search<A>
- Type Parameters:
A- the target type.
- All Implemented Interfaces:
Pattern<A>,Serializable,Cloneable
Subclasses must implement the initAlternatives(A) and nextAlternative() methods.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe current alternative.protected AThe target for the current alternative. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidinitAlternatives(A target) Sets up the dynamic enumeration of alternatives for a target.booleanChecks whether this pattern is deterministic.booleanAttempts to match this pattern against a given object.booleanAttempts to re-match this pattern against a previously matched object.protected abstract booleanEnumerates an alternative.Methods inherited from class eu.bandm.tools.paisley.AbstractPattern
clone, doclone, fork
-
Field Details
-
currentAlt
The current alternative. -
currentAltTarget
The target for the current alternative.
-
-
Constructor Details
-
Search
protected Search()Creates a new instance.
-
-
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,
currentAltandcurrentAltTargetmust be set accordingly.- Returns:
trueif an(other) alternative has been found;falseotherwise.
-
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.
The
nulltarget is generally allowed.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).- Parameters:
target- the object to match against- Returns:
trueif the matching is successful,falseif it fails. WhichVariables are bound by a successful or failed match depends.- See Also:
-
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 matching alternative again. On failure it uses
nextAlternative()to find the next matching alternative for the target, and succeeds if one is found.- Returns:
trueif the matching is successful,falseif it fails. WhichVariables 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
false.This implementation returns
false.- Returns:
trueif this pattern is guaranteed to match any object at most once,falseotherwise.- See Also:
-