Class J2MapHandler
- java.lang.Object
-
- org.exolab.castor.mapping.handlers.J2MapHandler
-
- All Implemented Interfaces:
MapHandler
public final class J2MapHandler extends java.lang.Object implements MapHandler
A Map handler for adding and retreiving key-value pairs from A map. A map handler is instantiated only once, must be thread safe and not use any synchronization.- Version:
- $Revision: 5951 $ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
- Author:
- Keith Visco
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
J2MapHandler.IteratorEnumerator
Enumerator for an iterator.
-
Constructor Summary
Constructors Constructor Description J2MapHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear(java.lang.Object map)
Clears the map of all key-value pairs.java.lang.Object
create()
Creates a new Instance of the map represented by this MapHandler.java.util.Enumeration
elements(java.lang.Object map)
Returns an enumeration of all the objects in the Map.java.lang.Object
get(java.lang.Object map, java.lang.Object key)
Returns the object associated with the given key.java.util.Enumeration
keys(java.lang.Object map)
Returns an enumeration of all the keys in the Map.java.lang.Object
put(java.lang.Object map, java.lang.Object key, java.lang.Object object)
Adds the given key-value pair to the map.int
size(java.lang.Object map)
Returns the number of elements (key-value) in the map.
-
-
-
Method Detail
-
create
public java.lang.Object create()
Creates a new Instance of the map represented by this MapHandler.- Specified by:
create
in interfaceMapHandler
- Returns:
- the new map.
-
put
public java.lang.Object put(java.lang.Object map, java.lang.Object key, java.lang.Object object) throws java.lang.ClassCastException
Adds the given key-value pair to the map. Keys must be unique. Adding a key-value pair to the map, when an existing association for that key already exists will cause the existing association to be overwritten. The map is provided as a parameter and is returned as the return value if the returned map is a different object. That way the handler can create a new map if necessary.- Specified by:
put
in interfaceMapHandler
- Parameters:
map
- the map, null if no map has been created yet.key
- the key for the object.object
- the object to add to the map.- Returns:
- The map with the new object if a different instance than the map parameter, null otherwise
- Throws:
java.lang.ClassCastException
- The MapHandler does not support maps of the given type.
-
elements
public java.util.Enumeration elements(java.lang.Object map) throws java.lang.ClassCastException
Returns an enumeration of all the objects in the Map.- Specified by:
elements
in interfaceMapHandler
- Parameters:
map
- The map instance for which to return the enumeration of elements for.- Returns:
- An enumeration of all the elements in the Map.
- Throws:
java.lang.ClassCastException
- The MapHandler does not support collections of this type
-
keys
public java.util.Enumeration keys(java.lang.Object map) throws java.lang.ClassCastException
Returns an enumeration of all the keys in the Map.- Specified by:
keys
in interfaceMapHandler
- Parameters:
map
- The map instance for which to return the enumeration of keys.- Returns:
- An enumeration of all the keys in the Map.
- Throws:
java.lang.ClassCastException
- The MapHandler does not support collections of this type
-
size
public int size(java.lang.Object map) throws java.lang.ClassCastException
Returns the number of elements (key-value) in the map.- Specified by:
size
in interfaceMapHandler
- Parameters:
map
- the map.- Returns:
- Number of key-value associations in the Map
- Throws:
java.lang.ClassCastException
- The MapHandler does not support collections of the given type.
-
clear
public void clear(java.lang.Object map) throws java.lang.ClassCastException
Clears the map of all key-value pairs.- Specified by:
clear
in interfaceMapHandler
- Parameters:
map
- the map to clear.- Throws:
java.lang.ClassCastException
- The MapHandler does not support collections of the given type.
-
get
public java.lang.Object get(java.lang.Object map, java.lang.Object key) throws java.lang.ClassCastException
Returns the object associated with the given key.- Specified by:
get
in interfaceMapHandler
- Parameters:
map
- the map to return the object from.key
- the key for the object.- Returns:
- the object associated with the given key, or null if no association was found in the given map.
- Throws:
java.lang.ClassCastException
- The MapHandler does not support maps of the given type.
-
-