org.apache.commons.lang.CharSet


 public class CharSet implements java.io.Serializable 

A set of characters. Instances are immutable, but instances of subclasses may not be.

Field Summary

 public static final CharSet EMPTY 

A CharSet defining no characters.

 public static final CharSet ASCII_ALPHA 

A CharSet defining ASCII alphabetic characters "a-zA-Z".

 public static final CharSet ASCII_ALPHA_LOWER 

A CharSet defining ASCII alphabetic characters "a-z".

 public static final CharSet ASCII_ALPHA_UPPER 

A CharSet defining ASCII alphabetic characters "A-Z".

 public static final CharSet ASCII_NUMERIC 

A CharSet defining ASCII alphabetic characters "0-9".

Method Detail

 public static CharSet getInstance(java.lang.String setStr) 

Factory method to create a new CharSet using a special syntax.

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

The matching order is:

  1. Negated multi character range, such as "^a-e"

  2. Ordinary multi character range, such as "a-e"

  3. Negated single character, such as "^a"

  4. 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: setStrthe String describing the set, may be null

Returns: a CharSet instance

 public CharRange[] getCharRanges() 

Gets the internal set as an array of CharRange objects.

Returns: an array of immutable CharRange objects

 public boolean contains(char ch) 

Does the CharSet contain the specified character ch.

Parameters: chthe character to check for

Returns: true if the set contains the characters

 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 abc and a-c are not equal according to this method.

Parameters: objthe object to compare to

Returns: true if equal

 public int hashCode() 

Gets a hashCode compatible with the equals method.

Returns: a suitable hashCode

 public java.lang.String toString() 

Gets a string representation of the set.

Returns: string representation of the set



    Apache Jakarta Commons(c) Reusable Java Components
    Real World Web Services
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 137
    Authors: Will Iverson

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net