Class KeywordMap


  • public class KeywordMap
    extends java.lang.Object
    Maps (parts of) Segments to byte values. It allows lookups of text sub-strings without the overhead of creating new string objects.

    The keys are stored in a tree consisting of Nodes. Each node represents one character of the key string. The root node rootNode represents the first character.

    • Constructor Summary

      Constructors 
      Constructor Description
      KeywordMap​(boolean ignoreCase)
      Creates a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.CharSequence keyword, byte id)
      Adds a key-value mapping.
      byte lookup​(javax.swing.text.Segment text, int offset, int length)
      Looks up a key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KeywordMap

        public KeywordMap​(boolean ignoreCase)
        Creates a new instance.
        Parameters:
        ignoreCase - if set, ignore match keys case-insensitive
    • Method Detail

      • lookup

        public byte lookup​(javax.swing.text.Segment text,
                           int offset,
                           int length)
        Looks up a key.
        Parameters:
        text - the text segment to look up
        offset - the starting offset of the key within the text segment
        length - the length of the key
        Returns:
        the id registered for the key, or Token.NULL if no key matches
      • add

        public void add​(java.lang.CharSequence keyword,
                        byte id)
        Adds a key-value mapping.
        Parameters:
        keyword - the key to add
        id - the value to map to