Class Adaptive<A>
- Type Parameters:
A- the target type of the delegate pattern
- All Implemented Interfaces:
Pattern<A>,Serializable,Cloneable
- See Also:
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear(boolean recursively) Disposes of all temporary internal state related to results and nondeterminism.voidcut(boolean recursively) Disposes of all temporary internal state related to nondeterminism.Returns a delegate pattern for the given target.fork()Makes a copy of this pattern with independent internal state.booleanAttempts to match this pattern against a given object.booleanAttempts to re-match this pattern against a previously matched object.static <A> Adaptive<A> Returns a pattern that delegates by the given function.Methods inherited from class eu.bandm.tools.paisley.AbstractPattern
clone, doclone
-
Constructor Details
-
Adaptive
protected Adaptive()Creates a new instance.
-
-
Method Details
-
fork
Makes a copy of this pattern with independent internal state.Subclasses must override this method if necessary to honour the following rules for all transitively reachable patterns:
- Subpatterns that are instances of
Variablemust be shared. This implies thatVariable.fork()must returnthis. - Fields that do not refer to subpatterns, but to matching
state (changed by invocations of
Pattern.match(A),Pattern.matchAgain(),Pattern.cut()orPattern.clear()) must be duplicated. If matching state changes are effected by modification of other objects, these must be duplicated. In summary, matching operations on this pattern and its copy must not interfere, with the exception of variable bindings. - Fields neither referring to subpatterns nor to matching state may be either shared or duplicated. The usage of such fields in a modifiable way (such that the distinction is relevant) is strongly deprecated.
- Patterns
whose fields need not be duplicated need not be duplicated themselves, but
may return
this.
- Subpatterns that are instances of
-
delegate
Returns a delegate pattern for the given target.- Parameters:
target- the object to match against- Returns:
- the chosen delegate pattern
-
of
Returns a pattern that delegates by the given function.- Type Parameters:
A- the target type of objects to match against- Parameters:
fun- a function to compute a delegate pattern for each target- Returns:
- a pattern that matches any target by matching
fun.apply(target)
-
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).- Parameters:
recursively-trueif all subpatterns should traversed,falseotherwise.
-
clear
public void clear(boolean recursively) Disposes of all temporary internal state related to results and nondeterminism.The default implementation just invokes
cut(false). Subclasses that override this method should either invoke this overridden implementation, or ensure by other means that the effect ofcut(false)is implied. The default implementation invokescut(false), and delegates tobodyifrecursivelyistrue.- Parameters:
recursively-trueif all subpatterns should be traversed,falseotherwise.
-