remainingMatchLength_=-1;
}
+ /**
+ * Copy constructor.
+ * Makes a shallow copy of the other trie reader object and its state.
+ * Does not copy the byte array which will be shared.
+ * Same as clone() but without the throws clause.
+ *
+ * @draft ICU 64
+ * @provisional This API might change or be removed in a future release.
+ */
+ public BytesTrie(BytesTrie other) {
+ bytes_ = other.bytes_;
+ root_ = other.root_;
+ pos_ = other.pos_;
+ remainingMatchLength_ = other.remainingMatchLength_;
+ }
+
/**
* Clones this trie reader object and its state,
* but not the byte array which will be shared.
* @stable ICU 4.8
*/
@Override
- public Object clone() throws CloneNotSupportedException {
- return super.clone(); // A shallow copy is just what we need.
+ public BytesTrie clone() throws CloneNotSupportedException {
+ return (BytesTrie) super.clone(); // A shallow copy is just what we need.
}
/**
// and the remaining branch length in bits 24..16. (Bits 31..25 are unused.)
// (We could store the remaining branch length minus 1 in bits 23..16 and not use bits 31..24,
// but the code looks more confusing that way.)
- private ArrayList<Long> stack_=new ArrayList<Long>();
+ private ArrayList<Long> stack_=new ArrayList<>();
}
private void stop() {
remainingMatchLength_=-1;
}
+ /**
+ * Copy constructor.
+ * Makes a shallow copy of the other trie reader object and its state.
+ * Does not copy the char array which will be shared.
+ * Same as clone() but without the throws clause.
+ *
+ * @draft ICU 64
+ * @provisional This API might change or be removed in a future release.
+ */
+ public CharsTrie(CharsTrie other) {
+ chars_ = other.chars_;
+ root_ = other.root_;
+ pos_ = other.pos_;
+ remainingMatchLength_ = other.remainingMatchLength_;
+ }
+
/**
* Clones this trie reader object and its state,
* but not the char array which will be shared.
* @stable ICU 4.8
*/
@Override
- public Object clone() throws CloneNotSupportedException {
- return super.clone(); // A shallow copy is just what we need.
+ public CharsTrie clone() throws CloneNotSupportedException {
+ return (CharsTrie) super.clone(); // A shallow copy is just what we need.
}
/**
// and the remaining branch length in bits 31..16.
// (We could store the remaining branch length minus 1 in bits 30..16 and not use bit 31,
// but the code looks more confusing that way.)
- private ArrayList<Long> stack_=new ArrayList<Long>();
+ private ArrayList<Long> stack_=new ArrayList<>();
}
private void stop() {
data);
}
+ @Test
+ public void TestClone() throws CloneNotSupportedException {
+ final StringAndValue[] data={
+ new StringAndValue("a", 1),
+ new StringAndValue("ab", 100),
+ new StringAndValue("abc", 300),
+ new StringAndValue("az", 999)
+ };
+ BytesTrie trie = buildTrie(data, data.length, StringTrieBuilder.Option.SMALL);
+ assertEquals("a result", BytesTrie.Result.INTERMEDIATE_VALUE, trie.next('a'));
+ assertEquals("a value", 1, trie.getValue());
+ BytesTrie clone = trie.clone();
+ trie = null;
+ assertEquals("ab result", BytesTrie.Result.INTERMEDIATE_VALUE, clone.next('b'));
+ assertEquals("ab value", 100, clone.getValue());
+ BytesTrie copy = new BytesTrie(clone);
+ clone = null;
+ assertEquals("abc result", BytesTrie.Result.FINAL_VALUE, copy.next('c'));
+ assertEquals("abc value", 300, copy.getValue());
+ }
+
private void checkData(StringAndValue data[]) {
checkData(data, data.length);
}
checkIterator(CharsTrie.iterator(trieChars, 0, 0), data);
}
+ @Test
+ public void TestClone() throws CloneNotSupportedException {
+ final StringAndValue[] data={
+ new StringAndValue("a", 1),
+ new StringAndValue("ab", 100),
+ new StringAndValue("abc", 300),
+ new StringAndValue("az", 999)
+ };
+ CharsTrie trie = buildTrie(data, data.length, StringTrieBuilder.Option.SMALL);
+ assertEquals("a result", BytesTrie.Result.INTERMEDIATE_VALUE, trie.next('a'));
+ assertEquals("a value", 1, trie.getValue());
+ CharsTrie clone = trie.clone();
+ trie = null;
+ assertEquals("ab result", BytesTrie.Result.INTERMEDIATE_VALUE, clone.next('b'));
+ assertEquals("ab value", 100, clone.getValue());
+ CharsTrie copy = new CharsTrie(clone);
+ clone = null;
+ assertEquals("abc result", BytesTrie.Result.FINAL_VALUE, copy.next('c'));
+ assertEquals("abc value", 300, copy.getValue());
+ }
+
private void checkData(StringAndValue data[]) {
checkData(data, data.length);
}