/// <summary>
        /// If the given string has been specified as a contracting string
        /// in this collation table, return its ordering.
        /// Otherwise return UNMAPPED.
        /// </summary>
        private int GetContractOrder(String groupChars)
        {
            int result = RBCollationTables.UNMAPPED;

            if (ContractTable != null)
            {
                int ch = groupChars.CodePointAt(0);

                /*
                 * char ch0 = groupChars.charAt(0);
                 * int ch = Character.isHighSurrogate(ch0)?
                 * Character.toCodePoint(ch0, groupChars.charAt(1)):ch0;
                 */
                List <EntryPair> entryTable = GetContractValues(ch);
                if (entryTable != null)
                {
                    int index = RBCollationTables.GetEntry(entryTable, groupChars, true);
                    if (index != RBCollationTables.UNMAPPED)
                    {
                        EntryPair pair = entryTable[index];
                        result = pair.Value;
                    }
                }
            }
            return(result);
        }
        /// <summary>
        ///  Adds the contracting string into the collation table.
        /// </summary>
        private void AddContractOrder(String groupChars, int anOrder, bool fwd)
        {
            if (ContractTable == null)
            {
                ContractTable = new List <>(INITIALTABLESIZE);
            }

            //initial character
            int ch = groupChars.CodePointAt(0);

            /*
             * char ch0 = groupChars.charAt(0);
             * int ch = Character.isHighSurrogate(ch0)?
             * Character.toCodePoint(ch0, groupChars.charAt(1)):ch0;
             */
            // See if the initial character of the string already has a contract table.
            int entry = Mapping.elementAt(ch);
            List <EntryPair> entryTable = GetContractValuesImpl(entry - RBCollationTables.CONTRACTCHARINDEX);

            if (entryTable == null)
            {
                // We need to create a new table of contract entries for this base char
                int tableIndex = RBCollationTables.CONTRACTCHARINDEX + ContractTable.Count;
                entryTable = new List <>(INITIALTABLESIZE);
                ContractTable.Add(entryTable);

                // Add the initial character's current ordering first. then
                // update its mapping to point to this contract table
                entryTable.Add(new EntryPair(groupChars.Substring(0, Character.CharCount(ch)), entry));
                Mapping.setElementAt(ch, tableIndex);
            }

            // Now add (or replace) this string in the table
            int index = RBCollationTables.GetEntry(entryTable, groupChars, fwd);

            if (index != RBCollationTables.UNMAPPED)
            {
                EntryPair pair = entryTable[index];
                pair.Value = anOrder;
            }
            else
            {
                EntryPair pair = entryTable[entryTable.Count - 1];

                // NOTE:  This little bit of logic is here to speed CollationElementIterator
                // .nextContractChar().  This code ensures that the longest sequence in
                // this list is always the _last_ one in the list.  This keeps
                // nextContractChar() from having to search the entire list for the longest
                // sequence.
                if (groupChars.Length() > pair.EntryName.Length())
                {
                    entryTable.Add(new EntryPair(groupChars, anOrder, fwd));
                }
                else
                {
                    entryTable.Insert(entryTable.Count - 1, new EntryPair(groupChars, anOrder, fwd));
                }
            }

            // If this was a forward mapping for a contracting string, also add a
            // reverse mapping for it, so that CollationElementIterator.previous
            // can work right
            if (fwd && groupChars.Length() > 1)
            {
                AddContractFlags(groupChars);
                AddContractOrder((new StringBuffer(groupChars)).Reverse().ToString(), anOrder, false);
            }
        }