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 Stringdescribe(int widthToDescribe)Describe the element, summarized in a human-friendly way.booleanequals(Object obj)abstract Optional<ExtractedElement>extractElementFrom(String str, IOCase ioCase)Extracts the element from the left-most side of a string.abstract booleanhasConstantValue()Does the element never vary?inthashCode()abstract booleanisResolved()Can the element no longer be further broken down into smaller units?abstract Optional<Pattern>resolve()Converts thisPatterninto smaller units.abstract voidreverse()Reverses the current element.PatternElementreverseReturn()Reverses the pattern.StringtoString()abstract StringvalueAt(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 thisPatterninto smaller units.If isResolved()==true, this method should always return
Optional.empty().- Returns:
- a
Patternif 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, theindexis 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, anIllegalStateExceptionwill 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
-