Class CharArrayMap<V>

java.lang.Object
java.util.AbstractMap<Object,V>
org.apache.lucene.analysis.CharArrayMap<V>
All Implemented Interfaces:
Map<Object,V>
Direct Known Subclasses:
CharArrayMap.UnmodifiableCharArrayMap

public class CharArrayMap<V> extends AbstractMap<Object,V>
A simple class that stores key Strings as char[]'s in a hash table. Note that this is not a general purpose class. For example, it cannot remove items from the map, nor does it resize its hash table to be smaller, etc. It is designed to be quick to retrieve items by char[] keys without the necessity of converting to a String first.
  • Field Details

  • Constructor Details

    • CharArrayMap

      public CharArrayMap(int startSize, boolean ignoreCase)
      Create map with enough capacity to hold startSize terms
      Parameters:
      startSize - the initial capacity
      ignoreCase - false if and only if the set should be case sensitive otherwise true.
    • CharArrayMap

      public CharArrayMap(Map<?,? extends V> c, boolean ignoreCase)
      Creates a map from the mappings in another map.
      Parameters:
      c - a map whose mappings to be copied
      ignoreCase - false if and only if the set should be case sensitive otherwise true.
    • CharArrayMap

      private CharArrayMap(CharArrayMap<V> toCopy)
      Create set from the supplied map (used internally for readonly maps...)
  • Method Details

    • clear

      public void clear()
      Clears all entries in this map. This method is supported for reusing, but not Map.remove(java.lang.Object).
      Specified by:
      clear in interface Map<Object,V>
      Overrides:
      clear in class AbstractMap<Object,V>
    • containsKey

      public boolean containsKey(char[] text, int off, int len)
      true if the len chars of text starting at off are in the keySet()
    • containsKey

      public boolean containsKey(CharSequence cs)
      true if the CharSequence is in the keySet()
    • containsKey

      public boolean containsKey(Object o)
      Specified by:
      containsKey in interface Map<Object,V>
      Overrides:
      containsKey in class AbstractMap<Object,V>
    • get

      public V get(char[] text, int off, int len)
      returns the value of the mapping of len chars of text starting at off
    • get

      public V get(CharSequence cs)
      returns the value of the mapping of the chars inside this CharSequence
    • get

      public V get(Object o)
      Specified by:
      get in interface Map<Object,V>
      Overrides:
      get in class AbstractMap<Object,V>
    • getSlot

      private int getSlot(char[] text, int off, int len)
    • getSlot

      private int getSlot(CharSequence text)
      Returns true if the String is in the set
    • put

      public V put(CharSequence text, V value)
      Add the given mapping.
    • put

      public V put(Object o, V value)
      Specified by:
      put in interface Map<Object,V>
      Overrides:
      put in class AbstractMap<Object,V>
    • put

      public V put(String text, V value)
      Add the given mapping.
    • put

      public V put(char[] text, V value)
      Add the given mapping. If ignoreCase is true for this Set, the text array will be directly modified. The user should never modify this text array after calling this method.
    • rehash

      private void rehash()
    • equals

      private boolean equals(char[] text1, int off, int len, char[] text2)
    • equals

      private boolean equals(CharSequence text1, char[] text2)
    • getHashCode

      private int getHashCode(char[] text, int offset, int len)
    • getHashCode

      private int getHashCode(CharSequence text)
    • remove

      public V remove(Object key)
      Specified by:
      remove in interface Map<Object,V>
      Overrides:
      remove in class AbstractMap<Object,V>
    • size

      public int size()
      Specified by:
      size in interface Map<Object,V>
      Overrides:
      size in class AbstractMap<Object,V>
    • toString

      public String toString()
      Overrides:
      toString in class AbstractMap<Object,V>
    • createEntrySet

      CharArrayMap<V>.EntrySet createEntrySet()
    • entrySet

      public final CharArrayMap<V>.EntrySet entrySet()
      Specified by:
      entrySet in interface Map<Object,V>
      Specified by:
      entrySet in class AbstractMap<Object,V>
    • originalKeySet

      final Set<Object> originalKeySet()
    • keySet

      public final CharArraySet keySet()
      Returns an CharArraySet view on the map's keys. The set will use the same matchVersion as this map.
      Specified by:
      keySet in interface Map<Object,V>
      Overrides:
      keySet in class AbstractMap<Object,V>
    • unmodifiableMap

      public static <V> CharArrayMap<V> unmodifiableMap(CharArrayMap<V> map)
      Returns an unmodifiable CharArrayMap. This allows to provide unmodifiable views of internal map for "read-only" use.
      Parameters:
      map - a map for which the unmodifiable map is returned.
      Returns:
      an new unmodifiable CharArrayMap.
      Throws:
      NullPointerException - if the given map is null.
    • copy

      public static <V> CharArrayMap<V> copy(Map<?,? extends V> map)
      Returns a copy of the given map as a CharArrayMap. If the given map is a CharArrayMap the ignoreCase property will be preserved.
      Parameters:
      map - a map to copy
      Returns:
      a copy of the given map as a CharArrayMap. If the given map is a CharArrayMap the ignoreCase property as well as the matchVersion will be of the given map will be preserved.
    • emptyMap

      public static <V> CharArrayMap<V> emptyMap()
      Returns an empty, unmodifiable map.