Class Unary<A,B>

java.lang.Object
eu.bandm.tools.paisley.AbstractPattern<B>
eu.bandm.tools.paisley.Unary<A,B>
Type Parameters:
A - the target type of the contained subpattern
B - the target type of the containing pattern
All Implemented Interfaces:
Pattern<B>, Serializable, Cloneable
Direct Known Subclasses:
FlatMultiTransform, Proxy, Transform

@Generated(generator="eu.bandm.tools.expander", version="", timestamp="2026-01-24T11:39:10") public abstract class Unary<A,B> extends AbstractPattern<B>
Abstract base class for patterns that contain one subpattern. Methods have default implementations that delegate to the subpattern.

Subclasses must implement the Pattern.match(A) method.

See Also:
  • Constructor Details

    • Unary

      protected Unary(Pattern<? super A> body)
      Creates a new instance.
      Parameters:
      body - the subpattern
      Throws:
      NullPointerException - if body is null
    • Unary

      protected Unary()
      Creates a new instance without subpattern.

      This constructor is for lazy initialization; the method setBody(eu.bandm.tools.paisley.Pattern<A>) must be called before this pattern is usable.

  • Method Details

    • getBody

      @Opt public @Opt Pattern<A> getBody()
      Returns the contained subpattern.
      Returns:
      the contained subpattern, or null if not set
    • setBody

      protected void setBody(Pattern<A> body)
      Sets the uninitialized body subpattern.
      Parameters:
      body - the body subpattern
      Throws:
      NullPointerException - if body is null
      IllegalStateException - if the body subpattern has been initialized before, either by a constructor or by this method.
    • fork

      public Pattern<B> fork()
      Description copied from class: AbstractPattern
      Makes a copy of this pattern with independent internal state.

      Subclasses must override this method if necessary to honour the following rules for all transitively reachable patterns:

      • Subpatterns that are instances of Variable must be shared. This implies that Variable.fork() must return this.
      • Fields that do not refer to subpatterns, but to matching state (changed by invocations of Pattern.match(A), Pattern.matchAgain(), Pattern.cut() or Pattern.clear()) must be duplicated. If matching state changes are effected by modification of other objects, these must be duplicated. In summary, matching operations on this pattern and its copy must not interfere, with the exception of variable bindings.
      • Fields neither referring to subpatterns nor to matching state may be either shared or duplicated. The usage of such fields in a modifiable way (such that the distinction is relevant) is strongly deprecated.
      • Patterns whose fields need not be duplicated need not be duplicated themselves, but may return this.
      Specified by:
      fork in interface Pattern<A>
      Overrides:
      fork in class AbstractPattern<B>
      Returns:
      a copy of this pattern that has independent internal state, except for variables
    • 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 body.

      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:
    • cut

      public 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 of cut(false). The default implementation delegates to body if recursively is true.

      Parameters:
      recursively - true if all subpatterns should traversed, false otherwise.
    • clear

      public void clear(boolean recursively)
      Disposes of all temporary internal state related to results and nondeterminism.

      The default implementation just invokes cut(false). Subclasses that override this method should either invoke this overridden implementation, or ensure by other means that the effect of cut(false) is implied. The default implementation invokes cut(false), and delegates to body if recursively is true.

      Parameters:
      recursively - true if all subpatterns should be traversed, false otherwise.
    • binds

      public boolean binds(Variable<?> variable)
      Checks whether a variable is bound by this pattern.

      The default implementation returns false.

      This implementation delegates to body.

      Parameters:
      variable - a pattern variable
      Returns:
      true if the variable is guaranteed to have a meaningful value when this pattern is open, false otherwise.
    • preserves

      public boolean preserves(Variable<?> variable, boolean success)
      Checks whether a variable is preserved by this pattern, conditionally on success or failure.

      The default implementation returns false.

      This implementation delegates to body.

      Parameters:
      variable - a pattern variable
      success - specifies preservation on success or failure
      Returns:
      true if the variable value is guaranteed to be unaffected by a matching attempt with this pattern that returns a value equal to success.
    • preserves

      public boolean preserves(Variable<?> variable)
      Checks whether a variable is preserved by this pattern unconditionally.

      The default implementation returns false.

      This implementation delegates to body.

      Parameters:
      variable - a pattern variable
      Returns:
      true if the variable value is guaranteed to be unaffected by any matching attempt with this pattern.
    • isDeterministic

      public boolean isDeterministic()
      Checks whether this pattern is deterministic.

      The default implementation returns false. This implementation delegates to body.

      Returns:
      true if this pattern is guaranteed to match any object at most once, false otherwise.
      See Also: