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 Summary
Constructors Constructor Description PatternElement()
-
Method Summary
Modifier and Type Method Description abstract String
describe(int widthToDescribe)
Describe the element, summarized in a human-friendly way.boolean
equals(Object obj)
abstract Optional<ExtractedElement>
extractElementFrom(String str, IOCase ioCase)
Extracts the element from the left-most side of a string.abstract boolean
hasConstantValue()
Does the element never vary?int
hashCode()
abstract boolean
isResolved()
Can the element no longer be further broken down into smaller units?abstract Optional<Pattern>
resolve()
Converts thisPattern
into smaller units.abstract void
reverse()
Reverses the current element.PatternElement
reverseReturn()
Reverses the pattern.String
toString()
abstract String
valueAt(int index)
The value of the element for a particular string used during pattern extraction.
-
Constructor Details
-
PatternElement
public PatternElement()
-
-
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
Converts thisPattern
into smaller units.If isResolved()==true, this method should always return
Optional.empty()
.- Returns:
- a
Pattern
if successfully broken into smaller units, orOptional.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
-
hashCode
public int hashCode() -
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
Reverses the pattern.- Returns:
- the current element after being reversed
-
extractElementFrom
Extracts the element from the left-most side of a string.- Parameters:
str
- the string to extract the element fromioCase
- how to handle case-sensitivity- Returns:
Optional.empty()
if element cannot be extracted, otherwise the string split into two components (extracted, and remainder)
-
describe
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
The value of the element for a particular string used during pattern extraction.When {
hasConstantValue()
is true, theindex
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, anIllegalStateException
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
-