Class CharArrayMap<V>

java.lang.Object
org.eclipse.cdt.core.parser.util.CharArrayMap<V>
Type Parameters:
V -

public final class CharArrayMap<V> extends Object
Provides functionality similar to a Map, with the feature that char arrays and sections of char arrays (known as slices) may be used as keys. This class is useful because small pieces of an existing large char[] buffer can be directly used as map keys. This avoids the need to create many String objects as would normally be needed as keys in a standard java.util.Map. Thus performance is improved in the CDT core. Most methods are overloaded with two versions, one that uses a section of a char[] as the key (a slice), and one that uses the entire char[] as the key. This class is intended as a replacement for CharArrayObjectMap. ex: char[] key = "one two three".toCharArray(); map.put(key, 4, 3, Integer.valueOf(99)); map.get(key, 4, 3); // returns 99 map.get("two".toCharArray()); // returns 99
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty CharArrayMap with default initial capacity.
    CharArrayMap(int initialCapacity)
    Constructs an empty CharArrayMap with the given initial capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all mappings from the map.
    boolean
    containsKey(char[] chars)
    Returns true if the given key has a value associated with it in the map.
    boolean
    containsKey(char[] chars, int start, int length)
    Returns true if the given key has a value associated with it in the map.
    boolean
    Returns true if the given value is contained in the map.
    static <V> CharArrayMap<V>
    Static factory method that constructs an empty CharArrayMap with default initial capacity, and the map will be kept in ascending key order.
    get(char[] chars)
    Returns the value to which the specified array is mapped in this map, or null if the map contains no mapping for this key.
    get(char[] chars, int start, int length)
    Returns the value to which the specified array slice is mapped in this map, or null if the map contains no mapping for this key.
    boolean
    Returns true if the map is empty.
    Collection<char[]>
    Returns the keys stored in the map.
    void
    put(char[] chars, int start, int length, V value)
    Creates a new mapping in this map, uses the given array slice as the key.
    void
    put(char[] chars, V value)
    Creates a new mapping in this map, uses all of the given array as the key.
    remove(char[] chars)
    Removes the mapping for the given array if present.
    remove(char[] chars, int start, int length)
    Removes the mapping for the given array slice if present.
    int
    Returns the number of mappings.
    Returns a String representation of the map.
    Use this in a foreach loop.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CharArrayMap

      public CharArrayMap()
      Constructs an empty CharArrayMap with default initial capacity.
    • CharArrayMap

      public CharArrayMap(int initialCapacity)
      Constructs an empty CharArrayMap with the given initial capacity.
      Throws:
      IllegalArgumentException - if the initial capacity is negative
  • Method Details

    • createOrderedMap

      public static <V> CharArrayMap<V> createOrderedMap()
      Static factory method that constructs an empty CharArrayMap with default initial capacity, and the map will be kept in ascending key order. Characters are compared using a strictly numerical comparison; it is not locale-dependent.
    • put

      public void put(char[] chars, int start, int length, V value)
      Creates a new mapping in this map, uses the given array slice as the key. If the map previously contained a mapping for this key, the old value is replaced.
      Throws:
      NullPointerException - if chars is null
      IndexOutOfBoundsException - if the boundaries specified by start and length are out of range
    • put

      public void put(char[] chars, V value)
      Creates a new mapping in this map, uses all of the given array as the key. If the map previously contained a mapping for this key, the old value is replaced.
      Throws:
      NullPointerException - if chars is null
    • get

      public V get(char[] chars, int start, int length)
      Returns the value to which the specified array slice is mapped in this map, or null if the map contains no mapping for this key.
      Throws:
      NullPointerException - if chars is null
      IndexOutOfBoundsException - if the boundaries specified by start and length are out of range
    • get

      public V get(char[] chars)
      Returns the value to which the specified array is mapped in this map, or null if the map contains no mapping for this key.
      Throws:
      NullPointerException - if chars is null
    • remove

      public V remove(char[] chars, int start, int length)
      Removes the mapping for the given array slice if present. Returns the value object that corresponded to the key or null if the key was not in the map.
      Throws:
      NullPointerException - if chars is null
      IndexOutOfBoundsException - if the boundaries specified by start and length are out of range
    • remove

      public V remove(char[] chars)
      Removes the mapping for the given array if present. Returns the value object that corresponded to the key or null if the key was not in the map.
      Throws:
      NullPointerException - if chars is null
    • containsKey

      public boolean containsKey(char[] chars, int start, int length)
      Returns true if the given key has a value associated with it in the map.
      Throws:
      NullPointerException - if chars is null
      IndexOutOfBoundsException - if the boundaries specified by start and length are out of range
    • containsKey

      public boolean containsKey(char[] chars)
      Returns true if the given key has a value associated with it in the map.
      Throws:
      NullPointerException - if chars is null
    • containsValue

      public boolean containsValue(V value)
      Returns true if the given value is contained in the map.
    • values

      public Collection<V> values()
      Use this in a foreach loop.
    • keys

      public Collection<char[]> keys()
      Returns the keys stored in the map.
    • clear

      public void clear()
      Removes all mappings from the map.
    • size

      public int size()
      Returns the number of mappings.
    • isEmpty

      public boolean isEmpty()
      Returns true if the map is empty.
    • toString

      public String toString()
      Returns a String representation of the map.
      Overrides:
      toString in class Object