Class CachedTransform<A,B>

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

public abstract class CachedTransform<A,B> extends RestrictedTransform<A,B>
Abstract base class for patterns that delegate expensively transformed targets to a subpattern. If a subclass of Transform has expensive computations shared between { link Pattern#isApplicable{ FIXME "isApplicable" NOT FOUND SONAR-BT and apply(A), consider subclassing CachedTransform instead.

Subclasses must implement the tryApply(A) method.

See Also:
  • Constructor Details

    • CachedTransform

      protected CachedTransform(Pattern<? super B> body)
      Creates a new pattern.
  • Method Details

    • match

      public final 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.
      Overrides:
      match in class RestrictedTransform<A,B>
      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:
    • isDomain

      public final boolean isDomain(A target)

      This implementation calls tryApply(A) and caches the result.

      Overrides:
      isDomain in class RestrictedTransform<A,B>
    • tryApply

      protected abstract B tryApply(A target) throws CachedTransform.ApplyException
      Checks whether a target can be transformed and transforms it.
      Parameters:
      target - the object to be matched against.
      Returns:
      a target for Unary.body to be matched against.
      Throws:
      CachedTransform.ApplyException - if the target can not be transformed.
    • apply

      public B apply(A target)
      Transforms a target to be matched into a target for the subpattern.

      This implementation returns the result cached by link Pattern#isApplicable()}. FIXME NOT FOUND SONAR-BT

      Specified by:
      apply in class Transform<A,B>
      Parameters:
      target - the target for this pattern to be matched against.
      Returns:
      a target for Unary.body to be matched against.
    • clear

      public void clear(boolean recursively)
      Description copied from class: Pattern
      Disposes of all internal state related to results and nondeterminism.

      The default implementation does nothing.

      Overrides:
      clear in class Unary<B,A>
      Parameters:
      recursively - true if all subpatterns should be deactivated, false otherwise.