Package org.apache.lucene.analysis.util
Class CharArrayMap<V>
- java.lang.Object
-
- java.util.AbstractMap<java.lang.Object,V>
-
- org.apache.lucene.analysis.util.CharArrayMap<V>
-
- All Implemented Interfaces:
java.util.Map<java.lang.Object,V>
public class CharArrayMap<V> extends java.util.AbstractMap<java.lang.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.You must specify the required
Version
compatibility when creatingCharArrayMap
:- As of 3.1, supplementary characters are properly lowercased.
CharArrayMap
with the behavior before Lucene 3.1 pass aVersion
< 3.1 to the constructors.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
CharArrayMap.EntryIterator
public iterator class so efficient methods are exposed to usersclass
CharArrayMap.EntrySet
public EntrySet class so efficient methods are exposed to users
-
Constructor Summary
Constructors Constructor Description CharArrayMap(Version matchVersion, int startSize, boolean ignoreCase)
Create map with enough capacity to hold startSize termsCharArrayMap(Version matchVersion, java.util.Map<?,? extends V> c, boolean ignoreCase)
Creates a map from the mappings in another map.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears all entries in this map.boolean
containsKey(char[] text, int off, int len)
boolean
containsKey(java.lang.CharSequence cs)
true if theCharSequence
is in thekeySet()
boolean
containsKey(java.lang.Object o)
static <V> CharArrayMap<V>
copy(Version matchVersion, java.util.Map<?,? extends V> map)
Returns a copy of the given map as aCharArrayMap
.static <V> CharArrayMap<V>
emptyMap()
Returns an empty, unmodifiable map.CharArrayMap.EntrySet
entrySet()
V
get(char[] text, int off, int len)
returns the value of the mapping oflen
chars oftext
starting atoff
V
get(java.lang.CharSequence cs)
returns the value of the mapping of the chars inside thisCharSequence
V
get(java.lang.Object o)
CharArraySet
keySet()
Returns anCharArraySet
view on the map's keys.V
put(char[] text, V value)
Add the given mapping.V
put(java.lang.CharSequence text, V value)
Add the given mapping.V
put(java.lang.Object o, V value)
V
put(java.lang.String text, V value)
Add the given mapping.V
remove(java.lang.Object key)
int
size()
java.lang.String
toString()
static <V> CharArrayMap<V>
unmodifiableMap(CharArrayMap<V> map)
Returns an unmodifiableCharArrayMap
.
-
-
-
Constructor Detail
-
CharArrayMap
public CharArrayMap(Version matchVersion, int startSize, boolean ignoreCase)
Create map with enough capacity to hold startSize terms- Parameters:
matchVersion
- compatibility match version see Version note above for details.startSize
- the initial capacityignoreCase
-false
if and only if the set should be case sensitive otherwisetrue
.
-
CharArrayMap
public CharArrayMap(Version matchVersion, java.util.Map<?,? extends V> c, boolean ignoreCase)
Creates a map from the mappings in another map.- Parameters:
matchVersion
- compatibility match version see Version note above for details.c
- a map whose mappings to be copiedignoreCase
-false
if and only if the set should be case sensitive otherwisetrue
.
-
-
Method Detail
-
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
public boolean containsKey(java.lang.CharSequence cs)
true if theCharSequence
is in thekeySet()
-
containsKey
public boolean containsKey(java.lang.Object o)
-
get
public V get(char[] text, int off, int len)
returns the value of the mapping oflen
chars oftext
starting atoff
-
get
public V get(java.lang.CharSequence cs)
returns the value of the mapping of the chars inside thisCharSequence
-
get
public V get(java.lang.Object o)
-
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.
-
remove
public V remove(java.lang.Object key)
-
size
public int size()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractMap<java.lang.Object,V>
-
entrySet
public final CharArrayMap.EntrySet entrySet()
-
keySet
public final CharArraySet keySet()
Returns anCharArraySet
view on the map's keys. The set will use the samematchVersion
as this map.
-
unmodifiableMap
public static <V> CharArrayMap<V> unmodifiableMap(CharArrayMap<V> map)
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:
java.lang.NullPointerException
- if the given map isnull
.
-
copy
public static <V> CharArrayMap<V> copy(Version matchVersion, java.util.Map<?,? extends V> map)
Returns a copy of the given map as aCharArrayMap
. If the given map is aCharArrayMap
the ignoreCase property will be preserved.Note: If you intend to create a copy of another
CharArrayMap
where theVersion
of the source map differs from its copyCharArrayMap(Version, Map, boolean)
should be used instead. Thecopy(Version, Map)
will preserve theVersion
of the source map it is an instance ofCharArrayMap
.- Parameters:
matchVersion
- compatibility match version see Version note above for details. This argument will be ignored if the given map is aCharArrayMap
.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
public static <V> CharArrayMap<V> emptyMap()
Returns an empty, unmodifiable map.
-
-