public final class CharsTrie extends Object implements Cloneable, Iterable<CharsTrie.Entry>
This class is not intended for public subclassing.
Modifier and Type | Class and Description |
---|---|
static class |
CharsTrie.Entry
Return value type for the Iterator.
|
static class |
CharsTrie.Iterator
Iterator for all of the (string, value) pairs in a CharsTrie.
|
static class |
CharsTrie.State
CharsTrie state object, for saving a trie's current state
and resetting the trie back to this state later.
|
Constructor and Description |
---|
CharsTrie(CharSequence trieChars,
int offset)
Constructs a CharsTrie reader instance.
|
CharsTrie(CharsTrie other)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
CharsTrie |
clone()
Clones this trie reader object and its state,
but not the char array which will be shared.
|
BytesTrie.Result |
current()
Determines whether the string so far matches, whether it has a value,
and whether another input char can continue a matching string.
|
BytesTrie.Result |
first(int inUnit)
Traverses the trie from the initial state for this input char.
|
BytesTrie.Result |
firstForCodePoint(int cp)
Traverses the trie from the initial state for the
one or two UTF-16 code units for this input code point.
|
int |
getNextChars(Appendable out)
Finds each char which continues the string from the current state.
|
long |
getState64()
Returns the state of this trie as a 64-bit integer.
|
long |
getUniqueValue()
Determines whether all strings reachable from the current state
map to the same value, and if so, returns that value.
|
int |
getValue()
Returns a matching string's value if called immediately after
current()/first()/next() returned Result.INTERMEDIATE_VALUE or Result.FINAL_VALUE.
|
CharsTrie.Iterator |
iterator()
Iterates from the current state of this trie.
|
static CharsTrie.Iterator |
iterator(CharSequence trieChars,
int offset,
int maxStringLength)
Iterates from the root of a char-serialized BytesTrie.
|
CharsTrie.Iterator |
iterator(int maxStringLength)
Iterates from the current state of this trie.
|
BytesTrie.Result |
next(CharSequence s,
int sIndex,
int sLimit)
Traverses the trie from the current state for this string.
|
BytesTrie.Result |
next(int inUnit)
Traverses the trie from the current state for this input char.
|
BytesTrie.Result |
nextForCodePoint(int cp)
Traverses the trie from the current state for the
one or two UTF-16 code units for this input code point.
|
CharsTrie |
reset()
Resets this trie to its initial state.
|
CharsTrie |
resetToState(CharsTrie.State state)
Resets this trie to the saved state.
|
CharsTrie |
resetToState64(long state)
Resets this trie to the saved state.
|
CharsTrie |
saveState(CharsTrie.State state)
Saves the state of this trie.
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public CharsTrie(CharSequence trieChars, int offset)
The CharSequence must contain a copy of a char sequence from the CharsTrieBuilder, with the offset indicating the first char of that sequence. The CharsTrie object will not read more chars than the CharsTrieBuilder generated in the corresponding build() call.
The CharSequence is not copied/cloned and must not be modified while the CharsTrie object is in use.
trieChars
- CharSequence that contains the serialized trie.offset
- Root offset of the trie in the CharSequence.public CharsTrie(CharsTrie other)
public CharsTrie clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public CharsTrie reset()
public long getState64()
resetToState64(long)
public CharsTrie resetToState64(long state)
resetToState(State)
, the 64-bit state value
must be from getState64()
from the same trie object or
from one initialized the exact same way.
Because of no validation, this method is faster.state
- The opaque trie state value from getState64().getState64()
,
resetToState(com.ibm.icu.util.CharsTrie.State)
,
reset()
public CharsTrie saveState(CharsTrie.State state)
state
- The State object to hold the trie's state.resetToState(com.ibm.icu.util.CharsTrie.State)
public CharsTrie resetToState(CharsTrie.State state)
resetToState64(long)
which does not validate the state value.state
- The State object which holds a saved trie state.IllegalArgumentException
- if the state object contains no state,
or the state of a different triesaveState(com.ibm.icu.util.CharsTrie.State)
,
reset()
public BytesTrie.Result current()
public BytesTrie.Result first(int inUnit)
inUnit
- Input char value. Values below 0 and above 0xffff will never match.public BytesTrie.Result firstForCodePoint(int cp)
cp
- A Unicode code point 0..0x10ffff.public BytesTrie.Result next(int inUnit)
inUnit
- Input char value. Values below 0 and above 0xffff will never match.public BytesTrie.Result nextForCodePoint(int cp)
cp
- A Unicode code point 0..0x10ffff.public BytesTrie.Result next(CharSequence s, int sIndex, int sLimit)
Result result=current(); for(each c in s) if(!result.hasNext()) return Result.NO_MATCH; result=next(c); return result;
s
- Contains a string.sIndex
- The start index of the string in s.sLimit
- The (exclusive) end index of the string in s.public int getValue()
public long getUniqueValue()
public int getNextChars(Appendable out)
out
- Each next char is appended to this object.
(Only uses the out.append(c) method.)public CharsTrie.Iterator iterator()
iterator
in interface Iterable<CharsTrie.Entry>
public CharsTrie.Iterator iterator(int maxStringLength)
maxStringLength
- If 0, the iterator returns full strings.
Otherwise, the iterator returns strings with this maximum length.public static CharsTrie.Iterator iterator(CharSequence trieChars, int offset, int maxStringLength)
trieChars
- CharSequence that contains the serialized trie.offset
- Root offset of the trie in the CharSequence.maxStringLength
- If 0, the iterator returns full strings.
Otherwise, the iterator returns strings with this maximum length.Copyright © 2016 Unicode, Inc. and others.