Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.commons.lang.CharSet
Field Summary | |
static CharSet |
|
static CharSet |
|
static CharSet |
|
static CharSet |
|
protected static Map |
|
static CharSet |
|
Constructor Summary | |
| |
|
Method Summary | |
protected void |
|
boolean |
|
boolean |
|
CharRange[] |
|
static CharSet |
|
int |
|
String |
|
public static final CharSet ASCII_ALPHA
A CharSet defining ASCII alphabetic characters "a-zA-Z".
- Since:
- 2.0
public static final CharSet ASCII_ALPHA_LOWER
A CharSet defining ASCII alphabetic characters "a-z".
- Since:
- 2.0
public static final CharSet ASCII_ALPHA_UPPER
A CharSet defining ASCII alphabetic characters "A-Z".
- Since:
- 2.0
public static final CharSet ASCII_NUMERIC
A CharSet defining ASCII alphabetic characters "0-9".
- Since:
- 2.0
protected static final Map COMMON
A Map of the common cases used in the factory. Subclasses can add more common patterns if desired.
- Since:
- 2.0
protected CharSet(String setStr)
Constructs a new CharSet using the set syntax.
- Parameters:
setStr
- the String describing the set, may be null
- Since:
- 2.0
protected CharSet(String[] set)
Constructs a new CharSet using the set syntax. Each string is merged in with the set.
- Parameters:
set
- Strings to merge into the initial set
protected void add(String str)
Add a set definition string to theCharSet
.
- Parameters:
str
- set definition string
public boolean contains(char ch)
Does theCharSet
contain the specified characterch
.
- Parameters:
ch
- the character to check for
- Returns:
true
if the set contains the characters
public boolean equals(Object obj)
Compares two CharSet objects, returning true if they represent exactly the same set of characters defined in the same way. The two setsabc
anda-c
are not equal according to this method.
- Parameters:
obj
- the object to compare to
- Returns:
- true if equal
- Since:
- 2.0
public CharRange[] getCharRanges()
Gets the internal set as an array of CharRange objects.
- Returns:
- an array of immutable CharRange objects
- Since:
- 2.0
public static CharSet getInstance(String setStr)
Factory method to create a new CharSet using a special syntax.The matching order is:
null
or empty string ("") - set containing no characters- Single character, such as "a" - set containing just that character
- Multi character, such as "a-e" - set containing characters from one character to the other
- Negated, such as "^a" or "^a-e" - set containing all characters except those defined
- Combinations, such as "abe-g" - set containing all the characters from the individual sets
Matching works left to right. Once a match is found the search starts again from the next character. If the same range is defined twice using the same syntax, only one range will be kept. Thus, "a-ca-c" creates only one range of "a-c". If the start and end of a range are in the wrong order, they are reversed. Thus "a-e" is the same as "e-a". As a result, "a-ee-a" would create only one range, as the "a-e" and "e-a" are the same. The set of characters represented is the union of the specified ranges. All CharSet objects returned by this method will be immutable.
- Negated multi character range, such as "^a-e"
- Ordinary multi character range, such as "a-e"
- Negated single character, such as "^a"
- Ordinary single character, such as "a"
- Parameters:
setStr
- the String describing the set, may be null
- Returns:
- a CharSet instance
- Since:
- 2.0
public int hashCode()
Gets a hashCode compatible with the equals method.
- Returns:
- a suitable hashCode
- Since:
- 2.0
public String toString()
Gets a string representation of the set.
- Returns:
- string representation of the set