Class MultiTransform<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>
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 must implement the apply(A) method.
Use this class rather than FlatMultiTransform as a base class if
an Iterable view on transformation results is readily available.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMultiTransform(Pattern<? super B> body) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionTransforms a target to be matched into an enumeration of targets for the subpattern.final voidclose()Finalizes the iteration of transformation results for the current target.final booleanhasNext()final Bnext()static <A,B> MultiTransform <A, B> Creates a new instance with the given multi-valued transformation function and subpattern.final voidInitiates the iteration of transformation results for the given target.Methods inherited from class eu.bandm.tools.paisley.FlatMultiTransform
cut, isDeterministic, match, matchAgainMethods 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, remove
-
Constructor Details
-
MultiTransform
Creates a new instance.- Parameters:
body- the subpattern- Throws:
NullPointerException- ifbodyis null
-
-
Method Details
-
of
public static <A,B> MultiTransform<A,B> of(Function<? super A, ? extends Iterable<B>> fun, Pattern<? super B> body) Creates a new instance with the given multi-valued transformation function and subpattern.- Type Parameters:
A- the target type of the containing patternB- the target type of the contained subpattern- Parameters:
fun- the transformation functionbody- the subpattern- Returns:
- a pattern that transforms each target with
fun, passes all results tobody, and combines the respective matches disjunctively. - Throws:
NullPointerException- iffunorbodyis null
-
apply
Transforms a target to be matched into an enumeration of targets for the subpattern.- Parameters:
target- the target for this pattern to be matched against.- Returns:
- an enumeration of targets (possibly empty) for
Unary.bodyto be matched against.
-
open
Initiates the iteration of transformation results for the given target.This method is called once for each invocation of
FlatMultiTransform.match(A).The default implementation does nothing.
Subclasses must implement this method to set up the initial iterator state.
- Overrides:
openin classFlatMultiTransform<A,B> - Parameters:
target- the target object to match against
-
close
public final 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
FlatMultiTransform.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.
- Overrides:
closein classFlatMultiTransform<A,B>
-
hasNext
public final boolean hasNext() -
next
-