Class MultiTransform<A,B>

Type Parameters:
A - the target type of the containing pattern
B - the target type of the contained subpattern
All Implemented Interfaces:
Pattern<A>, Serializable, Cloneable, Iterator<B>

@Generated(generator="eu.bandm.tools.expander", version="", timestamp="2026-01-24T11:39:11") public abstract class MultiTransform<A,B> extends FlatMultiTransform<A,B>
Abstract base class for patterns that delegate several transformation results for a target to a subpattern.

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:
  • Constructor Details

    • MultiTransform

      protected MultiTransform(Pattern<? super B> body)
      Creates a new instance.
      Parameters:
      body - the subpattern
      Throws:
      NullPointerException - if body is 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 pattern
      B - the target type of the contained subpattern
      Parameters:
      fun - the transformation function
      body - the subpattern
      Returns:
      a pattern that transforms each target with fun, passes all results to body, and combines the respective matches disjunctively.
      Throws:
      NullPointerException - if fun or body is null
    • apply

      public abstract Iterable<B> apply(A target)
      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.body to be matched against.
    • open

      public final void open(A target)
      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:
      open in class FlatMultiTransform<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:
      close in class FlatMultiTransform<A,B>
    • hasNext

      public final boolean hasNext()
    • next

      public final B next()