Class Either<A>

Type Parameters:
A - the target type of objects to match against
All Implemented Interfaces:
Pattern<A>, Serializable, Cloneable

@Generated(generator="eu.bandm.tools.expander", version="", timestamp="2025-12-18T16:24:33") class Either<A> extends Binary<A,A,A>
Binary pattern disjunction.
  • Constructor Details

    • Either

      Either(Pattern<? super A> left, Pattern<? super A> right)
      Creates a new instance.
      Parameters:
      left - the left subpattern
      right - the right subpattern
      Throws:
      NullPointerException - if left or right is null
  • Method Details

    • 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().

      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).

      This implementation delegates to left and right if recursively is true.

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

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

      The default implementation returns false.

      Parameters:
      v - 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<?> v, boolean success)
      Checks whether a variable is preserved by this pattern, conditionally on success or failure.

      The default implementation returns false.

      Parameters:
      v - 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<?> v)
      Checks whether a variable is preserved by this pattern unconditionally.

      The default implementation returns false.

      Parameters:
      v - 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.

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

      protected String toStringOperator()
      Returns a human-readable operator symbol or name for this pattern.

      Subclasses should override this method to provide adequate information.

      The default implementation delegates to Object.toString().

      Overrides:
      toStringOperator in class Binary<A,A,A>
      Returns:
      a human-readable operator symbol or name for this pattern