Package org.apache.lucene.analysis
Class CharArrayMap<V>
- java.lang.Object
-
- java.util.AbstractMap<java.lang.Object,V>
-
- org.apache.lucene.analysis.CharArrayMap<V>
-
- All Implemented Interfaces:
java.util.Map<java.lang.Object,V>
- Direct Known Subclasses:
CharArrayMap.UnmodifiableCharArrayMap
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCharArrayMap.EmptyCharArrayMap<V>EmptyCharArrayMap.UnmodifiableCharArrayMapoptimized for speed.classCharArrayMap.EntryIteratorpublic iterator class so efficient methods are exposed to usersclassCharArrayMap.EntrySetpublic EntrySet class so efficient methods are exposed to usersprivate classCharArrayMap.MapEntry(package private) static classCharArrayMap.UnmodifiableCharArrayMap<V>
-
Field Summary
Fields Modifier and Type Field Description private intcountprivate static CharArrayMap<?>EMPTY_MAPprivate CharArrayMap.EntrySetentrySetprivate booleanignoreCaseprivate static intINIT_SIZE(package private) char[][]keysprivate CharArraySetkeySet(package private) V[]values
-
Constructor Summary
Constructors Modifier Constructor Description CharArrayMap(int startSize, boolean ignoreCase)Create map with enough capacity to hold startSize termsCharArrayMap(java.util.Map<?,? extends V> c, boolean ignoreCase)Creates a map from the mappings in another map.privateCharArrayMap(CharArrayMap<V> toCopy)Create set from the supplied map (used internally for readonly maps...)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears all entries in this map.booleancontainsKey(char[] text, int off, int len)booleancontainsKey(java.lang.CharSequence cs)true if theCharSequenceis in thekeySet()booleancontainsKey(java.lang.Object o)static <V> CharArrayMap<V>copy(java.util.Map<?,? extends V> map)Returns a copy of the given map as aCharArrayMap.(package private) CharArrayMap.EntrySetcreateEntrySet()static <V> CharArrayMap<V>emptyMap()Returns an empty, unmodifiable map.CharArrayMap.EntrySetentrySet()private booleanequals(char[] text1, int off, int len, char[] text2)private booleanequals(java.lang.CharSequence text1, char[] text2)Vget(char[] text, int off, int len)returns the value of the mapping oflenchars oftextstarting atoffVget(java.lang.CharSequence cs)returns the value of the mapping of the chars inside thisCharSequenceVget(java.lang.Object o)private intgetHashCode(char[] text, int offset, int len)private intgetHashCode(java.lang.CharSequence text)private intgetSlot(char[] text, int off, int len)private intgetSlot(java.lang.CharSequence text)Returns true if the String is in the setCharArraySetkeySet()Returns anCharArraySetview on the map's keys.(package private) java.util.Set<java.lang.Object>originalKeySet()Vput(char[] text, V value)Add the given mapping.Vput(java.lang.CharSequence text, V value)Add the given mapping.Vput(java.lang.Object o, V value)Vput(java.lang.String text, V value)Add the given mapping.private voidrehash()Vremove(java.lang.Object key)intsize()java.lang.StringtoString()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
-
-
-
-
Field Detail
-
EMPTY_MAP
private static final CharArrayMap<?> EMPTY_MAP
-
INIT_SIZE
private static final int INIT_SIZE
- See Also:
- Constant Field Values
-
ignoreCase
private boolean ignoreCase
-
count
private int count
-
keys
char[][] keys
-
values
V[] values
-
entrySet
private CharArrayMap.EntrySet entrySet
-
keySet
private CharArraySet keySet
-
-
Constructor Detail
-
CharArrayMap
public CharArrayMap(int startSize, boolean ignoreCase)Create map with enough capacity to hold startSize terms- Parameters:
startSize- the initial capacityignoreCase-falseif and only if the set should be case sensitive otherwisetrue.
-
CharArrayMap
public CharArrayMap(java.util.Map<?,? extends V> c, boolean ignoreCase)
Creates a map from the mappings in another map.- Parameters:
c- a map whose mappings to be copiedignoreCase-falseif and only if the set should be case sensitive otherwisetrue.
-
CharArrayMap
private CharArrayMap(CharArrayMap<V> toCopy)
Create set from the supplied map (used internally for readonly maps...)
-
-
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 theCharSequenceis 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 oflenchars oftextstarting 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)
-
getSlot
private int getSlot(char[] text, int off, int len)
-
getSlot
private int getSlot(java.lang.CharSequence text)
Returns true if the String is in the set
-
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(java.lang.CharSequence text1, char[] text2)
-
getHashCode
private int getHashCode(char[] text, int offset, int len)
-
getHashCode
private int getHashCode(java.lang.CharSequence text)
-
remove
public V remove(java.lang.Object key)
-
size
public int size()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractMap<java.lang.Object,V>
-
createEntrySet
CharArrayMap.EntrySet createEntrySet()
-
entrySet
public final CharArrayMap.EntrySet entrySet()
-
originalKeySet
final java.util.Set<java.lang.Object> originalKeySet()
-
keySet
public final CharArraySet keySet()
Returns anCharArraySetview on the map's keys. The set will use the samematchVersionas 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(java.util.Map<?,? extends V> map)
Returns a copy of the given map as aCharArrayMap. If the given map is aCharArrayMapthe 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 aCharArrayMapthe 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.
-
-