java.lang.Object | |
↳ | sun.text.normalizer.TrieIterator |
Class enabling iteration of the values in a Trie.
Result of each iteration contains the interval of codepoints that have the same value type and the value type itself.
The comparison of each codepoint value is done via extract(), which the default implementation is to return the value as it is.
Method extract() can be overwritten to perform manipulations on codepoint values in order to perform specialized comparison.
TrieIterator is designed to be a generic iterator for the CharTrie and the IntTrie, hence to accommodate both types of data, the return result will be in terms of int (32 bit) values.
See com.ibm.icu.text.UCharacterTypeIterator for examples of use.
Notes for porting utrie_enum from icu4c to icu4j:
Internally, icu4c's utrie_enum performs all iterations in its body. In Java
sense, the caller will have to pass a object with a callback function
UTrieEnumRange(const void *context, UChar32 start, UChar32 limit,
uint32_t value) into utrie_enum. utrie_enum will then find ranges of
codepoints with the same value as determined by
UTrieEnumValue(const void *context, uint32_t value). for each range,
utrie_enum calls the callback function to perform a task. In this way,
icu4c performs the iteration within utrie_enum.
To follow the JDK model, icu4j is slightly different from icu4c.
Instead of requesting the caller to implement an object for a callback.
The caller will have to implement a subclass of TrieIterator, fleshing out
the method extract(int) (equivalent to UTrieEnumValue). Independent of icu4j,
the caller will have to code his own iteration and flesh out the task
(equivalent to UTrieEnumRange) to be performed in the iteration loop.
There are basically 3 usage scenarios for porting:
1) UTrieEnumValue is the only implemented callback then just implement a subclass of TrieIterator and override the extract(int) method. The extract(int) method is analogus to UTrieEnumValue callback.
2) UTrieEnumValue and UTrieEnumRange both are implemented then implement a subclass of TrieIterator, override the extract method and iterate, e.g
utrie_enum(&normTrie, _enumPropertyStartsValue, _enumPropertyStartsRange,
set);
In Java :
class TrieIteratorImpl extends TrieIterator{ public TrieIteratorImpl(Trie data){ super(data); } public int extract(int value){ // port the implementation of _enumPropertyStartsValue here } } .... TrieIterator fcdIter = new TrieIteratorImpl(fcdTrieImpl.fcdTrie); while(fcdIter.next(result)) { // port the implementation of _enumPropertyStartsRange }
3) UTrieEnumRange is the only implemented callback then just implement the while loop, when utrie_enum is called
// utrie_enum(&fcdTrie, NULL, _enumPropertyStartsRange, set); TrieIterator fcdIter = new TrieIterator(fcdTrieImpl.fcdTrie); while(fcdIter.next(result)){ set.add(result.start); }
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
TrieEnumeration constructor
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns true if we are not at the end of the iteration, false otherwise. | |||||||||||
Resets the iterator to the beginning of the iteration
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Called by next() to extracts a 32 bit value from a trie value
used for comparison.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
TrieEnumeration constructor
trie | to be used |
---|
IllegalArgumentException | throw when argument is null. |
---|
Returns true if we are not at the end of the iteration, false otherwise.
The next set of codepoints with the same value type will be calculated during this call and returned in the arguement element.
element | return result |
---|
- if no more elements exist. |
Resets the iterator to the beginning of the iteration
Called by next() to extracts a 32 bit value from a trie value used for comparison. This method is to be overwritten if special manipulation is to be done to retrieve a relevant comparison. The default function is to return the value as it is.
value | a value from the trie |
---|