ICU-8167 add @draft ICU 4.8 to string trie APIs

X-SVN-Rev: 29530
This commit is contained in:
Markus Scherer 2011-03-03 21:53:40 +00:00
parent 4ff56e0dd5
commit 32ca14d226
4 changed files with 206 additions and 1 deletions

View File

@ -21,6 +21,8 @@ import java.util.NoSuchElementException;
*
* <p>This class is not intended for public subclassing.
*
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
* @author Markus W. Scherer
*/
public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
@ -37,6 +39,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
*
* @param trieBytes Bytes array that contains the serialized trie.
* @param offset Root offset of the trie in the array.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public BytesTrie(byte[] trieBytes, int offset) {
bytes_=trieBytes;
@ -48,6 +52,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* Clones this trie reader object and its state,
* but not the byte array which will be shared.
* @return A shallow clone of this trie.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -56,6 +62,9 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* Resets this trie to its initial state.
* @return this
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public BytesTrie reset() {
pos_=root_;
@ -66,8 +75,15 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* BytesTrie state object, for saving a trie's current state
* and resetting the trie back to this state later.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public static final class State {
/**
* Constructs an empty State.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public State() {}
private byte[] bytes;
private int root;
@ -77,7 +93,11 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* Saves the state of this trie.
* @param state The State object to hold the trie's state.
* @return this
* @see #resetToState
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public BytesTrie saveState(State state) /*const*/ {
state.bytes=bytes_;
@ -89,10 +109,14 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* Resets this trie to the saved state.
* @param state The State object which holds a saved trie state.
* @return this
* @throws IllegalArgumentException if the state object contains no state,
* or the state of a different trie
* @see #saveState
* @see #reset
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public BytesTrie resetToState(State state) {
if(bytes_==state.bytes && bytes_!=null && root_==state.root) {
@ -106,6 +130,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* Return values for BytesTrie.next(), CharsTrie.next() and similar methods.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public enum Result {
/**
@ -113,12 +139,16 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* Once current()/next() return NO_MATCH,
* all further calls to current()/next() will also return NO_MATCH,
* until the trie is reset to its original state or to a saved state.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
NO_MATCH,
/**
* The input unit(s) continued a matching string
* but there is no value for the string so far.
* (It is a prefix of a longer string.)
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
NO_VALUE,
/**
@ -126,6 +156,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* and there is a value for the string so far.
* This value will be returned by getValue().
* No further input byte/unit can continue a matching string.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
FINAL_VALUE,
/**
@ -133,6 +165,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* and there is a value for the string so far.
* This value will be returned by getValue().
* Another input byte/unit can continue a matching string.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
INTERMEDIATE_VALUE;
@ -143,6 +177,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* Same as (result!=NO_MATCH).
* @return true if the input bytes/units so far are part of a matching string/byte sequence.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public boolean matches() { return this!=NO_MATCH; }
@ -150,12 +186,16 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* Equivalent to (result==INTERMEDIATE_VALUE || result==FINAL_VALUE).
* @return true if there is a value for the input bytes/units so far.
* @see #getValue
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public boolean hasValue() { return ordinal()>=2; }
/**
* Equivalent to (result==NO_VALUE || result==INTERMEDIATE_VALUE).
* @return true if another input byte/unit can continue a matching string.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public boolean hasNext() { return (ordinal()&1)!=0; }
}
@ -164,6 +204,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* Determines whether the byte sequence so far matches, whether it has a value,
* and whether another input byte can continue a matching byte sequence.
* @return The match/value Result.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Result current() /*const*/ {
int pos=pos_;
@ -182,6 +224,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* @param inByte Input byte value. Values -0x100..-1 are treated like 0..0xff.
* Values below -0x100 and above 0xff will never match.
* @return The match/value Result.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Result first(int inByte) {
remainingMatchLength_=-1;
@ -196,6 +240,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* @param inByte Input byte value. Values -0x100..-1 are treated like 0..0xff.
* Values below -0x100 and above 0xff will never match.
* @return The match/value Result.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Result next(int inByte) {
int pos=pos_;
@ -232,7 +278,12 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* result=next(c);
* return result;
* </pre>
* @param s Contains a string or byte sequence.
* @param sIndex The start index of the byte sequence in s.
* @param sLimit The (exclusive) end index of the byte sequence in s.
* @return The match/value Result.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Result next(byte[] s, int sIndex, int sLimit) {
if(sIndex>=sLimit) {
@ -316,6 +367,9 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* getValue() can be called multiple times.
*
* Do not call getValue() after Result.NO_MATCH or Result.NO_VALUE!
* @return The value for the byte sequence so far.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public int getValue() /*const*/ {
int pos=pos_;
@ -330,6 +384,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* @return The unique value in bits 32..1 with bit 0 set,
* if all byte sequences reachable from the current state
* map to the same value; otherwise returns 0.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public long getUniqueValue() /*const*/ {
int pos=pos_;
@ -348,6 +404,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* @param out Each next byte is 0-extended to a char and appended to this object.
* (Only uses the out.append(c) method.)
* @return The number of bytes which continue the byte sequence from here.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public int getNextBytes(Appendable out) /*const*/ {
int pos=pos_;
@ -384,6 +442,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* Iterates from the current state of this trie.
* @return A new BytesTrie.Iterator.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Iterator iterator() {
return new Iterator(bytes_, pos_, remainingMatchLength_, 0);
@ -394,6 +454,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* @param maxStringLength If 0, the iterator returns full strings/byte sequences.
* Otherwise, the iterator returns strings with this maximum length.
* @return A new BytesTrie.Iterator.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Iterator iterator(int maxStringLength) {
return new Iterator(bytes_, pos_, remainingMatchLength_, maxStringLength);
@ -406,6 +468,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* @param maxStringLength If 0, the iterator returns full strings/byte sequences.
* Otherwise, the iterator returns strings with this maximum length.
* @return A new BytesTrie.Iterator.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public static Iterator iterator(byte[] trieBytes, int offset, int maxStringLength) {
return new Iterator(trieBytes, offset, -1, maxStringLength);
@ -413,21 +477,52 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* Return value type for the Iterator.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public static final class Entry {
private Entry(int capacity) {
bytes=new byte[capacity];
}
/**
* @return The length of the byte sequence.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public int bytesLength() { return length; }
/**
* Returns a byte of the byte sequence.
* @param index An index into the byte sequence.
* @return The index-th byte sequence byte.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public byte byteAt(int index) { return bytes[index]; }
/**
* Copies the byte sequence into a byte array.
* @param dest Destination byte array.
* @param destOffset Starting offset to where in dest the byte sequence is copied.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public void copyBytesTo(byte[] dest, int destOffset) {
System.arraycopy(bytes, 0, dest, destOffset, length);
}
/**
* @return The byte sequence as a read-only ByteBuffer.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public ByteBuffer bytesAsByteBuffer() {
return ByteBuffer.wrap(bytes, 0, length).asReadOnlyBuffer();
}
/**
* The value associated with the byte sequence.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public int value;
private void ensureCapacity(int len) {
@ -454,6 +549,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* Iterator for all of the (byte sequence, value) pairs in a BytesTrie.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public static final class Iterator implements java.util.Iterator<Entry> {
private Iterator(byte[] trieBytes, int offset, int remainingMatchLength, int maxStringLength) {
@ -477,6 +574,9 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* Resets this iterator to its initial state.
* @return this
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Iterator reset() {
pos_=initialPos_;
@ -494,6 +594,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* @return true if there are more elements.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public boolean hasNext() /*const*/ { return pos_>=0 || !stack_.isEmpty(); }
@ -506,6 +608,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
* a real value of -1.
* @return An Entry with the string and value of the next element.
* @throw NoSuchElementException - iteration has no more elements.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Entry next() {
int pos=pos_;
@ -574,6 +678,8 @@ public final class BytesTrie implements Cloneable, Iterable<BytesTrie.Entry> {
/**
* Iterator.remove() is not supported.
* @throws UnsupportedOperationException (always)
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public void remove() {
throw new UnsupportedOperationException();

View File

@ -17,11 +17,15 @@ import java.nio.ByteBuffer;
*
* <p>This class is not intended for public subclassing.
*
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
* @author Markus W. Scherer
*/
public final class BytesTrieBuilder extends StringTrieBuilder {
/**
* Constructs an empty builder.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public BytesTrieBuilder() {}
@ -48,6 +52,8 @@ public final class BytesTrieBuilder extends StringTrieBuilder {
* @param length The length of the byte sequence.
* @param value The value associated with this byte sequence.
* @return this
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public BytesTrieBuilder add(byte[] sequence, int length, int value) {
addImpl(new BytesAsCharSequence(sequence, length), value);
@ -64,6 +70,8 @@ public final class BytesTrieBuilder extends StringTrieBuilder {
* After clear() has been called, a new array will be used.
* @param buildOption Build option, see StringTrieBuilder.Option.
* @return A new BytesTrie for the add()ed data.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public BytesTrie build(StringTrieBuilder.Option buildOption) {
buildBytes(buildOption);
@ -84,6 +92,8 @@ public final class BytesTrieBuilder extends StringTrieBuilder {
* @param buildOption Build option, see StringTrieBuilder.Option.
* @return A ByteBuffer with the byte-serialized BytesTrie for the add()ed data.
* The buffer is not read-only and array() can be called.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public ByteBuffer buildByteBuffer(StringTrieBuilder.Option buildOption) {
buildBytes(buildOption);
@ -102,6 +112,8 @@ public final class BytesTrieBuilder extends StringTrieBuilder {
* Removes all (byte sequence, value) pairs.
* New data can then be add()ed and a new trie can be built.
* @return this
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public BytesTrieBuilder clear() {
clearImpl();

View File

@ -24,6 +24,8 @@ import com.ibm.icu.text.UTF16;
*
* <p>This class is not intended for public subclassing.
*
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
* @author Markus W. Scherer
*/
public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
@ -40,6 +42,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
*
* @param trieChars CharSequence that contains the serialized trie.
* @param offset Root offset of the trie in the CharSequence.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public CharsTrie(CharSequence trieChars, int offset) {
chars_=trieChars;
@ -51,6 +55,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* Clones this trie reader object and its state,
* but not the char array which will be shared.
* @return A shallow clone of this trie.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -59,6 +65,9 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
/**
* Resets this trie to its initial state.
* @return this
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public CharsTrie reset() {
pos_=root_;
@ -69,8 +78,15 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
/**
* CharsTrie state object, for saving a trie's current state
* and resetting the trie back to this state later.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public static final class State {
/**
* Constructs an empty State.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public State() {}
private CharSequence chars;
private int root;
@ -80,7 +96,11 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
/**
* Saves the state of this trie.
* @param state The State object to hold the trie's state.
* @return this
* @see #resetToState
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public CharsTrie saveState(State state) /*const*/ {
state.chars=chars_;
@ -92,10 +112,14 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
/**
* Resets this trie to the saved state.
* @param state The State object which holds a saved trie state.
* @return this
* @throws IllegalArgumentException if the state object contains no state,
* or the state of a different trie
* @see #saveState
* @see #reset
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public CharsTrie resetToState(State state) {
if(chars_==state.chars && chars_!=null && root_==state.root) {
@ -111,6 +135,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* Determines whether the string so far matches, whether it has a value,
* and whether another input char can continue a matching string.
* @return The match/value Result.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Result current() /*const*/ {
int pos=pos_;
@ -128,6 +154,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* Equivalent to reset().next(inUnit).
* @param inUnit Input char value. Values below 0 and above 0xffff will never match.
* @return The match/value Result.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Result first(int inUnit) {
remainingMatchLength_=-1;
@ -140,6 +168,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* Equivalent to reset().nextForCodePoint(cp).
* @param cp A Unicode code point 0..0x10ffff.
* @return The match/value Result.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Result firstForCodePoint(int cp) {
return cp<=0xffff ?
@ -153,6 +183,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* Traverses the trie from the current state for this input char.
* @param inUnit Input char value. Values below 0 and above 0xffff will never match.
* @return The match/value Result.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Result next(int inUnit) {
int pos=pos_;
@ -181,6 +213,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* one or two UTF-16 code units for this input code point.
* @param cp A Unicode code point 0..0x10ffff.
* @return The match/value Result.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Result nextForCodePoint(int cp) {
return cp<=0xffff ?
@ -200,7 +234,12 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* result=next(c);
* return result;
* </pre>
* @param s Contains a string.
* @param sIndex The start index of the string in s.
* @param sLimit The (exclusive) end index of the string in s.
* @return The match/value Result.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Result next(CharSequence s, int sIndex, int sLimit) {
if(sIndex>=sLimit) {
@ -284,6 +323,9 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* getValue() can be called multiple times.
*
* Do not call getValue() after Result.NO_MATCH or Result.NO_VALUE!
* @return The value for the string so far.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public int getValue() /*const*/ {
int pos=pos_;
@ -299,6 +341,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* @return The unique value in bits 32..1 with bit 0 set,
* if all strings reachable from the current state
* map to the same value; otherwise returns 0.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public long getUniqueValue() /*const*/ {
int pos=pos_;
@ -317,6 +361,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* @param out Each next char is appended to this object.
* (Only uses the out.append(c) method.)
* @return The number of chars which continue the string from here.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public int getNextChars(Appendable out) /*const*/ {
int pos=pos_;
@ -352,6 +398,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
/**
* Iterates from the current state of this trie.
* @return A new CharsTrie.Iterator.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Iterator iterator() {
return new Iterator(chars_, pos_, remainingMatchLength_, 0);
@ -362,6 +410,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* @param maxStringLength If 0, the iterator returns full strings.
* Otherwise, the iterator returns strings with this maximum length.
* @return A new CharsTrie.Iterator.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Iterator iterator(int maxStringLength) {
return new Iterator(chars_, pos_, remainingMatchLength_, maxStringLength);
@ -374,6 +424,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* @param maxStringLength If 0, the iterator returns full strings.
* Otherwise, the iterator returns strings with this maximum length.
* @return A new CharsTrie.Iterator.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public static Iterator iterator(CharSequence trieChars, int offset, int maxStringLength) {
return new Iterator(trieChars, offset, -1, maxStringLength);
@ -381,14 +433,28 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
/**
* Return value type for the Iterator.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public static final class Entry {
/**
* The string.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public CharSequence chars;
/**
* The value associated with the string.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public int value;
}
/**
* Iterator for all of the (string, value) pairs in a CharsTrie.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public static final class Iterator implements java.util.Iterator<Entry> {
private Iterator(CharSequence trieChars, int offset, int remainingMatchLength, int maxStringLength) {
@ -411,6 +477,9 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
/**
* Resets this iterator to its initial state.
* @return this
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Iterator reset() {
pos_=initialPos_;
@ -429,6 +498,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
/**
* @return true if there are more elements.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public boolean hasNext() /*const*/ { return pos_>=0 || !stack_.isEmpty(); }
@ -441,6 +512,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
* a real value of -1.
* @return An Entry with the string and value of the next element.
* @throw NoSuchElementException - iteration has no more elements.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public Entry next() {
int pos=pos_;
@ -525,6 +598,8 @@ public final class CharsTrie implements Cloneable, Iterable<CharsTrie.Entry> {
/**
* Iterator.remove() is not supported.
* @throws UnsupportedOperationException (always)
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public void remove() {
throw new UnsupportedOperationException();

View File

@ -17,11 +17,15 @@ import java.nio.CharBuffer;
*
* <p>This class is not intended for public subclassing.
*
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
* @author Markus W. Scherer
*/
public final class CharsTrieBuilder extends StringTrieBuilder {
/**
* Constructs an empty builder.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public CharsTrieBuilder() {}
@ -33,6 +37,8 @@ public final class CharsTrieBuilder extends StringTrieBuilder {
* @param s The input string.
* @param value The value associated with this char sequence.
* @return this
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public CharsTrieBuilder add(CharSequence s, int value) {
addImpl(s, value);
@ -48,6 +54,8 @@ public final class CharsTrieBuilder extends StringTrieBuilder {
* After clear() has been called, a new array will be used.
* @param buildOption Build option, see StringTrieBuilder.Option.
* @return A new CharsTrie for the add()ed data.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public CharsTrie build(StringTrieBuilder.Option buildOption) {
return new CharsTrie(buildCharSequence(buildOption), 0);
@ -62,13 +70,15 @@ public final class CharsTrieBuilder extends StringTrieBuilder {
* After clear() has been called, a new array will be used.
* @param buildOption Build option, see StringTrieBuilder.Option.
* @return A CharSequence with the char-serialized CharsTrie for the add()ed data.
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public CharSequence buildCharSequence(StringTrieBuilder.Option buildOption) {
buildChars(buildOption);
return CharBuffer.wrap(chars, chars.length-charsLength, charsLength);
}
public void buildChars(StringTrieBuilder.Option buildOption) {
private void buildChars(StringTrieBuilder.Option buildOption) {
// Create and char-serialize the trie for the elements.
if(chars==null) {
chars=new char[1024];
@ -80,6 +90,8 @@ public final class CharsTrieBuilder extends StringTrieBuilder {
* Removes all (string, value) pairs.
* New data can then be add()ed and a new trie can be built.
* @return this
* @draft ICU 4.8
* @provisional This API might change or be removed in a future release.
*/
public CharsTrieBuilder clear() {
clearImpl();