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

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

public abstract class IndexedMap2<X,Y,V>
extends AbstractMap2<X,Y,V>

IndexedMap2 is an abstract class that implements a two-parameter map with indexes for both parameters.

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
 
Nested classes/interfaces inherited from class com.myjavatools.lib.foundation.AbstractMap2
AbstractMap2.Entry<X,Y,V>
 
Constructor Summary
IndexedMap2()
          Default constructor.
 
Method Summary
 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. This implementation uses index to check for key pair presence.
 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. This implementation uses the index to return a Map<Y,V> view of Map<Y,Entry<X,Y,Z>> map that is stored in index.
 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. This implementation uses the index to return a Map<X,V> view of Map<Y,Entry<X,Y,Z>> map that is stored in index.
protected  java.util.Map<Y,AbstractMap2.Entry<X,Y,V>> ensureSlot1(X key1)
           
protected  java.util.Map<X,AbstractMap2.Entry<X,Y,V>> ensureSlot2(Y key2)
           
 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. This implementation uses two indexes.
protected  AbstractMap2.Entry<X,Y,V> getEntry(java.lang.Object key1, java.lang.Object key2)
           
 java.util.Set<X> keySet1()
          A Map2 has two sets of keys, first component and second component. This implementation returns a Set that subclasses AbstractSet and is based on the map's entrySet.
 java.util.Set<Y> keySet2()
          A Map2 has two sets of keys, first component and second component. This implementation returns a Set that subclasses AbstractSet and is based on the map's entrySet.
 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. This implementation uses and updates two indexes.
 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. This implementation uses index to retrieve an entry with the specified pair of keys.

 
Methods inherited from class com.myjavatools.lib.foundation.AbstractMap2
clear, containsValue, entrySet, equal, equals, hashCode, isEmpty, putAll, size, toString, values
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IndexedMap2

public IndexedMap2()
Default constructor.

Method Detail

getEntry

protected AbstractMap2.Entry<X,Y,V> getEntry(java.lang.Object key1,
                                             java.lang.Object key2)

ensureSlot1

protected java.util.Map<Y,AbstractMap2.Entry<X,Y,V>> ensureSlot1(X key1)

ensureSlot2

protected java.util.Map<X,AbstractMap2.Entry<X,Y,V>> ensureSlot2(Y key2)

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. This implementation uses two indexes.

Specified by:
get in interface Map2<X,Y,V>
Overrides:
get in class AbstractMap2<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. This implementation uses and updates two indexes.

Specified by:
put in interface Map2<X,Y,V>
Overrides:
put in class AbstractMap2<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.

keySet1

public java.util.Set<X> keySet1()
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. This implementation returns a Set that subclasses AbstractSet and is based on the map's entrySet.

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

keySet2

public java.util.Set<Y> keySet2()
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. This implementation returns a Set that subclasses AbstractSet and is based on the map's entrySet.

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

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. This implementation uses index to check for key pair presence.

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

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.

This implementation uses index to retrieve an entry with the specified pair of keys.

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

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. This implementation uses the index to return a Map<Y,V> view of Map<Y,Entry<X,Y,Z>> map that is stored in index.

Specified by:
curry1 in interface Map2<X,Y,V>
Overrides:
curry1 in class AbstractMap2<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. This implementation uses the index to return a Map<X,V> view of Map<Y,Entry<X,Y,Z>> map that is stored in index.

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