edu.rice.cs.plt.collect
Class AbstractKeyBasedMap<K,V>

java.lang.Object
  extended by edu.rice.cs.plt.collect.AbstractKeyBasedMap<K,V>
All Implemented Interfaces:
LambdaMap<K,V>, Lambda<K,V>, java.util.Map<K,V>
Direct Known Subclasses:
ComposedMap, DictionaryMap, MappedMap, SingletonMap, UnionMap

public abstract class AbstractKeyBasedMap<K,V>
extends java.lang.Object
implements LambdaMap<K,V>

An abstract parent class for Map implementations that defines its operations in terms of the key-based methods get() and keySet(). This is an alternative to AbstractMap, which defines its operations in terms of entrySet() (which is generally more difficult to implement, while its use as a basic operation leads to inefficient behavior). Subclasses must implement get(java.lang.Object) and keySet(); to support mutation, they must also implement put(K, V), remove(java.lang.Object), and clear().


Nested Class Summary
protected  class AbstractKeyBasedMap.EntrySet
          An entry set defined in terms of the enclosing map's other methods.
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
AbstractKeyBasedMap()
           
 
Method Summary
 void clear()
          Throws an UnsupportedOperationException.
 boolean containsKey(java.lang.Object key)
          Returns keySet().contains(key).
 boolean containsValue(java.lang.Object val)
          Returns IterUtil.contains(IterUtil.map(keySet(), this), val).
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
          Returns an instance of AbstractKeyBasedMap.EntrySet.
 boolean equals(java.lang.Object o)
           
abstract  V get(java.lang.Object key)
           
 int hashCode()
           
 boolean isEmpty()
          Returns keySet().isEmpty().
abstract  PredicateSet<K> keySet()
           
protected static
<K,V> java.util.Map.Entry<K,V>
mapEntryForKey(java.util.Map<K,V> map, K key)
          Define a map entry in terms of a map's get() and put() methods.
 V put(K key, V val)
          Throws an UnsupportedOperationException.
 void putAll(java.util.Map<? extends K,? extends V> elts)
          Invokes put(K, V) for each element of the given map's entry set.
 V remove(java.lang.Object key)
          Throws an UnsupportedOperationException.
 int size()
          Returns keySet().size().
 java.lang.String toString()
           
 V value(K key)
          Returns get(key).
 java.util.Collection<V> values()
          Return a collection backed by IterUtil.map(keySet(), this).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractKeyBasedMap

public AbstractKeyBasedMap()
Method Detail

get

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

keySet

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

value

public V value(K key)
Returns get(key).

Specified by:
value in interface Lambda<K,V>

size

public int size()
Returns keySet().size().

Specified by:
size in interface java.util.Map<K,V>

isEmpty

public boolean isEmpty()
Returns keySet().isEmpty().

Specified by:
isEmpty in interface java.util.Map<K,V>

containsKey

public boolean containsKey(java.lang.Object key)
Returns keySet().contains(key).

Specified by:
containsKey in interface java.util.Map<K,V>

containsValue

public boolean containsValue(java.lang.Object val)
Returns IterUtil.contains(IterUtil.map(keySet(), this), val).

Specified by:
containsValue in interface java.util.Map<K,V>

values

public java.util.Collection<V> values()
Return a collection backed by IterUtil.map(keySet(), this).

Specified by:
values in interface java.util.Map<K,V>

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Returns an instance of AbstractKeyBasedMap.EntrySet.

Specified by:
entrySet in interface java.util.Map<K,V>

put

public V put(K key,
             V val)
Throws an UnsupportedOperationException.

Specified by:
put in interface java.util.Map<K,V>

remove

public V remove(java.lang.Object key)
Throws an UnsupportedOperationException.

Specified by:
remove in interface java.util.Map<K,V>

clear

public void clear()
Throws an UnsupportedOperationException.

Specified by:
clear in interface java.util.Map<K,V>

putAll

public void putAll(java.util.Map<? extends K,? extends V> elts)
Invokes put(K, V) for each element of the given map's entry set.

Specified by:
putAll in interface java.util.Map<K,V>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Map<K,V>
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Map<K,V>
Overrides:
hashCode in class java.lang.Object

mapEntryForKey

protected static <K,V> java.util.Map.Entry<K,V> mapEntryForKey(java.util.Map<K,V> map,
                                                               K key)
Define a map entry in terms of a map's get() and put() methods. For the result to be a valid entry in the given map, the map must contain the given key.