Class HashMapIndex

  • All Implemented Interfaces:
    StringIndex
    Direct Known Subclasses:
    FileBasedIndex

    public class HashMapIndex
    extends Object
    implements StringIndex
    Implements a StringIndex that is based on a hashmap. Subclasses can override the protected load() and save() methods to implement persistent storage of the string index.

    This class is thread-safe.

    • Field Detail

      • stringToIndex

        protected final HashMap<String,​Integer> stringToIndex
        holds the string-to-index lookups.
      • indexToString

        protected final HashMap<Integer,​String> indexToString
        holds the index-to-string lookups.
    • Constructor Detail

      • HashMapIndex

        public HashMapIndex()
    • Method Detail

      • load

        protected void load()
        Loads the lookup table.
      • save

        protected void save()
        Saves the lookup table.
      • stringToIndex

        public int stringToIndex​(String nsUri)
        Returns the index for a given string. If the given string is not already indexed, the implementation can either automatically index it or throw an exception. This implementation reloads the table from the resource if a lookup fails and if the resource was modified since.
        Specified by:
        stringToIndex in interface StringIndex
        Parameters:
        nsUri - the indexed (or to be indexed) string
        Returns:
        index of the string
      • indexToString

        public String indexToString​(int i)
        Returns the string for a given index. This implementation reloads the table from the resource if a lookup fails and if the resource was modified since.
        Specified by:
        indexToString in interface StringIndex
        Parameters:
        i - index of a string
        Returns:
        the indexed string