org.eclipse.rse.services.clientserver
Class NamePatternMatcher
java.lang.Object
org.eclipse.rse.services.clientserver.NamePatternMatcher
-
All Implemented Interfaces:
-
IMatcher
-
public class NamePatternMatcher
- extends
Object
- implements
IMatcher
This class offers generic name pattern matching.
This supports one wildcard character ('*") anywhere in
the name, or one at the beginning and end of the name.
- ABC
- *
- ABC*
- *ABC
- AB*C
- *ABC*
This pattern matching class also optionally supports additional
advanced patterns beyond the stricter PDM style. These allow
for two '*'s anywhere in the name.
- AB*C*
- *A*C
- A*B*C
Quoted names are supported.
All matching is case-sensitive!
Instantiate this class for a given generic name, and then
call matches(String input) for each input name to see if it
matches the pattern.
To enable the advanced patterns, pass true
to the constructor.
Constructor Summary
|
NamePatternMatcher
(
String genericName)
Constructor for traditional-style only patterns, which allows
for one asterisk anywhere in the name,or one asterisk each at the
beginning or end of the name. |
NamePatternMatcher
(
String genericName,
boolean advanced,
boolean caseSensitive)
Constructor for traditional-style patterns PLUS advanced
patterns ABC*DEF* and A*C*F. |
Method Summary
|
int
|
getPatternType
()
What type of pattern is it? |
boolean
|
isGeneric
()
Was generic name given in the constructor a valid generic name (one or 2 '*'s)? |
boolean
|
isQuoted
()
Was quoted name given in the constructor a quoted name like "abcDEF"? |
boolean
|
isValid
()
Was generic name given in the constructor a valid scalar or generic name? |
boolean
|
matches
(
String input)
Test if a host name matches the pattern of this generic name. |
String
|
toString
()
For writing this object out. |
static boolean
|
verifyPattern
(
String genericName,
boolean advanced)
Static method to test if a given pattern is a valid generic name |
void
|
writeInfo
(
PrintWriter stream)
For debugging/testing purposes. |
WILDCARD
public static final char WILDCARD
- Wildcard character: *
-
See Also:
-
Constant Field Values
QUOTE
public static final char QUOTE
- Example: Quoted name delimiter: "
-
See Also:
-
Constant Field Values
SCALAR
public static final int SCALAR
- Example: ABC
-
See Also:
-
Constant Field Values
ALL
public static final int ALL
- Example: *
-
See Also:
-
Constant Field Values
WILDCARD_END
public static final int WILDCARD_END
- Example: ABC*
-
See Also:
-
Constant Field Values
WILDCARD_START
public static final int WILDCARD_START
- Example: *ABC
-
See Also:
-
Constant Field Values
WILDCARD_MIDDLE
public static final int WILDCARD_MIDDLE
- Example: A*C
-
See Also:
-
Constant Field Values
WILDCARD_START_END
public static final int WILDCARD_START_END
- Example: *ABC*
-
See Also:
-
Constant Field Values
WILDCARD_MIDDLE_END
public static final int WILDCARD_MIDDLE_END
-
See Also:
-
Constant Field Values
WILDCARD_START_MIDDLE
public static final int WILDCARD_START_MIDDLE
- Example: *A*F
-
See Also:
-
Constant Field Values
WILDCARD_MIDDLE_MIDDLE
public static final int WILDCARD_MIDDLE_MIDDLE
- Example: A*C*F
-
See Also:
-
Constant Field Values
NamePatternMatcher
public NamePatternMatcher(
String genericName)
- Constructor for traditional-style only patterns, which allows
for one asterisk anywhere in the name,or one asterisk each at the
beginning or end of the name.
If you don't know for sure the input is generic or valid, after
constructing call:
-
isValid()
to determine if given generic name was valid.
-
isGeneric()
to determine if given generic name had a wildcard.
If curious, you can also subsequently call:
-
getPatternType()
to determine which type of pattern the generic name follows.
Once constructed for a valid name, you can call
-
matches(String)
for each name to see if it matches this generic name pattern.
Quoted names are supported.
All matching is case-sensitive!
-
Parameters:
-
genericName
- generic name to do pattern matching for (ie, ABC*DEF)
NamePatternMatcher
public NamePatternMatcher(
String genericName,
boolean advanced,
boolean caseSensitive)
- Constructor for traditional-style patterns PLUS advanced
patterns ABC*DEF* and A*C*F.
If you don't know for sure the input is generic or valid, after
constructing call:
-
isValid()
to determine if given generic name was valid.
-
isGeneric()
to determine if given generic name had a wildcard.
If curious, you can also subsequently call:
-
getPatternType()
to determine which type of pattern the generic name follows.
Once constructed for a valid name, you can call
-
matches(String)
for each name to see if it matches this generic name pattern.
Quoted names are supported.
-
Parameters:
-
genericName
- generic name to do pattern matching for (ie, ABC*DEF) -
advanced
- true if you want to support the advanced patterns. -
caseSensitive
- true if the names are case-sensitive, false if case insensitive
matches
public boolean matches(
String input)
- Test if a host name matches the pattern of this generic name.
-
-
Specified by:
-
matches
in interface
IMatcher
-
-
Parameters:
-
input
- Scalar name like ABCDEF
-
Returns:
- true if given name matches this generic name pattern.
isValid
public boolean isValid()
- Was generic name given in the constructor a valid scalar or generic name?
-
-
-
Returns:
- true if name contained 0, 1 or 2 wildcards.
isGeneric
public boolean isGeneric()
- Was generic name given in the constructor a valid generic name (one or 2 '*'s)?
-
-
isQuoted
public boolean isQuoted()
- Was quoted name given in the constructor a quoted name like "abcDEF"?
-
-
getPatternType
public int getPatternType()
- What type of pattern is it? One of:
SCALAR
,
ALL
,
WILDCARD_END
,
WILDCARD_START
,
WILDCARD_MIDDLE
,
WILDCARD_START_END
, or
WILDCARD_MIDDLE_END
-
-
toString
public
String toString()
- For writing this object out.
Writes out the original generic name specified in the constructor.
-
-
Overrides:
-
toString
in class
Object
-
writeInfo
public void writeInfo(
PrintWriter stream)
- For debugging/testing purposes.
Writes out information about this generic name to the given stream file.
-
-
verifyPattern
public static boolean verifyPattern(
String genericName,
boolean advanced)
- Static method to test if a given pattern is a valid generic name
-
-
-
Parameters:
-
genericName
- pattern to test -
advanced
- true if advanced pattern allowed: ABC*DEF* and A*C*F
Copyright (c) IBM Corporation and others 2000, 2008. All Rights Reserved.