Class Either<A>
- Type Parameters:
A- the target type of objects to match against
- All Implemented Interfaces:
Pattern<A>,Serializable,Cloneable
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether a variable is bound by this pattern.voidcut(boolean recursively) Disposes of all temporary internal state related to nondeterminism.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.booleanChecks whether a variable is preserved by this pattern unconditionally.booleanChecks whether a variable is preserved by this pattern, conditionally on success or failure.protected StringReturns a human-readable operator symbol or name for this pattern.Methods inherited from class eu.bandm.tools.paisley.AbstractPattern
clone, doclone
-
Constructor Details
-
Either
Creates a new instance.- Parameters:
left- the left subpatternright- the right subpattern- Throws:
NullPointerException- ifleftorrightis null
-
-
Method Details
-
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.- 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().- Returns:
trueif the matching is successful,falseif it fails. WhichVariables are bound by a successful match depends. The default implementation always returnsfalse.- See Also:
-
cut
public void cut(boolean recursively) Disposes of all temporary internal state related to nondeterminism.The default implementation does nothing. Subclasses that override this method should also override
Pattern.clear(boolean)and ensure that it implies the effect ofcut(false).This implementation delegates to
leftandrightifrecursivelyistrue. -
binds
Checks whether a variable is bound by this pattern.The default implementation returns
false.- Parameters:
v- a pattern variable- Returns:
trueif the variable is guaranteed to have a meaningful value when this pattern is open,falseotherwise.
-
preserves
Checks whether a variable is preserved by this pattern, conditionally on success or failure.The default implementation returns
false.- Parameters:
v- a pattern variablesuccess- specifies preservation on success or failure- Returns:
trueif the variable value is guaranteed to be unaffected by a matching attempt with this pattern that returns a value equal tosuccess.
-
preserves
Checks whether a variable is preserved by this pattern unconditionally.The default implementation returns
false.- Parameters:
v- a pattern variable- Returns:
trueif the variable value is guaranteed to be unaffected by any matching attempt with this pattern.
-
isDeterministic
public boolean isDeterministic()Checks whether this pattern is deterministic.The default implementation returns
false.- Returns:
trueif this pattern is guaranteed to match any object at most once,falseotherwise.- See Also:
-
toStringOperator
Returns a human-readable operator symbol or name for this pattern.Subclasses should override this method to provide adequate information.
The default implementation delegates to
Object.toString().- Overrides:
toStringOperatorin classBinary<A,A, A> - Returns:
- a human-readable operator symbol or name for this pattern
-