Class FlatMultiTransform<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,Iterator<B>
- Direct Known Subclasses:
MultiTransform
Matchings of the subpattern to the transformation results are combined disjunctively. In particular, matching fails altogether if there the number of transformation results is zero.
Transformation results for a target are iterated lazily on demand.
Subclasses should implement the methods open(A), close(), and must implement the methods Iterator.hasNext() and Iterator.next().
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFlatMultiTransform(Pattern<? super B> body) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidclose()Finalizes the iteration of transformation results for the current target.final voidcut(boolean recursively) Disposes of all temporary internal state related to nondeterminism.final booleanChecks whether this pattern is deterministic.final booleanAttempts to match this pattern against a given object.final booleanAttempts to re-match this pattern against a previously matched object.protected voidInitiates the iteration of transformation results for the given target.Methods inherited from class eu.bandm.tools.paisley.Unary
binds, clear, fork, getBody, preserves, preserves, setBodyMethods inherited from class eu.bandm.tools.paisley.AbstractPattern
clone, docloneMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Constructor Details
-
FlatMultiTransform
Creates a new instance.- Parameters:
body- the subpattern- Throws:
NullPointerException- ifbodyis 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. -
matchAgain
public final 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:
-
cut
public final 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). The default implementation delegates toUnary.bodyifrecursivelyistrue.This implmentation calls
close(). -
isDeterministic
public final boolean isDeterministic()Checks whether this pattern is deterministic.The default implementation returns
false. This implementation delegates toUnary.body.This implmentation always returns
false.- Specified by:
isDeterministicin interfacePattern<A>- Overrides:
isDeterministicin classUnary<B,A> - Returns:
trueif this pattern is guaranteed to match any object at most once,falseotherwise.- See Also:
-
open
Initiates the iteration of transformation results for the given target.This method is called once for each invocation of
match(A).The default implementation does nothing.
Subclasses must implement this method to set up the initial iterator state.
- Parameters:
target- the target object to match against
-
close
protected void close()Finalizes the iteration of transformation results for the current target.This method is called once for each unsuccessful match, or for each invocation of
cut(boolean).The default implementation does nothing.
Subclasses should override this method to release resources needed during iteration. Implementations should be idempotent; immediately repeated calls should not result in further changes.
-