Package com.sshtools.daemon.util
Class StringPattern
- java.lang.Object
-
- com.sshtools.daemon.util.StringPattern
-
- All Implemented Interfaces:
java.io.Serializable
public class StringPattern extends java.lang.Object implements java.io.SerializableThis class provides services for checking strings against string-patterns. Currently it supports the wildcards
'' for any number of any character and
'?' for any one character. The API is very simple:
There are only the two class methods match() and matchIgnoreCase().
Example:
StringPattern.match( 'Hello World", "H W" ) ; --> evaluates to true
StringPattern.matchIgnoreCase( 'StringPattern", "str???pat" ) ; --> evaluates to true- Version:
- 1.7
- Author:
- Manfred Duchrow
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringMULTI_WILDCARDprotected static charMULTICHAR_WILDCARDprotected static charSINGLECHAR_WILDCARD
-
Constructor Summary
Constructors Constructor Description StringPattern(java.lang.String pattern)Initializes the new instance with the string pattern.StringPattern(java.lang.String pattern, boolean ignoreCase)Initializes the new instance with the string pattern and the selecteion, if case should be ignored when comparing characters.StringPattern(java.lang.String pattern, boolean ignoreCase, char digitWildcard)Initializes the new instance with the string pattern and the selecteion, if case should be ignored when comparing characters plus a wildcard character for digits.StringPattern(java.lang.String pattern, char digitWildcard)Initializes the new instance with the string pattern and a digit wildcard character.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancharsAreEqual(char probeChar, char patternChar)protected java.lang.CharacterdigitWildcard()protected voiddigitWildcard(java.lang.Character newValue)protected chardigitWildcardChar()protected booleanendNotReached(char character)protected booleanendReached(char character)booleangetIgnoreCase()Returns whether or not the pattern matching ignores upper and lower casejava.lang.StringgetPattern()Returns the pattern as string.protected chargetPatternChar(StringExaminer patternIterator, char probeCh)protected booleanhasDigitWildcard()booleanhasWildcard()Returns true if the pattern contains any '' or '?' wildcard character.static booleanmatch(java.lang.String probe, java.lang.String pattern)Returns true, if the given probe string matches the given pattern.booleanmatches(java.lang.String probe)Tests if a specified string matches the pattern.static booleanmatchIgnoreCase(java.lang.String probe, java.lang.String pattern)Returns true, if the given probe string matches the given pattern.protected booleanmatchReverse(java.lang.String pattern, StringExaminer probeIterator)protected StringExaminernewExaminer(java.lang.String str)voidsetDigitWildcardChar(char digitWildcard)Sets the given character as a wildcard character in this pattern to match only digits ('0'-'9').voidsetIgnoreCase(boolean newValue)Sets whether the pattern matching should ignore case or notvoidsetPattern(java.lang.String newValue)Sets the pattern to a new valueprotected booleanskipAfter(StringExaminer examiner, java.lang.String matchString)Increments the given iterator up to the last character that matched the character sequence in the given matchString.protected charskipWildcards(StringExaminer iterator)Moves the iterator position to the next character that is no wildcard.protected StringUtilstrUtil()java.lang.StringtoString()Returns the pattern string.protected java.lang.StringupToEnd(StringExaminer iterator)
-
-
-
Field Detail
-
MULTI_WILDCARD
protected static final java.lang.String MULTI_WILDCARD
- See Also:
- Constant Field Values
-
MULTICHAR_WILDCARD
protected static final char MULTICHAR_WILDCARD
- See Also:
- Constant Field Values
-
SINGLECHAR_WILDCARD
protected static final char SINGLECHAR_WILDCARD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
StringPattern
public StringPattern(java.lang.String pattern, boolean ignoreCase)Initializes the new instance with the string pattern and the selecteion, if case should be ignored when comparing characters.- Parameters:
pattern- The pattern to check against ( May contain '' and '?' wildcards )ignoreCase- Definition, if case sensitive character comparison or not.
-
StringPattern
public StringPattern(java.lang.String pattern)
Initializes the new instance with the string pattern. The default is case sensitive checking.- Parameters:
pattern- The pattern to check against ( May contain '' and '?' wildcards )
-
StringPattern
public StringPattern(java.lang.String pattern, char digitWildcard)Initializes the new instance with the string pattern and a digit wildcard character. The default is case sensitive checking.- Parameters:
pattern- The pattern to check against ( May contain '', '?' wildcards and the digit wildcard )digitWildcard- A wildcard character that stands as placeholder for digits
-
StringPattern
public StringPattern(java.lang.String pattern, boolean ignoreCase, char digitWildcard)Initializes the new instance with the string pattern and the selecteion, if case should be ignored when comparing characters plus a wildcard character for digits.- Parameters:
pattern- The pattern to check against ( May contain '' and '?' wildcards )ignoreCase- Definition, if case sensitive character comparison or not.digitWildcard- A wildcard character that stands as placeholder for digits
-
-
Method Detail
-
getIgnoreCase
public boolean getIgnoreCase()
Returns whether or not the pattern matching ignores upper and lower case- Returns:
-
setIgnoreCase
public void setIgnoreCase(boolean newValue)
Sets whether the pattern matching should ignore case or not- Parameters:
newValue-
-
getPattern
public java.lang.String getPattern()
Returns the pattern as string.- Returns:
-
setPattern
public void setPattern(java.lang.String newValue)
Sets the pattern to a new value- Parameters:
newValue-
-
digitWildcard
protected java.lang.Character digitWildcard()
- Returns:
-
digitWildcard
protected void digitWildcard(java.lang.Character newValue)
- Parameters:
newValue-
-
match
public static boolean match(java.lang.String probe, java.lang.String pattern)Returns true, if the given probe string matches the given pattern.
The character comparison is done case sensitive.- Parameters:
probe- The string to check against the pattern.pattern- The patter, that probably contains wildcards ( '' or '?' )- Returns:
-
matchIgnoreCase
public static boolean matchIgnoreCase(java.lang.String probe, java.lang.String pattern)Returns true, if the given probe string matches the given pattern.
The character comparison is done ignoring upper/lower-case.- Parameters:
probe- The string to check against the pattern.pattern- The patter, that probably contains wildcards ( '' or '?' )- Returns:
-
matches
public boolean matches(java.lang.String probe)
Tests if a specified string matches the pattern.- Parameters:
probe- The string to compare to the pattern- Returns:
- true if and only if the probe matches the pattern, false otherwise.
-
toString
public java.lang.String toString()
Returns the pattern string.- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-
hasWildcard
public boolean hasWildcard()
Returns true if the pattern contains any '' or '?' wildcard character.- Returns:
-
setDigitWildcardChar
public void setDigitWildcardChar(char digitWildcard)
Sets the given character as a wildcard character in this pattern to match only digits ('0'-'9').- Parameters:
digitWildcard- The placeholder character for digits
-
hasDigitWildcard
protected boolean hasDigitWildcard()
- Returns:
-
digitWildcardChar
protected char digitWildcardChar()
-
skipWildcards
protected char skipWildcards(StringExaminer iterator)
Moves the iterator position to the next character that is no wildcard. Doesn't skip digit wildcards !- Parameters:
iterator-- Returns:
-
skipAfter
protected boolean skipAfter(StringExaminer examiner, java.lang.String matchString)
Increments the given iterator up to the last character that matched the character sequence in the given matchString. Returns true, if the matchString was found, otherwise false.- Parameters:
examiner-matchString- The string to be found (must not contain )- Returns:
-
upToEnd
protected java.lang.String upToEnd(StringExaminer iterator)
-
matchReverse
protected boolean matchReverse(java.lang.String pattern, StringExaminer probeIterator)
-
charsAreEqual
protected boolean charsAreEqual(char probeChar, char patternChar)
-
endReached
protected boolean endReached(char character)
-
endNotReached
protected boolean endNotReached(char character)
-
getPatternChar
protected char getPatternChar(StringExaminer patternIterator, char probeCh)
-
newExaminer
protected StringExaminer newExaminer(java.lang.String str)
-
strUtil
protected StringUtil strUtil()
-
-