Class CharSet
- java.lang.Object
 - 
- org.apache.commons.lang.CharSet
 
 
- 
- All Implemented Interfaces:
 java.io.Serializable
public class CharSet extends java.lang.Object implements java.io.SerializableA set of characters.
Instances are immutable, but instances of subclasses may not be.
#ThreadSafe#
- Since:
 - 1.0
 - See Also:
 - Serialized Form
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description static CharSetASCII_ALPHAA CharSet defining ASCII alphabetic characters "a-zA-Z".static CharSetASCII_ALPHA_LOWERA CharSet defining ASCII alphabetic characters "a-z".static CharSetASCII_ALPHA_UPPERA CharSet defining ASCII alphabetic characters "A-Z".static CharSetASCII_NUMERICA CharSet defining ASCII alphabetic characters "0-9".static CharSetEMPTYA CharSet defining no characters. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(char ch)Does theCharSetcontain the specified characterch.booleanequals(java.lang.Object obj)Compares two CharSet objects, returning true if they represent exactly the same set of characters defined in the same way.CharRange[]getCharRanges()Gets the internal set as an array of CharRange objects.static CharSetgetInstance(java.lang.String setStr)Factory method to create a new CharSet using a special syntax.static CharSetgetInstance(java.lang.String[] setStrs)Constructs a new CharSet using the set syntax.inthashCode()Gets a hashCode compatible with the equals method.java.lang.StringtoString()Gets a string representation of the set. 
 - 
 
- 
- 
Field Detail
- 
EMPTY
public static final CharSet EMPTY
A CharSet defining no characters.- Since:
 - 2.0
 
 
- 
ASCII_ALPHA
public static final CharSet ASCII_ALPHA
A CharSet defining ASCII alphabetic characters "a-zA-Z".- Since:
 - 2.0
 
 
- 
ASCII_ALPHA_LOWER
public static final CharSet ASCII_ALPHA_LOWER
A CharSet defining ASCII alphabetic characters "a-z".- Since:
 - 2.0
 
 
- 
ASCII_ALPHA_UPPER
public static final CharSet ASCII_ALPHA_UPPER
A CharSet defining ASCII alphabetic characters "A-Z".- Since:
 - 2.0
 
 
- 
ASCII_NUMERIC
public static final CharSet ASCII_NUMERIC
A CharSet defining ASCII alphabetic characters "0-9".- Since:
 - 2.0
 
 
 - 
 
- 
Method Detail
- 
getInstance
public static CharSet getInstance(java.lang.String setStr)
Factory method to create a new CharSet using a special syntax.
nullor 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
 
The matching order is:
- 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"
 
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.
- Parameters:
 setStr- the String describing the set, may be null- Returns:
 - a CharSet instance
 - Since:
 - 2.0
 
 
- 
getInstance
public static CharSet getInstance(java.lang.String[] setStrs)
Constructs a new CharSet using the set syntax. Each string is merged in with the set.
- Parameters:
 setStrs- Strings to merge into the initial set, may be null- Returns:
 - a CharSet instance
 - Since:
 - 2.4
 
 
- 
getCharRanges
public CharRange[] getCharRanges()
Gets the internal set as an array of CharRange objects.
- Returns:
 - an array of immutable CharRange objects
 - Since:
 - 2.0
 
 
- 
contains
public boolean contains(char ch)
Does the
CharSetcontain the specified characterch.- Parameters:
 ch- the character to check for- Returns:
 trueif the set contains the characters
 
- 
equals
public boolean equals(java.lang.Object obj)
Compares two CharSet objects, returning true if they represent exactly the same set of characters defined in the same way.
The two sets
abcanda-care not equal according to this method.- Overrides:
 equalsin classjava.lang.Object- Parameters:
 obj- the object to compare to- Returns:
 - true if equal
 - Since:
 - 2.0
 
 
- 
hashCode
public int hashCode()
Gets a hashCode compatible with the equals method.
- Overrides:
 hashCodein classjava.lang.Object- Returns:
 - a suitable hashCode
 - Since:
 - 2.0
 
 
- 
toString
public java.lang.String toString()
Gets a string representation of the set.
- Overrides:
 toStringin classjava.lang.Object- Returns:
 - string representation of the set
 
 
 - 
 
 -