12ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/* GENERATED SOURCE. DO NOT MODIFY. */
2f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// © 2016 and later: Unicode, Inc. and others.
3f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html#License
42ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/*
52ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*******************************************************************************
62ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*   Copyright (C) 2011-2014, International Business Machines
72ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*   Corporation and others.  All Rights Reserved.
82ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*******************************************************************************
92ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*   created on: 2011jan07
102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*   created by: Markus W. Scherer
112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*   ported from ICU4C ucharstriebuilder/.cpp
122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*/
132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpackage android.icu.util;
152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.nio.CharBuffer;
172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/**
192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Builder class for CharsTrie.
202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller *
212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>This class is not intended for public subclassing.
222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller *
232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @author Markus W. Scherer
24836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide Only a subset of ICU is exposed in Android
252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */
262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpublic final class CharsTrieBuilder extends StringTrieBuilder {
272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Constructs an empty builder.
292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public CharsTrieBuilder() {}
312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Adds a (string, value) pair.
342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * The string must be unique.
352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * The string contents will be copied; the builder does not keep
362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * a reference to the input CharSequence.
372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param s The input string.
382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param value The value associated with this char sequence.
392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @return this
402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public CharsTrieBuilder add(CharSequence s, int value) {
422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        addImpl(s, value);
432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return this;
442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Builds a CharsTrie for the add()ed data.
482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Once built, no further data can be add()ed until clear() is called.
492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * <p>A CharsTrie cannot be empty. At least one (string, value) pair
512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * must have been add()ed.
522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * <p>Multiple calls to build() or buildCharSequence() return tries or sequences
542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * which share the builder's char array, without rebuilding.
552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * After clear() has been called, a new array will be used.
562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param buildOption Build option, see StringTrieBuilder.Option.
572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @return A new CharsTrie for the add()ed data.
582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public CharsTrie build(StringTrieBuilder.Option buildOption) {
602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return new CharsTrie(buildCharSequence(buildOption), 0);
612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Builds a CharsTrie for the add()ed data and char-serializes it.
652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Once built, no further data can be add()ed until clear() is called.
662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * <p>A CharsTrie cannot be empty. At least one (string, value) pair
682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * must have been add()ed.
692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * <p>Multiple calls to build() or buildCharSequence() return tries or sequences
712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * which share the builder's char array, without rebuilding.
722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * After clear() has been called, a new array will be used.
732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param buildOption Build option, see StringTrieBuilder.Option.
742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @return A CharSequence with the char-serialized CharsTrie for the add()ed data.
752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public CharSequence buildCharSequence(StringTrieBuilder.Option buildOption) {
772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        buildChars(buildOption);
782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return CharBuffer.wrap(chars, chars.length-charsLength, charsLength);
792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private void buildChars(StringTrieBuilder.Option buildOption) {
822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // Create and char-serialize the trie for the elements.
832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if(chars==null) {
842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            chars=new char[1024];
852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        buildImpl(buildOption);
872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Removes all (string, value) pairs.
912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * New data can then be add()ed and a new trie can be built.
922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @return this
932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public CharsTrieBuilder clear() {
952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        clearImpl();
962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        chars=null;
972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        charsLength=0;
982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return this;
992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * {@inheritDoc}
1032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @deprecated This API is ICU internal only.
104836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller     * @hide draft / provisional / internal are hidden on Android
1052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Deprecated
1072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Override
1082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected boolean matchNodesCanHaveValues() /*const*/ { return true; }
1092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * {@inheritDoc}
1122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @deprecated This API is ICU internal only.
113836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller     * @hide draft / provisional / internal are hidden on Android
1142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Deprecated
1162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Override
1172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int getMaxBranchLinearSubNodeLength() /*const*/ { return CharsTrie.kMaxBranchLinearSubNodeLength; }
1182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * {@inheritDoc}
1202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @deprecated This API is ICU internal only.
121836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller     * @hide draft / provisional / internal are hidden on Android
1222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Deprecated
1242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Override
1252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int getMinLinearMatch() /*const*/ { return CharsTrie.kMinLinearMatch; }
1262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * {@inheritDoc}
1282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @deprecated This API is ICU internal only.
129836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller     * @hide draft / provisional / internal are hidden on Android
1302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Deprecated
1322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Override
1332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int getMaxLinearMatchLength() /*const*/ { return CharsTrie.kMaxLinearMatchLength; }
1342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private void ensureCapacity(int length) {
1362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if(length>chars.length) {
1372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            int newCapacity=chars.length;
1382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            do {
1392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                newCapacity*=2;
1402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            } while(newCapacity<=length);
1412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            char[] newChars=new char[newCapacity];
1422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            System.arraycopy(chars, chars.length-charsLength,
1432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                             newChars, newChars.length-charsLength, charsLength);
1442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            chars=newChars;
1452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
1462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * {@inheritDoc}
1492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @deprecated This API is ICU internal only.
150836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller     * @hide draft / provisional / internal are hidden on Android
1512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Deprecated
1532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Override
1542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int write(int unit) {
1552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int newLength=charsLength+1;
1562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        ensureCapacity(newLength);
1572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        charsLength=newLength;
1582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        chars[chars.length-charsLength]=(char)unit;
1592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return charsLength;
1602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * {@inheritDoc}
1632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @deprecated This API is ICU internal only.
164836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller     * @hide draft / provisional / internal are hidden on Android
1652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Deprecated
1672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Override
1682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int write(int offset, int length) {
1692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int newLength=charsLength+length;
1702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        ensureCapacity(newLength);
1712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        charsLength=newLength;
1722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int charsOffset=chars.length-charsLength;
1732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        while(length>0) {
1742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            chars[charsOffset++]=strings.charAt(offset++);
1752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            --length;
1762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
1772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return charsLength;
1782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private int write(char[] s, int length) {
1802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int newLength=charsLength+length;
1812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        ensureCapacity(newLength);
1822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        charsLength=newLength;
1832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        System.arraycopy(s, 0, chars, chars.length-charsLength, length);
1842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return charsLength;
1852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    // For writeValueAndFinal(), writeValueAndType() and writeDeltaTo().
1882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private final char[] intUnits=new char[3];
1892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * {@inheritDoc}
1922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @deprecated This API is ICU internal only.
193836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller     * @hide draft / provisional / internal are hidden on Android
1942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Deprecated
1962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Override
1972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int writeValueAndFinal(int i, boolean isFinal) {
1982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if(0<=i && i<=CharsTrie.kMaxOneUnitValue) {
1992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            return write(i|(isFinal ? CharsTrie.kValueIsFinal : 0));
2002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int length;
2022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if(i<0 || i>CharsTrie.kMaxTwoUnitValue) {
2032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[0]=(char)(CharsTrie.kThreeUnitValueLead);
2042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[1]=(char)(i>>16);
2052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[2]=(char)i;
2062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            length=3;
2072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // } else if(i<=CharsTrie.kMaxOneUnitValue) {
2082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        //     intUnits[0]=(char)(i);
2092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        //     length=1;
2102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        } else {
2112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[0]=(char)(CharsTrie.kMinTwoUnitValueLead+(i>>16));
2122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[1]=(char)i;
2132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            length=2;
2142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        intUnits[0]=(char)(intUnits[0]|(isFinal ? CharsTrie.kValueIsFinal : 0));
2162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return write(intUnits, length);
2172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
2182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
2192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * {@inheritDoc}
2202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @deprecated This API is ICU internal only.
221836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller     * @hide draft / provisional / internal are hidden on Android
2222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
2232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Deprecated
2242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Override
2252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int writeValueAndType(boolean hasValue, int value, int node) {
2262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if(!hasValue) {
2272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            return write(node);
2282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int length;
2302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if(value<0 || value>CharsTrie.kMaxTwoUnitNodeValue) {
2312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[0]=(char)(CharsTrie.kThreeUnitNodeValueLead);
2322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[1]=(char)(value>>16);
2332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[2]=(char)value;
2342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            length=3;
2352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        } else if(value<=CharsTrie.kMaxOneUnitNodeValue) {
2362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[0]=(char)((value+1)<<6);
2372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            length=1;
2382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        } else {
2392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[0]=(char)(CharsTrie.kMinTwoUnitNodeValueLead+((value>>10)&0x7fc0));
2402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[1]=(char)value;
2412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            length=2;
2422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        intUnits[0]|=(char)node;
2442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return write(intUnits, length);
2452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
2462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
2472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * {@inheritDoc}
2482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @deprecated This API is ICU internal only.
249836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller     * @hide draft / provisional / internal are hidden on Android
2502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
2512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Deprecated
2522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    @Override
2532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int writeDeltaTo(int jumpTarget) {
2542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int i=charsLength-jumpTarget;
2552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        assert(i>=0);
2562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if(i<=CharsTrie.kMaxOneUnitDelta) {
2572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            return write(i);
2582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int length;
2602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if(i<=CharsTrie.kMaxTwoUnitDelta) {
2612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[0]=(char)(CharsTrie.kMinTwoUnitDeltaLead+(i>>16));
2622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            length=1;
2632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        } else {
2642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[0]=(char)(CharsTrie.kThreeUnitDeltaLead);
2652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            intUnits[1]=(char)(i>>16);
2662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            length=2;
2672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        intUnits[length++]=(char)i;
2692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return write(intUnits, length);
2702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
2712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    // char serialization of the trie.
2732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    // Grows from the back: charsLength measures from the end of the buffer!
2742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private char[] chars;
2752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private int charsLength;
2762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller}
277