org.geotools.util
Class DerivedMap

java.lang.Object
  extended byjava.util.AbstractMap
      extended byorg.geotools.util.DerivedMap
All Implemented Interfaces:
java.util.Map, java.io.Serializable

public abstract class DerivedMap
extends java.util.AbstractMap
implements java.io.Serializable

A map whose keys are derived from an other map. The keys are derived only when requested, which make it possible to backup potentially large maps. Implementations need only to overrides baseToDerived(java.lang.Object) and derivedToBase(java.lang.Object) methods. This set do not supports key, since is used when no mapping from base to exists. This class is serializable if the underlying base set is serializable too.

Since:
2.0
Version:
$Id: DerivedMap.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Serialized Form

Field Summary
protected  java.util.Map base
          The base map whose keys are derived from.
 
Constructor Summary
DerivedMap(java.util.Map base)
          Creates a new derived map from the specified base map.
 
Method Summary
protected abstract  java.lang.Object baseToDerived(java.lang.Object key)
          Transforms a key from the base map to a key in this map.
 boolean containsKey(java.lang.Object key)
          Returns if this map contains a mapping for the specified key.
 boolean containsValue(java.lang.Object value)
          Returns if this map maps one or more keys to this value.
protected abstract  java.lang.Object derivedToBase(java.lang.Object key)
          Transforms a key from this derived map to a key in the base map.
 java.util.Set entrySet()
          Returns a set view of the mappings contained in this map.
 java.lang.Object get(java.lang.Object key)
          Returns the value to which this map maps the specified key.
 boolean isEmpty()
          Returns if this map contains no key-value mappings.
 java.util.Set keySet()
          Returns a set view of the keys contained in this map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified value with the specified key in this map.
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping for this key from this map if present.
 int size()
          Returns the number of key-value mappings in this map.
 java.util.Collection values()
          Returns a collection view of the values contained in this map.
 
Methods inherited from class java.util.AbstractMap
clear, clone, equals, hashCode, putAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

base

protected final java.util.Map base
The base map whose keys are derived from.

See Also:
baseToDerived(java.lang.Object), derivedToBase(java.lang.Object)
Constructor Detail

DerivedMap

public DerivedMap(java.util.Map base)
Creates a new derived map from the specified base map.

Parameters:
base - The base map.
Method Detail

baseToDerived

protected abstract java.lang.Object baseToDerived(java.lang.Object key)
Transforms a key from the base map to a key in this map. If there is no key in the derived map for the specified base key, then this method returns .

Parameters:
key - A ley from the base map.
Returns:
The key that this view should contains instead of , or .

derivedToBase

protected abstract java.lang.Object derivedToBase(java.lang.Object key)
Transforms a key from this derived map to a key in the base map.

Parameters:
key - A key in this map.
Returns:
The key stored in the base map.

size

public int size()
Returns the number of key-value mappings in this map.

Specified by:
size in interface java.util.Map
Returns:
the number of key-value mappings in this map.

isEmpty

public boolean isEmpty()
Returns if this map contains no key-value mappings.

Specified by:
isEmpty in interface java.util.Map
Returns:
if this map contains no key-value mappings.

containsValue

public boolean containsValue(java.lang.Object value)
Returns if this map maps one or more keys to this value. The default implementation invokes base.containsValue(value).

Specified by:
containsValue in interface java.util.Map
Returns:
if this map maps one or more keys to this value.

containsKey

public boolean containsKey(java.lang.Object key)
Returns if this map contains a mapping for the specified key. The default implementation invokes base.containsKey(derivedToBase(key)).

Specified by:
containsKey in interface java.util.Map
Parameters:
key - key whose presence in this map is to be tested.
Returns:
if this map contains a mapping for the specified key.

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which this map maps the specified key. The default implementation invokes base.get(derivedToBase(key)).

Specified by:
get in interface java.util.Map
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
                     throws java.lang.UnsupportedOperationException
Associates the specified value with the specified key in this map. The default implementation invokes base.put(derivedToBase(key), value).

Specified by:
put in interface java.util.Map
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or if there was no mapping for key.
Throws:
java.lang.UnsupportedOperationException - if the base map doesn't supports the operation.

remove

public java.lang.Object remove(java.lang.Object key)
                        throws java.lang.UnsupportedOperationException
Removes the mapping for this key from this map if present. The default implementation invokes base.remove(derivedToBase(key)).

Specified by:
remove in interface java.util.Map
Parameters:
key - key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or if there was no entry for key.
Throws:
java.lang.UnsupportedOperationException - if the base map doesn't supports the operation.

keySet

public java.util.Set keySet()
Returns a set view of the keys contained in this map.

Specified by:
keySet in interface java.util.Map
Returns:
a set view of the keys contained in this map.

values

public java.util.Collection values()
Returns a collection view of the values contained in this map.

Specified by:
values in interface java.util.Map
Returns:
a collection view of the values contained in this map.

entrySet

public java.util.Set entrySet()
Returns a set view of the mappings contained in this map.

Specified by:
entrySet in interface java.util.Map
Returns:
a set view of the mappings contained in this map.


Copyright © GeoTools. All Rights Reserved.