예제 #1
0
 /// <summary>
 /// Adds a child node for the character under this character node in the
 /// trie. When the matching child node already exists, the reference of
 /// the existing child node is returned.
 /// </summary>
 ///
 /// <param name="ch">The character associated with a child node.</param>
 /// <returns>The child node.</returns>
 public TextTrieMap.CharacterNode  AddChildNode(int ch)
 {
     if (children == null)
     {
         children = new ArrayList();
         TextTrieMap.CharacterNode newNode = new TextTrieMap.CharacterNode(outer_TextTrieMap, ch);
         ILOG.J2CsMapping.Collections.Generics.Collections.Add(children, newNode);
         return(newNode);
     }
     TextTrieMap.CharacterNode node = null;
     for (int i = 0; i < children.Count; i++)
     {
         TextTrieMap.CharacterNode cur = (TextTrieMap.CharacterNode)children[i];
         if (outer_TextTrieMap.Compare(ch, cur.GetCharacter()))
         {
             node = cur;
             break;
         }
     }
     if (node == null)
     {
         node = new TextTrieMap.CharacterNode(outer_TextTrieMap, ch);
         ILOG.J2CsMapping.Collections.Generics.Collections.Add(children, node);
     }
     return(node);
 }
예제 #2
0
        private void Find(TextTrieMap.CharacterNode node, String text, int start,
                          int index, TextTrieMap.ResultHandler handler)
        {
            IIterator itr = node.Iterator();

            if (itr != null)
            {
                if (!handler.HandlePrefixMatch(index - start, itr))
                {
                    return;
                }
            }
            if (index < text.Length)
            {
                IList childNodes = node.GetChildNodes();
                if (childNodes == null)
                {
                    return;
                }
                int ch    = IBM.ICU.Text.UTF16.CharAt(text, index);
                int chLen = IBM.ICU.Text.UTF16.GetCharCount(ch);
                for (int i = 0; i < childNodes.Count; i++)
                {
                    TextTrieMap.CharacterNode child = (TextTrieMap.CharacterNode)childNodes[i];
                    if (Compare(ch, child.GetCharacter()))
                    {
                        Find(child, text, start, index + chLen, handler);
                        break;
                    }
                }
            }
        }
예제 #3
0
 public void Put(String text, Object o)
 {
     TextTrieMap.CharacterNode node = root;
     for (int i = 0; i < text.Length; i++)
     {
         int ch = IBM.ICU.Text.UTF16.CharAt(text, i);
         node = node.AddChildNode(ch);
         if (IBM.ICU.Text.UTF16.GetCharCount(ch) == 2)
         {
             i++;
         }
     }
     node.AddObject(o);
 }