Class CharArrayMap<V>
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.nd.util.CharArrayMap<V>
- Type Parameters:
V
-
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, new Integer(99));
map.get(key, 4, 3); // returns 99
map.get("two".toCharArray()); // returns 99
- Author:
- Mike Kucera
-
Constructor Summary
ConstructorDescriptionConstructs an empty CharArrayMap with default initial capacity.CharArrayMap(int initialCapacity)
Constructs an empty CharArrayMap with the given initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
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
containsValue(V value)
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
isEmpty()
Returns true if the map is empty.Collection<char[]>
keys()
Returns the keys stored in the map.void
Creates a new mapping in this map, uses the given array slice as the key.void
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
size()
Returns the number of mappings.toString()
Returns a String representation of the map.values()
Use this in a foreach loop.
-
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
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
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 nullIndexOutOfBoundsException
- if the boundaries specified by start and length are out of range
-
put
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
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 nullIndexOutOfBoundsException
- if the boundaries specified by start and length are out of range
-
get
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
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 nullIndexOutOfBoundsException
- if the boundaries specified by start and length are out of range
-
remove
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 nullIndexOutOfBoundsException
- 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
Returns true if the given value is contained in the map. -
values
Use this in a foreach loop. -
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
Returns a String representation of the map.
-