|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectij.util.WildcardMatch
public class WildcardMatch
This class allows for simple wildcard pattern matching. Possible patterns allow to match single characters ('?') or any count of characters ('*').
Wildcard characters can be escaped (default: by an '\').
This class always matches for the whole word.
Examples:
WildcardMatch wm = new WildcardMatch();
System.out.println(wm.match("CfgOptions.class", "C*.class")); // true
System.out.println(wm.match("CfgOptions.class", "?gOpti*c?as?")); // false
System.out.println(wm.match("CfgOptions.class", "??gOpti*c?ass")); // true
System.out.println(wm.match("What's this?", "What\*\?")); // true
System.out.println(wm.match("What's this?", "What*?")); // true
System.out.println(wm.match("A \\ backslash", "\*\\\?back*")); // true
| Constructor Summary | |
|---|---|
WildcardMatch()
|
|
WildcardMatch(char singleChar,
char multipleChars)
|
|
| Method Summary | |
|---|---|
boolean |
getCaseSensitive()
Returns the current state of case sensitivity. |
char |
getEscapeChar()
Returns the character used to escape the wildcard functionality of a wildcard character. |
char |
getMultipleWildcardChar()
Returns the character used to specify any amount of characters. |
char |
getSingleWildcardChar()
Returns the character used to specify exactly one character. |
boolean |
match(String s,
String pattern)
Matches a string against a pattern with wildcards. |
void |
setCaseSensitive(boolean caseSensitive)
Makes pattern matching case insensitive. |
void |
setEscapeChar(char escapeChar)
Sets the new character to be used as an escape character, overriding the the default of '\'. |
void |
setWildcardChars(char singleChar,
char multipleChars)
Sets new characters to be used as wildcard characters, overriding the the default of '?' for any single character match and '*' for any amount of characters, including 0 characters. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WildcardMatch()
public WildcardMatch(char singleChar,
char multipleChars)
| Method Detail |
|---|
public void setWildcardChars(char singleChar,
char multipleChars)
singleChar - The char used to match exactly ONE character.multipleChars - The char used to match any amount of characters
including o characters.public void setEscapeChar(char escapeChar)
escapeChar - The char used to match escape wildcard characters.public char getSingleWildcardChar()
public char getMultipleWildcardChar()
public char getEscapeChar()
public void setCaseSensitive(boolean caseSensitive)
caseSensitive - false for case insensitivity. Default is case
sensitive match.public boolean getCaseSensitive()
public boolean match(String s,
String pattern)
s - The string, in which the search should be performed.pattern - The search pattern string including wildcards.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||