org.slim3.commons.util
Class ArrayMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.slim3.commons.util.ArrayMap<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Map<K,V>
Direct Known Subclasses:
CaseInsensitiveMap

public class ArrayMap<K,V>
extends AbstractMap<K,V>
implements Map<K,V>, Cloneable, Externalizable

A map acts like array.

Since:
3.0
Author:
higa
See Also:
Serialized Form

Field Summary
protected  Set<Map.Entry<K,V>> entrySet
          The set of entries.
protected static int INITIAL_CAPACITY
          The default initial capacity.
protected  org.slim3.commons.util.ArrayMap.Entry<K,V>[] listTable
          The list table.
protected static float LOAD_FACTOR
          The default load factor.
protected  org.slim3.commons.util.ArrayMap.Entry<K,V>[] mapTable
          The map table.
protected  int size
          The number of entries.
protected  int threshold
          The threshold to extend the capacity.
 
Constructor Summary
ArrayMap()
          Constructor.
ArrayMap(int initialCapacity)
          Constructor.
ArrayMap(Map<? extends K,? extends V> map)
          Constructor.
 
Method Summary
 void clear()
           
 Object clone()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<K,V>> entrySet()
           
 boolean equals(Object o)
           
 V get(int index)
          Returns the value for the index.
 V get(Object key)
           
 org.slim3.commons.util.ArrayMap.Entry<K,V> getEntry(int index)
          Returns the entry for the index.
 K getKey(int index)
          Returns the key for the index.
 int indexOf(Object value)
          Returns the index in the list table.
 boolean isEmpty()
           
 V put(K key, V value)
           
 void putAll(Map<? extends K,? extends V> map)
           
 void readExternal(ObjectInput in)
           
 V remove(int index)
          Removes the entry for the index.
 V remove(Object key)
           
 void set(int index, V value)
          Sets the value for the index.
 int size()
           
 Object[] toArray()
          Converts this object to an array.
 Object[] toArray(Object[] proto)
          Converts this object to an array.
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.util.AbstractMap
hashCode, keySet, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
hashCode, keySet, values
 

Field Detail

INITIAL_CAPACITY

protected static final int INITIAL_CAPACITY
The default initial capacity.

See Also:
Constant Field Values

LOAD_FACTOR

protected static final float LOAD_FACTOR
The default load factor.

See Also:
Constant Field Values

threshold

protected transient int threshold
The threshold to extend the capacity.


mapTable

protected transient org.slim3.commons.util.ArrayMap.Entry<K,V>[] mapTable
The map table.


listTable

protected transient org.slim3.commons.util.ArrayMap.Entry<K,V>[] listTable
The list table.


size

protected transient int size
The number of entries.


entrySet

protected transient Set<Map.Entry<K,V>> entrySet
The set of entries.

Constructor Detail

ArrayMap

public ArrayMap()
Constructor.


ArrayMap

public ArrayMap(int initialCapacity)
Constructor.

Parameters:
initialCapacity - the initial capacity

ArrayMap

public ArrayMap(Map<? extends K,? extends V> map)
Constructor.

Parameters:
map - other map
Method Detail

size

public final int size()
Specified by:
size in interface Map<K,V>
Overrides:
size in class AbstractMap<K,V>

isEmpty

public final boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>
Overrides:
isEmpty in class AbstractMap<K,V>

containsValue

public final boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>
Overrides:
containsValue in class AbstractMap<K,V>

indexOf

public final int indexOf(Object value)
Returns the index in the list table.

Parameters:
value - the value
Returns:
the index

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class AbstractMap<K,V>

get

public V get(Object key)
Specified by:
get in interface Map<K,V>
Overrides:
get in class AbstractMap<K,V>

get

public final V get(int index)
Returns the value for the index.

Parameters:
index - the index
Returns:
the value

getKey

public final K getKey(int index)
Returns the key for the index.

Parameters:
index - the index
Returns:
the key

getEntry

public final org.slim3.commons.util.ArrayMap.Entry<K,V> getEntry(int index)
Returns the entry for the index.

Parameters:
index - the index
Returns:
the entry

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>
Overrides:
put in class AbstractMap<K,V>

set

public final void set(int index,
                      V value)
Sets the value for the index.

Parameters:
index - the index
value - the value

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>
Overrides:
remove in class AbstractMap<K,V>

remove

public final V remove(int index)
Removes the entry for the index.

Parameters:
index - the index
Returns:
the removed value

putAll

public void putAll(Map<? extends K,? extends V> map)
Specified by:
putAll in interface Map<K,V>
Overrides:
putAll in class AbstractMap<K,V>

clear

public final void clear()
Specified by:
clear in interface Map<K,V>
Overrides:
clear in class AbstractMap<K,V>

toArray

public final Object[] toArray()
Converts this object to an array.

Returns:
an array

toArray

public final Object[] toArray(Object[] proto)
Converts this object to an array.

Parameters:
proto - the prototype
Returns:
an array

equals

public final boolean equals(Object o)
Specified by:
equals in interface Map<K,V>
Overrides:
equals in class AbstractMap<K,V>

entrySet

public final Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Specified by:
entrySet in class AbstractMap<K,V>

writeExternal

public final void writeExternal(ObjectOutput out)
                         throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

readExternal

public final void readExternal(ObjectInput in)
                        throws IOException,
                               ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

clone

public Object clone()
Overrides:
clone in class AbstractMap<K,V>


Copyright © 2008-2009 The Slim3 project. All Rights Reserved.