Class RestrictedTransform<A,B>
- Type Parameters:
A- the target type of the containing patternB- the target type of the contained subpattern
- All Implemented Interfaces:
Pattern<A>,Serializable,Cloneable
- Direct Known Subclasses:
CachedTransform,Filter
Subclasses must implement the Transform.apply(A) method. They should also
override the isDomain(A) and/or isRange(B) method to impose
restrictions on which transformed targets are to be delegated.
Patterns of this class match body against target if both
isDomain(target) and isRange(apply(target)) return
true; or fail immediately otherwise.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRestrictedTransform(Pattern<? super B> body) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidcut(boolean recursively) Disposes of all temporary internal state related to nondeterminism.booleanChecks whether a given target is supported by this transform.booleanChecks whether a given result is supported by this transform.booleanAttempts to match this pattern against a given object.booleanAttempts to re-match this pattern against a previously matched object.static <A,B> Pattern <A> ofUnlessNull(Function<? super A, ? extends B> fun, Pattern<B> body) static <A,B> Motif <B, A> withUnlessNull(Function<? super A, ? extends B> fun) Methods inherited from class eu.bandm.tools.paisley.Unary
binds, clear, fork, getBody, isDeterministic, preserves, preserves, setBodyMethods inherited from class eu.bandm.tools.paisley.AbstractPattern
clone, doclone
-
Constructor Details
-
RestrictedTransform
Creates a new instance.- Parameters:
body- the subpattern
-
-
Method Details
-
ofUnlessNull
-
withUnlessNull
-
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(). The default implementation delegates toUnary.body.- Specified by:
matchAgainin interfacePattern<A>- Overrides:
matchAgainin classUnary<B,A> - Returns:
trueif the matching is successful,falseif it fails. WhichVariables are bound by a successful match depends. The default implementation always returnsfalse.- See Also:
-
isDomain
Checks whether a given target is supported by this transform.The default implementation always returns
true.Subclasses should override this method to restrict the supported targets.
- Parameters:
target- the target to match against- Returns:
trueiftargetis supported by this transform;falseotherwise
-
isRange
Checks whether a given result is supported by this transform.The default implementation always returns
true.Subclasses should override this method to restrict the supported results.
- Parameters:
transformed- the transformation result- Returns:
trueiftransformedis supported by this transform;falseotherwise
-
cut
public void cut(boolean recursively) Description copied from class:UnaryDisposes 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). The default implementation delegates toUnary.bodyifrecursivelyistrue.
-