GNU Trove

gnu.trove.decorator
Class TIntObjectMapDecorator<V>

java.lang.Object
  extended by java.util.AbstractMap<java.lang.Integer,V>
      extended by gnu.trove.decorator.TIntObjectMapDecorator<V>
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Integer,V>

public class TIntObjectMapDecorator<V>
extends java.util.AbstractMap<java.lang.Integer,V>
implements java.util.Map<java.lang.Integer,V>, java.io.Externalizable, java.lang.Cloneable

Wrapper class to make a TIntObjectMap conform to the java.util.Map API. This class simply decorates an underlying TIntObjectMap and translates the Object-based APIs into their Trove primitive analogs.

Note that wrapping and unwrapping primitive values is extremely inefficient. If possible, users of this class should override the appropriate methods in this class and use a table of canonical values.

Created: Mon Sep 23 22:07:40 PDT 2002

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
protected  TIntObjectMap<V> _map
          the wrapped primitive map
 
Constructor Summary
TIntObjectMapDecorator()
          FOR EXTERNALIZATION ONLY!!
TIntObjectMapDecorator(TIntObjectMap<V> map)
          Creates a wrapper that decorates the specified primitive map.
 
Method Summary
 void clear()
          Empties the map.
 boolean containsKey(java.lang.Object key)
          Checks for the present of key in the keys of the map.
 boolean containsValue(java.lang.Object val)
          Checks for the presence of val in the values of the map.
 java.util.Set<java.util.Map.Entry<java.lang.Integer,V>> entrySet()
          Returns a Set view on the entries of the map.
 V get(java.lang.Object key)
          Retrieves the value for key
 TIntObjectMap<V> getMap()
          Returns a reference to the map wrapped by this decorator.
 boolean isEmpty()
          Indicates whether map has any entries.
 V put(java.lang.Integer key, V value)
          Inserts a key/value pair into the map.
 void putAll(java.util.Map<? extends java.lang.Integer,? extends V> map)
          Copies the key/value mappings in map into this map.
 void readExternal(java.io.ObjectInput in)
           
 V remove(java.lang.Object key)
          Deletes a key/value pair from the map.
 int size()
          Returns the number of entries in the map.
protected  int unwrapKey(java.lang.Integer key)
          Unwraps a key
protected  java.lang.Integer wrapKey(int k)
          Wraps a key
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, keySet, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, keySet, values
 

Field Detail

_map

protected TIntObjectMap<V> _map
the wrapped primitive map

Constructor Detail

TIntObjectMapDecorator

public TIntObjectMapDecorator()
FOR EXTERNALIZATION ONLY!!


TIntObjectMapDecorator

public TIntObjectMapDecorator(TIntObjectMap<V> map)
Creates a wrapper that decorates the specified primitive map.

Parameters:
map - the TIntObjectMap to wrap.
Method Detail

getMap

public TIntObjectMap<V> getMap()
Returns a reference to the map wrapped by this decorator.

Returns:
the wrapped TIntObjectMap instance.

put

public V put(java.lang.Integer key,
             V value)
Inserts a key/value pair into the map.

Specified by:
put in interface java.util.Map<java.lang.Integer,V>
Overrides:
put in class java.util.AbstractMap<java.lang.Integer,V>
Parameters:
key - an Integer value
value - an Object value
Returns:
the previous value associated with key, or null if none was found.

get

public V get(java.lang.Object key)
Retrieves the value for key

Specified by:
get in interface java.util.Map<java.lang.Integer,V>
Overrides:
get in class java.util.AbstractMap<java.lang.Integer,V>
Parameters:
key - an Object value
Returns:
the value of key or null if no such mapping exists.

clear

public void clear()
Empties the map.

Specified by:
clear in interface java.util.Map<java.lang.Integer,V>
Overrides:
clear in class java.util.AbstractMap<java.lang.Integer,V>

remove

public V remove(java.lang.Object key)
Deletes a key/value pair from the map.

Specified by:
remove in interface java.util.Map<java.lang.Integer,V>
Overrides:
remove in class java.util.AbstractMap<java.lang.Integer,V>
Parameters:
key - an Object value
Returns:
the removed value, or Integer(0) if it was not found in the map

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.Integer,V>> entrySet()
Returns a Set view on the entries of the map.

Specified by:
entrySet in interface java.util.Map<java.lang.Integer,V>
Specified by:
entrySet in class java.util.AbstractMap<java.lang.Integer,V>
Returns:
a Set value

containsValue

public boolean containsValue(java.lang.Object val)
Checks for the presence of val in the values of the map.

Specified by:
containsValue in interface java.util.Map<java.lang.Integer,V>
Overrides:
containsValue in class java.util.AbstractMap<java.lang.Integer,V>
Parameters:
val - an Object value
Returns:
a boolean value

containsKey

public boolean containsKey(java.lang.Object key)
Checks for the present of key in the keys of the map.

Specified by:
containsKey in interface java.util.Map<java.lang.Integer,V>
Overrides:
containsKey in class java.util.AbstractMap<java.lang.Integer,V>
Parameters:
key - an Object value
Returns:
a boolean value

size

public int size()
Returns the number of entries in the map.

Specified by:
size in interface java.util.Map<java.lang.Integer,V>
Overrides:
size in class java.util.AbstractMap<java.lang.Integer,V>
Returns:
the map's size.

isEmpty

public boolean isEmpty()
Indicates whether map has any entries.

Specified by:
isEmpty in interface java.util.Map<java.lang.Integer,V>
Overrides:
isEmpty in class java.util.AbstractMap<java.lang.Integer,V>
Returns:
true if the map is empty

putAll

public void putAll(java.util.Map<? extends java.lang.Integer,? extends V> map)
Copies the key/value mappings in map into this map. Note that this will be a deep copy, as storage is by primitive value.

Specified by:
putAll in interface java.util.Map<java.lang.Integer,V>
Overrides:
putAll in class java.util.AbstractMap<java.lang.Integer,V>
Parameters:
map - a Map value

wrapKey

protected java.lang.Integer wrapKey(int k)
Wraps a key

Parameters:
k - key in the underlying map
Returns:
an Object representation of the key

unwrapKey

protected int unwrapKey(java.lang.Integer key)
Unwraps a key

Parameters:
key - wrapped key
Returns:
an unwrapped representation of the key

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

GNU Trove