tip.util
Class EqualityMap<K,V>

java.lang.Object
  extended by tip.util.EqualityMap<K,V>
Type Parameters:
K - the type of the keys
V - the type of the values
All Implemented Interfaces:
Map<K,V>

public class EqualityMap<K,V>
extends Object
implements Map<K,V>

EqualityMap implements a Map where equality of key elements can be abstracted using an Equalitor, i.e. key elements are in the set are regarded as equal based on Equalitor.equals(Object, Object).

Author:
Johnni Winther, jw@brics.dk

Constructor Summary
EqualityMap()
          Creates a new empty map using IdentityEqualitor as equalitor on key elements.
EqualityMap(Equalitor<K> equalitor)
          Create a new empty map using equalitor as equalitor on key elements.
 
Method Summary
 void clear()
          
 EqualityMap<K,V> clone()
          
 boolean containsKey(Object key)
          
 boolean containsValue(Object value)
          
 Set<Map.Entry<K,V>> entrySet()
          
 boolean equals(Object o)
          
 V get(Object key)
          
 Equalitor<K> getEqualitor()
          Returns the Equalitor used for equality on key elements.
 int hashCode()
          
 boolean isEmpty()
          
 EqualitySet<K> keySet()
          
 V put(K key, V value)
          
 void putAll(Map<? extends K,? extends V> t)
          
 V remove(Object key)
          
 int size()
          
 String toString()
          
 String toString(Collection<K> keySet, Stringifier<K> keyStringifier, Stringifier<V> valueStringifier)
          Returns a text representation of a subset of the keys in the map using the keyStringifier and valueStringifier.
 String toString(Stringifier<K> keyStringifier, Stringifier<V> valueStringifier)
          Returns a text representation of the map using the keyStringifier and valueStringifier.
 Collection<V> values()
          
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EqualityMap

public EqualityMap()
Creates a new empty map using IdentityEqualitor as equalitor on key elements.


EqualityMap

public EqualityMap(Equalitor<K> equalitor)
Create a new empty map using equalitor as equalitor on key elements.

Parameters:
equalitor - the Equalitor used for equality on key elements
Throws:
{@link - IllegalArgumentException} if equalitor is null
Method Detail

clear

public void clear()

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

clone

public EqualityMap<K,V> clone()

Overrides:
clone in class Object

containsKey

public boolean containsKey(Object key)

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

containsValue

public boolean containsValue(Object value)

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

entrySet

public Set<Map.Entry<K,V>> entrySet()

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

equals

public boolean equals(Object o)

Specified by:
equals in interface Map<K,V>
Overrides:
equals in class Object

get

public V get(Object key)

Specified by:
get in interface Map<K,V>

getEqualitor

public Equalitor<K> getEqualitor()
Returns the Equalitor used for equality on key elements.

Returns:
the Equalitor used for equality on key elements

hashCode

public int hashCode()

Specified by:
hashCode in interface Map<K,V>
Overrides:
hashCode in class Object

isEmpty

public boolean isEmpty()

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

keySet

public EqualitySet<K> keySet()

Specified by:
keySet in interface Map<K,V>

put

public V put(K key,
             V value)

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

putAll

public void putAll(Map<? extends K,? extends V> t)

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

remove

public V remove(Object key)

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

size

public int size()

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

toString

public String toString()

Overrides:
toString in class Object

toString

public String toString(Stringifier<K> keyStringifier,
                       Stringifier<V> valueStringifier)
Returns a text representation of the map using the keyStringifier and valueStringifier.

Parameters:
keyStringifier - the Stringifier used for key elements
valueStringifier - the Stringifier used for values
Returns:
a text representation of the set using the stringifiers

toString

public String toString(Collection<K> keySet,
                       Stringifier<K> keyStringifier,
                       Stringifier<V> valueStringifier)
Returns a text representation of a subset of the keys in the map using the keyStringifier and valueStringifier.

Parameters:
keyStringifier - the Stringifier used for key elements
valueStringifier - the Stringifier used for values
Returns:
a text representation of the set using the stringifiers

values

public Collection<V> values()

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