primaryOrder
- Parameters:
order
- the collation element- Returns:
- the element's primary component
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:
And in German,"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').
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"äb" → the first key is key('a'), the second key is key('e'), and the third key is key('b').
primaryOrder
, secondaryOrder
, and
tertiaryOrder
return int
, short
,
and short
respectively to ensure the correctness of the key
value.
Example of the iterator usage,
String testString = "This is a test"; Collator col = Collator.getInstance(); if (col instanceof RuleBasedCollator) { RuleBasedCollator ruleBasedCollator = (RuleBasedCollator)col; CollationElementIterator collationElementIterator = ruleBasedCollator.getCollationElementIterator(testString); int primaryOrder = CollationElementIterator.primaryOrder(collationElementIterator.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.
Note: CollationElementIterator
is a part of
RuleBasedCollator
implementation. It is only usable
with RuleBasedCollator
instances.
Collator
,
RuleBasedCollator
static int
int
getMaxExpansion(int order)
int
int
next()
int
previous()
static int
primaryOrder(int order)
void
reset()
static short
secondaryOrder(int order)
void
setOffset(int newOffset)
void
void
setText(CharacterIterator source)
static short
tertiaryOrder(int order)
This iterator iterates over a sequence of collation elements that were built from the string. Because there isn't necessarily a one-to-one mapping from characters to collation elements, this doesn't mean the same thing as "return the collation element [or ordering priority] of the next character in the string".
This function returns the collation element that the iterator is currently pointing to and then updates the internal pointer to point to the next element. previous() updates the pointer first and then returns the element. This means that when you change direction while iterating (i.e., call next() and then call previous(), or call previous() and then call next()), you'll get back the same element twice.
This iterator iterates over a sequence of collation elements that were built from the string. Because there isn't necessarily a one-to-one mapping from characters to collation elements, this doesn't mean the same thing as "return the collation element [or ordering priority] of the previous character in the string".
This function updates the iterator's internal pointer to point to the collation element preceding the one it's currently pointing to and then returns that element, while next() returns the current element and then updates the pointer. This means that when you change direction while iterating (i.e., call next() and then call previous(), or call previous() and then call next()), you'll get back the same element twice.
order
- the collation elementorder
- the collation elementorder
- the collation elementnewOffset
- The new character offset into the original text.order
- a collation order returned by previous or next.source
- the new source textsource
- the new source text.