Class PatternElement

Object
com.owenfeehan.pathpatternfinder.patternelements.PatternElement
Direct Known Subclasses:
ResolvedPatternElement

public abstract class PatternElement
extends Object
Abstract base class for any pattern elements.

A PatternElement is one part of the pattern that is fitted against a list of strings/paths.

It can have a constant-value (identical value for all items in the list) or can have a varying value.

Author:
Owen Feehan
  • Constructor Details

  • Method Details

    • isResolved

      public abstract boolean isResolved()
      Can the element no longer be further broken down into smaller units?
      Returns:
      true iff this element cannot be broken down further into smaller units.
    • resolve

      public abstract Optional<Pattern> resolve()
      Converts this Pattern into smaller units.

      If isResolved()==true, this method should always return Optional.empty().

      Returns:
      a Pattern if successfully broken into smaller units, or Optional.empty() if this isn't possible
    • hasConstantValue

      public abstract boolean hasConstantValue()
      Does the element never vary?
      Returns:
      true iff this element have a constant value. Otherwise the element has multiple possible values. Iff true, describe(int) should return this constant value
    • equals

      public boolean equals​(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • reverse

      public abstract void reverse()
      Reverses the current element.

      i.e. if the string was previously applied from left to right it is now, right to left and vice-versa

    • reverseReturn

      public PatternElement reverseReturn()
      Reverses the pattern.
      Returns:
      the current element after being reversed
    • extractElementFrom

      public abstract Optional<ExtractedElement> extractElementFrom​(String str, IOCase ioCase)
      Extracts the element from the left-most side of a string.
      Parameters:
      str - the string to extract the element from
      ioCase - how to handle case-sensitivity
      Returns:
      Optional.empty() if element cannot be extracted, otherwise the string split into two components (extracted, and remainder)
    • describe

      public abstract String describe​(int widthToDescribe)
      Describe the element, summarized in a human-friendly way.
      Parameters:
      widthToDescribe - the maximum width that should be used to describe the pattern
      Returns:
      the constant-value if it exists, otherwise a descriptive string describing the variable-element
    • valueAt

      public abstract String valueAt​(int index)
      The value of the element for a particular string used during pattern extraction.

      When {hasConstantValue() is true, the index is irrelevant, as the same value will always be returned.

      The value exists when {isResolved() is true, and should only be called on elements in this state. Otherwise, an IllegalStateException will be thrown.

      Parameters:
      index - the index (zero-valued) of the corresponding string (as passed during pattern extraction to initialize elements) for which we wish to establish a value.
      Returns:
      the established value.
    • toString

      public String toString()
      Overrides:
      toString in class Object