java.text
Class CharSet

java.lang.Object
  extended byjava.text.CharSet
All Implemented Interfaces:
Cloneable

class CharSet
extends Object
implements Cloneable

An object representing a set of characters. (This is a "set" in the mathematical sense: an unduplicated list of characters on which set operations such as union and intersection can be performed.) The set information is stored in compressed, optimized form: The object contains a String with an even number of characters. Each pair of characters represents a range of characters contained in the set (a pair of the same character represents a single character). The characters are sorted in increasing order.


Nested Class Summary
 class CharSet.Enumeration
          An Enumeration that can be used to extract the character ranges from a CharSet one at a time
 
Field Summary
private static String[][] categoryMap
          Table used with charSetFromCategory.
private  String chars
          The structure containing the set information.
private static Hashtable expressionCache
          A cache which is used to speed up parseString() whenever it is used to parse a description that has been parsed before
 
Constructor Summary
  CharSet()
          Creates an empty CharSet.
  CharSet(char c)
          Creates a CharSet containing a single character.
  CharSet(char lo, char hi)
          Creates a CharSet containing a range of characters.
private CharSet(String chars)
          Creates a CharSet, initializing it from the internal storage of another CharSet (this function performs no error checking on "chars", so if it's malformed, undefined behavior will result)
 
Method Summary
private static CharSet charSetForCategory(String category)
          Creates a CharSet containing all the characters in a particular Unicode category.
 Object clone()
          Creates a new CharSet that is equal to this one
 CharSet complement()
          Returns a CharSet containing all the characters which are not in "this"
 boolean contains(char c)
          Returns true if this CharSet contains the specified character
 CharSet difference(CharSet that)
          Returns a CharSet containing all the characters in "this" that aren't also in "that"
private  StringBuffer doComplement()
          The internal implementation function for the complement routines
private  StringBuffer doIntersection(String c2)
          The internal implementation of the two intersection functions
private static CharSet doParseString(String s)
          This function is used by parseString() to actually parse the string
private  StringBuffer doUnion(String c2)
          The actual implementation of the union functions
 boolean empty()
          Returns true if this CharSet contains no characters
 boolean equals(Object that)
          Returns true if "that" is another instance of CharSet containing the exact same characters as this one
 CharSet.Enumeration getChars()
          Returns an Enumeration that will return the ranges of characters contained in this CharSet one at a time
 String getRanges()
          Returns a String representing the contents of this CharSet in the same form in which they're stored internally: as pairs of characters representing the start and end points of ranges
private  void internalComplement()
          Complements "this".
private  void internalDifference(CharSet that)
          Removes from "this" all the characters that are also in "that"
private  void internalIntersection(CharSet that)
          Removes from this CharSet any characters that aren't also in "that"
private  void internalUnion(CharSet that)
          Adds the characters in "that" to this CharSet
 CharSet intersection(CharSet that)
          Returns the intersection of two CharSets.
static CharSet parseString(String s)
          Builds a CharSet based on a textual description.
static Hashtable releaseExpressionCache()
          Returns a copy of CharSet's expression cache and sets CharSet's expression cache to empty.
 String toString()
          Returns a textual representation of this CharSet.
 CharSet union(CharSet that)
          Returns a CharSet representing the union of two CharSets.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

chars

private String chars
The structure containing the set information. The characters in this string are organized into pairs, each pair representing a range of characters contained in the set


expressionCache

private static Hashtable expressionCache
A cache which is used to speed up parseString() whenever it is used to parse a description that has been parsed before


categoryMap

private static final String[][] categoryMap
Table used with charSetFromCategory. This is an array of pairs of Strings. The first column of Strings is Unicode character category codes as defined in the Unicode database. The second column is the internal storage for a CharSet containing the characters in that category.

Constructor Detail

CharSet

public CharSet()
Creates an empty CharSet.


CharSet

public CharSet(char c)
Creates a CharSet containing a single character.

Parameters:
c - The character to put into the CharSet

CharSet

public CharSet(char lo,
               char hi)
Creates a CharSet containing a range of characters.

Parameters:
lo - The lowest-numbered character to include in the range
hi - The highest-numbered character to include in the range

CharSet

private CharSet(String chars)
Creates a CharSet, initializing it from the internal storage of another CharSet (this function performs no error checking on "chars", so if it's malformed, undefined behavior will result)

Method Detail

parseString

public static CharSet parseString(String s)
Builds a CharSet based on a textual description. For the syntax of the description, see the documentation of RuleBasedBreakIterator.

See Also:
RuleBasedBreakIterator

doParseString

private static CharSet doParseString(String s)
This function is used by parseString() to actually parse the string


charSetForCategory

private static CharSet charSetForCategory(String category)
Creates a CharSet containing all the characters in a particular Unicode category. The text is either a two-character code from the Unicode database or a single character that begins one or more two-character codes.


releaseExpressionCache

public static Hashtable releaseExpressionCache()
Returns a copy of CharSet's expression cache and sets CharSet's expression cache to empty.


union

public CharSet union(CharSet that)
Returns a CharSet representing the union of two CharSets.


internalUnion

private void internalUnion(CharSet that)
Adds the characters in "that" to this CharSet


doUnion

private StringBuffer doUnion(String c2)
The actual implementation of the union functions


intersection

public CharSet intersection(CharSet that)
Returns the intersection of two CharSets.


internalIntersection

private void internalIntersection(CharSet that)
Removes from this CharSet any characters that aren't also in "that"


doIntersection

private StringBuffer doIntersection(String c2)
The internal implementation of the two intersection functions


difference

public CharSet difference(CharSet that)
Returns a CharSet containing all the characters in "this" that aren't also in "that"


internalDifference

private void internalDifference(CharSet that)
Removes from "this" all the characters that are also in "that"


complement

public CharSet complement()
Returns a CharSet containing all the characters which are not in "this"


internalComplement

private void internalComplement()
Complements "this". All the characters it contains are removed, and all the characters it doesn't contain are added.


doComplement

private StringBuffer doComplement()
The internal implementation function for the complement routines


contains

public boolean contains(char c)
Returns true if this CharSet contains the specified character

Parameters:
c - The character we're testing for set membership

equals

public boolean equals(Object that)
Returns true if "that" is another instance of CharSet containing the exact same characters as this one

Overrides:
equals in class Object
Parameters:
that - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
Object.hashCode(), Hashtable

clone

public Object clone()
Creates a new CharSet that is equal to this one

Overrides:
clone in class Object
Returns:
a clone of this instance.
See Also:
Cloneable

empty

public boolean empty()
Returns true if this CharSet contains no characters


toString

public String toString()
Returns a textual representation of this CharSet. If the result of calling this function is passed to CharSet.parseString(), it will produce another CharSet that is equal to this one.

Overrides:
toString in class Object
Returns:
a string representation of the object.

getRanges

public String getRanges()
Returns a String representing the contents of this CharSet in the same form in which they're stored internally: as pairs of characters representing the start and end points of ranges


getChars

public CharSet.Enumeration getChars()
Returns an Enumeration that will return the ranges of characters contained in this CharSet one at a time