Class RestrictedTransform<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
Direct Known Subclasses:
CachedTransform, Filter

@Generated(generator="eu.bandm.tools.expander", version="", timestamp="2026-01-24T11:39:09") public abstract class RestrictedTransform<A,B> extends Transform<A,B>
Abstract base class for patterns that either delegate transformed targets to a subpattern or fail immediately.

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

    • RestrictedTransform

      protected RestrictedTransform(Pattern<? super B> body)
      Creates a new instance.
      Parameters:
      body - the subpattern
  • Method Details

    • ofUnlessNull

      public static <A, B> Pattern<A> ofUnlessNull(Function<? super A,? extends B> fun, Pattern<B> body)
    • withUnlessNull

      public static <A, B> Motif<B,A> withUnlessNull(Function<? super A,? extends B> fun)
    • match

      public boolean match(A target)
      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 null target is generally allowed.

      Parameters:
      target - the object to match against
      Returns:
      true if the matching is successful, false if it fails. Which Variables 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 to Unary.body.

      Specified by:
      matchAgain in interface Pattern<A>
      Overrides:
      matchAgain in class Unary<B,A>
      Returns:
      true if the matching is successful, false if it fails. Which Variables are bound by a successful match depends. The default implementation always returns false.
      See Also:
    • isDomain

      public boolean isDomain(A target)
      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:
      true if target is supported by this transform; false otherwise
    • isRange

      public boolean isRange(B transformed)
      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:
      true if transformed is supported by this transform; false otherwise
    • cut

      public void cut(boolean recursively)
      Description copied from class: Unary
      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 of cut(false). The default implementation delegates to Unary.body if recursively is true.

      Specified by:
      cut in interface Pattern<A>
      Overrides:
      cut in class Unary<B,A>
      Parameters:
      recursively - true if all subpatterns should traversed, false otherwise.