org.rutil.collection.map
Class IndexedMap<K,V>

java.lang.Object
  extended by org.rutil.collection.map.IndexedMap<K,V>
All Implemented Interfaces:
java.io.Serializable, java.util.Map<K,V>

public class IndexedMap<K,V>
extends java.lang.Object
implements java.util.Map<K,V>, java.io.Serializable

The key/value storage/retrival is managed by an externalized interface, IndexedMapIndexer. So, the performance of the read/wite methods are directly dependent on the implemenation of IndexedMapIndexer used by this map. Even though this map supports the method keySet, its recommended to use keys() method to find the keys. If the indexer is a sorting indexer that sorts by value (instead of key), keys may not be unique. The actual order in which keys/values stored is preserved even in methods that return an instanceof Set (like keySet()).

Author:
mohan
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
protected  IndexedMapIndexer<K,V> keyIndexer
           
protected  java.util.List<K> keyList
           
protected  java.util.List<V> valueList
           
 
Constructor Summary
protected IndexedMap()
           
  IndexedMap(IndexedMapIndexer<K,V> keyIndexer)
           
 
Method Summary
protected  boolean areEqual(java.util.List list, int index, java.lang.Object value)
           
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
           
 V get(java.lang.Object key)
           
protected  int getIndexerIndex(K key, V value)
           
 boolean isEmpty()
           
 java.util.Collection<K> keys()
           
 java.util.Set<K> keySet()
           
 V put(K key, V value)
           
 void putAll(java.util.Map<? extends K,? extends V> m)
           
 V remove(java.lang.Object key)
           
 java.util.Collection<K> removeKeys(int numItems)
           
 int size()
           
 java.util.Collection<V> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

keyList

protected java.util.List<K> keyList

valueList

protected java.util.List<V> valueList

keyIndexer

protected IndexedMapIndexer<K,V> keyIndexer
Constructor Detail

IndexedMap

protected IndexedMap()

IndexedMap

public IndexedMap(IndexedMapIndexer<K,V> keyIndexer)
Method Detail

put

public V put(K key,
             V value)
Specified by:
put in interface java.util.Map<K,V>

size

public int size()
Specified by:
size in interface java.util.Map<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<K,V>

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<K,V>

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<K,V>

get

public V get(java.lang.Object key)
Specified by:
get in interface java.util.Map<K,V>

areEqual

protected boolean areEqual(java.util.List list,
                           int index,
                           java.lang.Object value)

remove

public V remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<K,V>

clear

public void clear()
Specified by:
clear in interface java.util.Map<K,V>

keys

public java.util.Collection<K> keys()

keySet

public java.util.Set<K> keySet()
Specified by:
keySet in interface java.util.Map<K,V>

values

public java.util.Collection<V> values()
Specified by:
values in interface java.util.Map<K,V>

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface java.util.Map<K,V>

putAll

public void putAll(java.util.Map<? extends K,? extends V> m)
Specified by:
putAll in interface java.util.Map<K,V>

removeKeys

public java.util.Collection<K> removeKeys(int numItems)

getIndexerIndex

protected int getIndexerIndex(K key,
                              V value)