- Direct Known Subclasses:
CharArrayMap.UnmodifiableCharArrayMap
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
EmptyCharArrayMap.UnmodifiableCharArrayMap
optimized for speed.class
public iterator class so efficient methods are exposed to usersfinal class
public EntrySet class so efficient methods are exposed to usersprivate final class
(package private) static class
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private static final CharArrayMap<?>
private CharArrayMap<V>.EntrySet
private boolean
private static final int
(package private) char[][]
private CharArraySet
(package private) V[]
-
Constructor Summary
ConstructorsModifierConstructorDescriptionCharArrayMap
(int startSize, boolean ignoreCase) Create map with enough capacity to hold startSize termsCharArrayMap
(Map<?, ? extends V> c, boolean ignoreCase) Creates a map from the mappings in another map.private
CharArrayMap
(CharArrayMap<V> toCopy) Create set from the supplied map (used internally for readonly maps...) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears all entries in this map.boolean
containsKey
(char[] text, int off, int len) boolean
true if theCharSequence
is in thekeySet()
boolean
static <V> CharArrayMap<V>
Returns a copy of the given map as aCharArrayMap
.(package private) CharArrayMap<V>.EntrySet
static <V> CharArrayMap<V>
emptyMap()
Returns an empty, unmodifiable map.final CharArrayMap<V>.EntrySet
entrySet()
private boolean
equals
(char[] text1, int off, int len, char[] text2) private boolean
equals
(CharSequence text1, char[] text2) get
(char[] text, int off, int len) returns the value of the mapping oflen
chars oftext
starting atoff
get
(CharSequence cs) returns the value of the mapping of the chars inside thisCharSequence
private int
getHashCode
(char[] text, int offset, int len) private int
getHashCode
(CharSequence text) private int
getSlot
(char[] text, int off, int len) private int
getSlot
(CharSequence text) Returns true if the String is in the setfinal CharArraySet
keySet()
Returns anCharArraySet
view on the map's keys.Add the given mapping.put
(CharSequence text, V value) Add the given mapping.Add the given mapping.private void
rehash()
int
size()
toString()
static <V> CharArrayMap<V>
unmodifiableMap
(CharArrayMap<V> map) Returns an unmodifiableCharArrayMap
.Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, putAll, values
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
EMPTY_MAP
-
INIT_SIZE
private static final int INIT_SIZE- See Also:
-
ignoreCase
private boolean ignoreCase -
count
private int count -
keys
char[][] keys -
values
V[] values -
entrySet
-
keySet
-
-
Constructor Details
-
CharArrayMap
public CharArrayMap(int startSize, boolean ignoreCase) Create map with enough capacity to hold startSize terms- Parameters:
startSize
- the initial capacityignoreCase
-false
if and only if the set should be case sensitive otherwisetrue
.
-
CharArrayMap
Creates a map from the mappings in another map.- Parameters:
c
- a map whose mappings to be copiedignoreCase
-false
if and only if the set should be case sensitive otherwisetrue
.
-
CharArrayMap
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 notMap.remove(java.lang.Object)
. -
containsKey
public boolean containsKey(char[] text, int off, int len) -
containsKey
true if theCharSequence
is in thekeySet()
-
containsKey
- Specified by:
containsKey
in interfaceMap<Object,
V> - Overrides:
containsKey
in classAbstractMap<Object,
V>
-
get
returns the value of the mapping oflen
chars oftext
starting atoff
-
get
returns the value of the mapping of the chars inside thisCharSequence
-
get
-
getSlot
private int getSlot(char[] text, int off, int len) -
getSlot
Returns true if the String is in the set -
put
Add the given mapping. -
put
-
put
Add the given mapping. -
put
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
-
getHashCode
private int getHashCode(char[] text, int offset, int len) -
getHashCode
-
remove
-
size
public int size() -
toString
- Overrides:
toString
in classAbstractMap<Object,
V>
-
createEntrySet
CharArrayMap<V>.EntrySet createEntrySet() -
entrySet
-
originalKeySet
-
keySet
Returns anCharArraySet
view on the map's keys. The set will use the samematchVersion
as this map. -
unmodifiableMap
Returns an unmodifiableCharArrayMap
. 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 isnull
.
-
copy
Returns a copy of the given map as aCharArrayMap
. If the given map is aCharArrayMap
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 aCharArrayMap
the ignoreCase property as well as the matchVersion will be of the given map will be preserved.
-
emptyMap
Returns an empty, unmodifiable map.
-