ptolemy.graph.mapping
Class ToIntMapMapping

java.lang.Object
  extended by ptolemy.graph.mapping.MapMapping
      extended by ptolemy.graph.mapping.ToIntMapMapping
All Implemented Interfaces:
Mapping, ToIntMapping

public class ToIntMapMapping
extends MapMapping
implements ToIntMapping

A ToIntMapping that is based on a Map. The values in the Map must be instances of Integer. ToIntMapMappings are immutable in the sense that the underlying Map cannot be changed (although the keys and values associated with the Map can be changed).

Since:
Ptolemy II 4.0
Version:
$Id: ToIntMapMapping.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Shuvra S. Bhattacharyya
Accepted Rating:
Red (ssb)
Proposed Rating:
Red (ssb)

Field Summary
 
Fields inherited from class ptolemy.graph.mapping.MapMapping
_map
 
Constructor Summary
ToIntMapMapping(java.util.Map map)
          Construct a ToIntMapMapping from a given map.
 
Method Summary
 boolean inDomain(java.lang.Object object)
          Return true if the given object is in the domain of this Mapping.
 int toInt(java.lang.Object object)
          Return the int value that is associated with given object under this mapping.
 java.lang.Object toObject(java.lang.Object object)
          Return the object associated with the given object in the mapping.
 
Methods inherited from class ptolemy.graph.mapping.MapMapping
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ToIntMapMapping

public ToIntMapMapping(java.util.Map map)
Construct a ToIntMapMapping from a given map. The values in the must be instances of Integer; otherwise, unpredictable behavior may result. Modifications to the argument Map after construction of this mapping will be reflected in the mapping. The Map modifications must follow the restriction that all added values to the Map must be instances of Integer.

Parameters:
map - The given map.
Method Detail

inDomain

public boolean inDomain(java.lang.Object object)
Return true if the given object is in the domain of this Mapping. More precisely, return true if the given object is a valid argument to toInt(Object), which means that the object is a key in the Map that is associated with this Mapping and the value in the Map is an instance of Integer.

Specified by:
inDomain in interface Mapping
Overrides:
inDomain in class MapMapping
Parameters:
object - The given object.
Returns:
True if the given object is in the domain of this Mapping.

toInt

public int toInt(java.lang.Object object)
Return the int value that is associated with given object under this mapping. For efficiency, no error checking is performed on the argument, and consequently, a runtime exception may result as noted below. To perform argument validity checking before mapping an object, use Mapping.inDomain(Object).

Specified by:
toInt in interface ToIntMapping
Parameters:
object - The given object.
Returns:
The int value that is associated with given object under this mapping.
Throws:
java.lang.RuntimeException - If the given object is not an instance of Integer or if the given object is not in the domain of the mapping.

toObject

public java.lang.Object toObject(java.lang.Object object)
Description copied from interface: Mapping
Return the object associated with the given object in the mapping.

Specified by:
toObject in interface Mapping
Parameters:
object - The given object.
Returns:
Return the object associated with the given object in the mapping.