20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 /* 26 ******************************************************************************* 27 * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * 28 * * 29 * The original version of this source code and documentation is copyrighted * 30 * and owned by IBM, These materials are provided under terms of a License * 31 * Agreement between IBM and Sun. This technology is protected by multiple * 32 * US and International patents. This notice and attribution to IBM may not * 33 * to removed. * 34 ******************************************************************************* 35 */ 36 37 package sun.text.normalizer; 38 39 /** 40 * <p>Class enabling iteration of the values in a Trie.</p> 41 * <p>Result of each iteration contains the interval of codepoints that have 42 * the same value type and the value type itself.</p> 43 * <p>The comparison of each codepoint value is done via extract(), which the 44 * default implementation is to return the value as it is.</p> 45 * <p>Method extract() can be overwritten to perform manipulations on 46 * codepoint values in order to perform specialized comparison.</p> 47 * <p>TrieIterator is designed to be a generic iterator for the CharTrie 48 * and the IntTrie, hence to accommodate both types of data, the return 49 * result will be in terms of int (32 bit) values.</p> 50 * <p>See com.ibm.icu.text.UCharacterTypeIterator for examples of use.</p> 51 * <p>Notes for porting utrie_enum from icu4c to icu4j:<br> 52 * Internally, icu4c's utrie_enum performs all iterations in its body. In Java 53 * sense, the caller will have to pass a object with a callback function 54 * UTrieEnumRange(const void *context, UChar32 start, UChar32 limit, 55 * uint32_t value) into utrie_enum. utrie_enum will then find ranges of 56 * codepoints with the same value as determined by 57 * UTrieEnumValue(const void *context, uint32_t value). for each range, 58 * utrie_enum calls the callback function to perform a task. In this way, 59 * icu4c performs the iteration within utrie_enum. 60 * To follow the JDK model, icu4j is slightly different from icu4c. 61 * Instead of requesting the caller to implement an object for a callback. 62 * The caller will have to implement a subclass of TrieIterator, fleshing out 63 * the method extract(int) (equivalent to UTrieEnumValue). Independent of icu4j, 64 * the caller will have to code his own iteration and flesh out the task 65 * (equivalent to UTrieEnumRange) to be performed in the iteration loop. 66 * </p> 67 * <p>There are basically 3 usage scenarios for porting:</p> 68 * <p>1) UTrieEnumValue is the only implemented callback then just implement a 69 * subclass of TrieIterator and override the extract(int) method. The 70 * extract(int) method is analogus to UTrieEnumValue callback. 71 * </p> 72 * <p>2) UTrieEnumValue and UTrieEnumRange both are implemented then implement 73 * a subclass of TrieIterator, override the extract method and iterate, e.g 74 * </p> 75 * <p>utrie_enum(&normTrie, _enumPropertyStartsValue, _enumPropertyStartsRange, 76 * set);<br> 77 * In Java :<br> 78 * <pre> 79 * class TrieIteratorImpl extends TrieIterator{ 80 * public TrieIteratorImpl(Trie data){ 81 * super(data); 82 * } 83 * public int extract(int value){ 84 * // port the implementation of _enumPropertyStartsValue here 85 * } 86 * } 87 * .... 88 * TrieIterator fcdIter = new TrieIteratorImpl(fcdTrieImpl.fcdTrie); 89 * while(fcdIter.next(result)) { 90 * // port the implementation of _enumPropertyStartsRange 91 * } 92 * </pre> 93 * </p> 94 * <p>3) UTrieEnumRange is the only implemented callback then just implement 95 * the while loop, when utrie_enum is called 96 * <pre> 97 * // utrie_enum(&fcdTrie, NULL, _enumPropertyStartsRange, set); 98 * TrieIterator fcdIter = new TrieIterator(fcdTrieImpl.fcdTrie); 99 * while(fcdIter.next(result)){ 100 * set.add(result.start); 101 * } 102 * </pre> 103 * </p> 104 * @author synwee 105 * @see com.ibm.icu.impl.Trie 106 * @see com.ibm.icu.lang.UCharacterTypeIterator 107 * @since release 2.1, Jan 17 2002 108 */ 109 public class TrieIterator implements RangeValueIterator 110 { 111 112 // public constructor --------------------------------------------- 113 114 /** 115 * TrieEnumeration constructor 116 * @param trie to be used 117 * @exception IllegalArgumentException throw when argument is null. 118 */ 119 public TrieIterator(Trie trie) 120 { 121 if (trie == null) { 122 throw new IllegalArgumentException( 123 "Argument trie cannot be null"); | 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 /* 26 ******************************************************************************* 27 * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * 28 * * 29 * The original version of this source code and documentation is copyrighted * 30 * and owned by IBM, These materials are provided under terms of a License * 31 * Agreement between IBM and Sun. This technology is protected by multiple * 32 * US and International patents. This notice and attribution to IBM may not * 33 * to removed. * 34 ******************************************************************************* 35 */ 36 37 package sun.text.normalizer; 38 39 /** 40 * Class enabling iteration of the values in a Trie. 41 * <p>Result of each iteration contains the interval of codepoints that have 42 * the same value type and the value type itself. 43 * <p>The comparison of each codepoint value is done via extract(), which the 44 * default implementation is to return the value as it is. 45 * <p>Method extract() can be overwritten to perform manipulations on 46 * codepoint values in order to perform specialized comparison. 47 * <p>TrieIterator is designed to be a generic iterator for the CharTrie 48 * and the IntTrie, hence to accommodate both types of data, the return 49 * result will be in terms of int (32 bit) values. 50 * <p>See com.ibm.icu.text.UCharacterTypeIterator for examples of use. 51 * <p>Notes for porting utrie_enum from icu4c to icu4j:<br> 52 * Internally, icu4c's utrie_enum performs all iterations in its body. In Java 53 * sense, the caller will have to pass a object with a callback function 54 * UTrieEnumRange(const void *context, UChar32 start, UChar32 limit, 55 * uint32_t value) into utrie_enum. utrie_enum will then find ranges of 56 * codepoints with the same value as determined by 57 * UTrieEnumValue(const void *context, uint32_t value). for each range, 58 * utrie_enum calls the callback function to perform a task. In this way, 59 * icu4c performs the iteration within utrie_enum. 60 * To follow the JDK model, icu4j is slightly different from icu4c. 61 * Instead of requesting the caller to implement an object for a callback. 62 * The caller will have to implement a subclass of TrieIterator, fleshing out 63 * the method extract(int) (equivalent to UTrieEnumValue). Independent of icu4j, 64 * the caller will have to code his own iteration and flesh out the task 65 * (equivalent to UTrieEnumRange) to be performed in the iteration loop. 66 * 67 * <p>There are basically 3 usage scenarios for porting: 68 * <p>1) UTrieEnumValue is the only implemented callback then just implement a 69 * subclass of TrieIterator and override the extract(int) method. The 70 * extract(int) method is analogus to UTrieEnumValue callback. 71 * 72 * <p>2) UTrieEnumValue and UTrieEnumRange both are implemented then implement 73 * a subclass of TrieIterator, override the extract method and iterate, e.g.<br> 74 * {@code utrie_enum(&normTrie, _enumPropertyStartsValue, _enumPropertyStartsRange, 75 * set);}<br> 76 * In Java:<br> 77 * <pre> 78 * class TrieIteratorImpl extends TrieIterator{ 79 * public TrieIteratorImpl(Trie data){ 80 * super(data); 81 * } 82 * public int extract(int value){ 83 * // port the implementation of _enumPropertyStartsValue here 84 * } 85 * } 86 * .... 87 * TrieIterator fcdIter = new TrieIteratorImpl(fcdTrieImpl.fcdTrie); 88 * while(fcdIter.next(result)) { 89 * // port the implementation of _enumPropertyStartsRange 90 * } 91 * </pre> 92 * 93 * <p>3) UTrieEnumRange is the only implemented callback then just implement 94 * the while loop, when utrie_enum is called 95 * <pre>{@code 96 * // utrie_enum(&fcdTrie, NULL, _enumPropertyStartsRange, set); 97 * TrieIterator fcdIter = new TrieIterator(fcdTrieImpl.fcdTrie); 98 * while(fcdIter.next(result)){ 99 * set.add(result.start); 100 * } 101 * }</pre> 102 * 103 * @author synwee 104 * @see com.ibm.icu.impl.Trie 105 * @see com.ibm.icu.lang.UCharacterTypeIterator 106 * @since release 2.1, Jan 17 2002 107 */ 108 public class TrieIterator implements RangeValueIterator 109 { 110 111 // public constructor --------------------------------------------- 112 113 /** 114 * TrieEnumeration constructor 115 * @param trie to be used 116 * @exception IllegalArgumentException throw when argument is null. 117 */ 118 public TrieIterator(Trie trie) 119 { 120 if (trie == null) { 121 throw new IllegalArgumentException( 122 "Argument trie cannot be null"); |