Class Search<A>

java.lang.Object
eu.bandm.tools.paisley.Pattern<A>
eu.bandm.tools.paisley.Search<A>
Type Parameters:
A - the target type.
All Implemented Interfaces:
Serializable, Cloneable

public abstract class Search<A> extends Pattern<A>
Abstract base class for patterns that delegate matching dynamically to a number of alternative subpatterns.

Subclasses must implement the initAlternatives(A) and nextAlternative() methods.

See Also:
  • Field Details

    • alt

      protected Pattern<? super A> alt
      The current alternative.
    • arg

      protected A arg
      The target for the current alternative.
  • Constructor Details

    • Search

      public Search()
  • Method Details

    • initAlternatives

      protected abstract void initAlternatives(A target)
      Sets up the dynamic enumeration of alternatives for a target.
      Parameters:
      target - the object to be matched against.
    • nextAlternative

      protected abstract boolean nextAlternative()
      Enumerates an alternative. Must be called only after initAlternatives(A).

      If an alternative is found, alt and arg must be set to non-null values accordingly.

      Returns:
      true if an(other) alternative has been found; false otherwise.
    • 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.

      This implementation uses initAlternatives(A) and nextAlternative() to find the first matching alternative for the target, and succeeds if one is found. Alternative matching is done by alt.match(arg).

      Specified by:
      match in class Pattern<A>
      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().

      This implementation first tries to match the last m,atching alternative again. On failure it uses nextAlternative() to find the next matching alternative for the target, and succeeds if one is found. Alternative matching is done by alt.match(arg).

      Overrides:
      matchAgain in class Pattern<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:
    • isDeterministic

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

      The default implementation returns true.

      This implementation returns false.

      Overrides:
      isDeterministic in class Pattern<A>
      Returns:
      true if this pattern is guaranteed to match any object at most once, false otherwise.
      See Also: