JavaTM 2 Platform
Standard Edition

java.text
Class CollationElementIterator

java.lang.Object
  |
  +--java.text.CollationElementIterator

public final class CollationElementIterator
extends Object

The CollationElementIterator class is used as an iterator to walk through each character of an international string. Use the iterator to return the ordering priority of the positioned character. The ordering priority of a character, which we refer to as a key, defines how a character is collated in the given collation object.

For example, consider the following in Spanish:

 "ca" -> the first key is key('c') and second key is key('a').
 "cha" -> the first key is key('ch') and second key is key('a').
 
And in German,
 "äb"-> the first key is key('a'), the second key is key('e'), and
 the third key is key('b').
 
The key of a character is an integer composed of primary order(short), secondary order(byte), and tertiary order(byte). Java strictly defines the size and signedness of its primitive data types. Therefore, the static functions primaryOrder, secondaryOrder, and tertiaryOrder return int, short, and short respectively to ensure the correctness of the key value.

Example of the iterator usage,

 // get the first key of the string
 String str = "This is a test";
 CollationElementIterator c =
     new CollationElementIterator(str, 0, str.length(),
                                  Collator.getInstance());
 int primaryOrder = CollationElementIterator.primaryOrder(c->next());
 

CollationElementIterator.next returns the collation order of the next character. A collation order consists of primary order, secondary order and tertiary order. The data type of the collation order is int. The first 16 bits of a collation order is its primary order; the next 8 bits is the secondary order and the last 8 bits is the tertiary order.

See Also:
Collator, RuleBasedCollator

Field Summary
static int NULLORDER
          Null order which indicates the end of string is reached by the cursor.
 
Method Summary
 int getMaxExpansion(int order)
          Return the maximum length of any expansion sequences that end with the specified comparison order.
 int getOffset()
          Gets the offset of the current character in the the source text.
 int next()
          Get the ordering priority of the next character in the string.
 int previous()
          Get the ordering priority of the previous collation element in the string.
static int primaryOrder(int order)
          Get the primary order of a collation order.
 void reset()
          Resets the cursor to the beginning of the string.
static short secondaryOrder(int order)
          Get the secondary order of a collation order.
 void setOffset(int newOffset)
          Sets the position within the source text.
 void setText(CharacterIterator source)
          Set a new string over which to iterate.
 void setText(String source)
          Set a new string over which to iterate.
static short tertiaryOrder(int order)
          Get the tertiary order of a collation order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULLORDER

public static final int NULLORDER
Null order which indicates the end of string is reached by the cursor.
Method Detail

reset

public void reset()
Resets the cursor to the beginning of the string.

next

public int next()
Get the ordering priority of the next character in the string.
Returns:
the next character's ordering. Returns NULLORDER if the end of string is reached.

previous

public int previous()
Get the ordering priority of the previous collation element in the string.
Returns:
the previous element's ordering. Returns NULLORDER if the beginning of string is reached.

primaryOrder

public static final int primaryOrder(int order)
Get the primary order of a collation order.
Parameters:
order - the collation order
Returns:
the primary order of a collation order.

secondaryOrder

public static final short secondaryOrder(int order)
Get the secondary order of a collation order.
Parameters:
order - the collation order
Returns:
the secondary order of a collation order.

tertiaryOrder

public static final short tertiaryOrder(int order)
Get the tertiary order of a collation order.
Parameters:
order - the collation order
Returns:
the tertiary order of a collation order.

setOffset

public void setOffset(int newOffset)
Sets the position within the source text.
Parameters:
newOffset - The new offset relative to the start of the text.

getOffset

public int getOffset()
Gets the offset of the current character in the the source text. That is, the next call to next() will return the Collation element for this character (possibly including more than one character, if required by the language).
Returns:
the returned ofset.

getMaxExpansion

public int getMaxExpansion(int order)
Return the maximum length of any expansion sequences that end with the specified comparison order.
Parameters:
order - a collation order returned by previous or next.
Returns:
the maximum length of any expansion sequences ending with the specified order.

setText

public void setText(String source)
Set a new string over which to iterate.
Parameters:
str - the new source text.

setText

public void setText(CharacterIterator source)
Set a new string over which to iterate.
Parameters:
str - the new source text.

JavaTM 2 Platform
Standard Edition

Submit a bug or feature
Java, Java 2D, and JDBC are a trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.