com.myjavatools.lib.foundation
Class AbstractMap2<X,Y,V>

java.lang.Object
  extended by com.myjavatools.lib.foundation.AbstractMap2<X,Y,V>
All Implemented Interfaces:
Map2<X,Y,V>
Direct Known Subclasses:
IndexedMap2

public abstract class AbstractMap2<X,Y,V>
extends java.lang.Object
implements Map2<X,Y,V>

AbstractMap2 is a partial implementation of two-parameter map.

Copyright: This is public domain; The right of people to use, distribute, copy or improve the contents of the following may not be restricted.

Company: My Java Tools

Version:
6.0 12/10/2006

Nested Class Summary
static class AbstractMap2.Entry<X,Y,V>
          An entry of a two-parameter map.
 
Constructor Summary
AbstractMap2()
          Default constructor
 
Method Summary
 void clear()
          Removes all mappings from this map. This implementation calls entrySet().clear().
 boolean containsKeyPair(java.lang.Object key1, java.lang.Object key2)
          Returns true if this map contains a mapping for the specified key pair. This implementation iterates over entrySet() searching for an entry with the specified keys.
 boolean containsValue(java.lang.Object value)
          
 java.util.Map<Y,V> curry1(X key1)
          Currying by first argument. This implementation builds the map on every call.
 java.util.Map<X,V> curry2(Y key2)
          Currying by second argument. This implementation builds the map on every call.
abstract  java.util.Set<Map2.Entry<X,Y,V>> entrySet()
          Returns a set view of the mappings contained in this map.
protected static boolean equal(java.lang.Object o1, java.lang.Object o2)
           
 boolean equals(java.lang.Object o)
          Compares the specified object with this map for equality.
 V get(X key1, Y key2)
          Returns the value to which this map maps the specified key pair, and null if the map contains no mapping for these keys. This implementation iterates over entrySet() searching for an entry with the specified pair of keys.
 int hashCode()
           
 boolean isEmpty()
          
abstract  java.util.Set<X> keySet1()
          A Map2 has two sets of keys, first component and second component.
abstract  java.util.Set<Y> keySet2()
          A Map2 has two sets of keys, first component and second component.
 V put(X key1, Y key2, V value)
          Associates the specified value with the specified key pair. This implementation always throws an UnsupportedOperationException.
 void putAll(Map2<? extends X,? extends Y,? extends V> source)
          Copies all of the mappings from the specified map to this map. This implementation iterates over the specified map's entrySet() collection, and calls this map's put operation once for each entry returned by the iteration.
 V remove(X key1, Y key2)
          Removes the mapping for this key pair from this map if it is present. This implementation iterates over entrySet() searching for an entry with the specified pair of keys.
 int size()
          
 java.lang.String toString()
           
 java.util.Collection<V> values()
          Returns a collection view of the values contained in this map. This implementation returns a collection and is based on the map's entrySet.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractMap2

public AbstractMap2()
Default constructor

Method Detail

equal

protected static boolean equal(java.lang.Object o1,
                               java.lang.Object o2)

size

public int size()

Specified by:
size in interface Map2<X,Y,V>
Returns:
the number of key-value mappings in this map.

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface Map2<X,Y,V>
Returns:
true if this map contains no key-value mappings.

containsValue

public boolean containsValue(java.lang.Object value)


containsKeyPair

public boolean containsKeyPair(java.lang.Object key1,
                               java.lang.Object key2)
Returns true if this map contains a mapping for the specified key pair. This implementation iterates over entrySet() searching for an entry with the specified keys. If such an entry is found, true is returned. If the iteration terminates without finding such an entry, false is returned. Note that this implementation requires linear time in the size of the map; many implementations will override this method.

Specified by:
containsKeyPair in interface Map2<X,Y,V>
Parameters:
key1 - first key
key2 - second key
Returns:
true if this map contains a mapping for the specified pair of keys.

get

public V get(X key1,
             Y key2)
Returns the value to which this map maps the specified key pair, and null if the map contains no mapping for these keys. This implementation iterates over entrySet() searching for an entry with the specified pair of keys. If such an entry is found, the entry's value is returned. If the iteration terminates without finding such an entry, null is returned. Note that this implementation requires linear time in the size of the map; many implementations will override this method.

Specified by:
get in interface Map2<X,Y,V>
Parameters:
key1 - first key
key2 - second key
Returns:
the value to which this map maps the specified keys.
See Also:
#containsKeyPair(X,Y)

put

public V put(X key1,
             Y key2,
             V value)
Associates the specified value with the specified key pair. If the map previously contained a mapping for this key pair, the old value is replaced by the specified value. This implementation always throws an UnsupportedOperationException.

Specified by:
put in interface Map2<X,Y,V>
Parameters:
key1 - first key.
key2 - second key.
value - value to be associated with the specified key pair.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

remove

public V remove(X key1,
                Y key2)
Removes the mapping for this key pair from this map if it is present.

Returns the value to which the map previously associated the keys, or null if the map contained no mapping for this key pair. This implementation iterates over entrySet() searching for an entry with the specified pair of keys. If such an entry is found, its value is obtained with its getValue operation, the entry is removed from the collection of entries with the iterator's remove operation, and the saved value is returned. If the iteration terminates without finding such an entry, null is returned. Note that this implementation requires linear time in the size of the map; many implementations will override this method.

Specified by:
remove in interface Map2<X,Y,V>
Parameters:
key1 - first key.
key2 - second key.
Returns:
previous value, or null if there was no mapping for key.

putAll

public void putAll(Map2<? extends X,? extends Y,? extends V> source)
Copies all of the mappings from the specified map to this map. This implementation iterates over the specified map's entrySet() collection, and calls this map's put operation once for each entry returned by the iteration.

Specified by:
putAll in interface Map2<X,Y,V>

clear

public void clear()
Removes all mappings from this map. This implementation calls entrySet().clear().

Specified by:
clear in interface Map2<X,Y,V>

keySet1

public abstract java.util.Set<X> keySet1()
Description copied from interface: Map2
A Map2 has two sets of keys, first component and second component. This method returns an unmodifiable set view of the set of keys of the first component. The set is backed by the map, so changes to the map are reflected in the set. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined.

Specified by:
keySet1 in interface Map2<X,Y,V>
Returns:
an unmodifiable set view of the keys contained in this map.

keySet2

public abstract java.util.Set<Y> keySet2()
Description copied from interface: Map2
A Map2 has two sets of keys, first component and second component. This method returns an unmodifiable set view of the set of keys of the second component. The set is backed by the map, so changes to the map are reflected in the set. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined.

Specified by:
keySet2 in interface Map2<X,Y,V>
Returns:
an unmodifiable set view of the keys contained in this map.

values

public java.util.Collection<V> values()
Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined. This implementation returns a collection and is based on the map's entrySet.

Specified by:
values in interface Map2<X,Y,V>
Returns:
a collection view of the values contained in this map.

curry1

public java.util.Map<Y,V> curry1(X key1)
Currying by first argument. Produces a map that for each Y key2 returns the same value as get(key1, key2) would return. If key1 is not present in the set of keys, an empty map is returned. This implementation builds the map on every call. Better implementations are available if entries are indexed.

Specified by:
curry1 in interface Map2<X,Y,V>
Parameters:
key1 - X
Returns:
Map resulting map.

curry2

public java.util.Map<X,V> curry2(Y key2)
Currying by second argument. Produces a map that for each X key1 returns the same value as get(key1, key2) would return. If key2 is not present in the set of keys, an empty map is returned. This implementation builds the map on every call. Better implementations are available if entries are indexed.

Specified by:
curry2 in interface Map2<X,Y,V>
Parameters:
key2 - X
Returns:
Map resulting map.

entrySet

public abstract java.util.Set<Map2.Entry<X,Y,V>> entrySet()
Returns a set view of the mappings contained in this map. Each element in the returned set is a Map2.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.

Specified by:
entrySet in interface Map2<X,Y,V>
Returns:
a set view of the mappings contained in this map.

equals

public boolean equals(java.lang.Object o)
Compares the specified object with this map for equality. Returns true if the given object is also a map2 and the two maps represent the same mappings.

Overrides:
equals in class java.lang.Object
Parameters:
o - object to be compared for equality with this map.
Returns:
true if the specified object is equal to this map.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value for this map.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a String representation of this map.