com.odi.util
Class OSHashMap

java.lang.Object
  |
  +--com.odi.util.OSDictionary
        |
        +--com.odi.util.OSHashtable
              |
              +--com.odi.util.OSHashMap
All Implemented Interfaces:
java.lang.Cloneable, IPersistent, IPersistentHooks, java.util.Map, java.io.Serializable

public class OSHashMap
extends OSHashtable
implements java.util.Map

OSHashMap implements the java.util.Map interface with a persistent hash table. Certain operations on OSHashMap that require comparison of objects might cause ObjectStore to throw ReferencedObjectNotFoundException. If this occurs, it indicates that one or more of the key or value objects referenced by the hash table cannot be accessed, most likely because they have been destroyed. The OSHashMap class provides a clearDestroyed() operation that can be used to remove entries that contain these references to these destroyed objects.

Additional information about OSHashMap is in the user guide. Here are exceptions that might be thrown by many of the methods in this class:

DatabaseNotOpenException If the database containing the object is not open.

NoTransactionInProgressException If there is no transaction in progress.

ObjectNotFoundException If the object was not found, either because the object itself, its segment, or its database was destroyed.

ObjectException Ifthe object was local and was fetched in a previous transaction.

ObjectStoreException If the session implied by an argument to the call or the object the method is called on is not the same as the session associated with the current thread.

UpdateReadOnlyException If there is a readonly transaction in progress or if the database is open for readonly.

See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
OSHashMap()
          Constructs a new persistence-capable hash map.
OSHashMap(int initialCapacity)
          Constructs a new persistence-capable hash map.
 
Method Summary
 void clear()
          Removes all entries from the hash table.
 boolean equals(java.lang.Object obj)
          Compares the specified Object with this Map for equality.
 int hashCode()
          Returns the hash code value for this Map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Enters the mapping of a key to a value in the hash table.
 java.lang.Object remove(java.lang.Object key)
          Removes any existing mapping at the specified key.
 boolean removeValue(java.lang.Object value)
          Removes the specified value from the hashtable.
 
Methods inherited from class com.odi.util.OSHashtable
clearContents, clearDestroyed, clone, contains, containsKey, containsKey, containsValue, destroy, elements, entries, entrySet, flushContents, get, get, getKey, getKey, initializeContents, isEmpty, keys, keySet, putAll, rehash, resize, setLoadFactor, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, size, values
 
Methods inherited from interface com.odi.IPersistentHooks
postInitializeContents, preClearContents, preDestroyPersistent, preFlushContents
 
Methods inherited from interface com.odi.IPersistent
ODIgetRef, ODIgetState, ODIsetRef, ODIsetState
 

Constructor Detail

OSHashMap

public OSHashMap(int initialCapacity)
Constructs a new persistence-capable hash map.

Parameters:
initialCapacity - The initial expected capacity requirement for the hash table.

OSHashMap

public OSHashMap()
Constructs a new persistence-capable hash map. A default size is used as the initial hash table capacity.
Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Enters the mapping of a key to a value in the hash table.

Specified by:
put in interface java.util.Map
Overrides:
put in class OSHashtable
Parameters:
key - The identifier for the value.

value - The value being stored in the hash table.

Returns:
The object previously mapped at the specified key, or null.

Throws:
NullPointerException - If either key or value is null.
ReferencedObjectNotFoundException - If an entry key is not found.

remove

public java.lang.Object remove(java.lang.Object key)
Removes any existing mapping at the specified key.

Specified by:
remove in interface java.util.Map
Overrides:
remove in class OSHashtable
Parameters:
key - The key of the object to remove.

Returns:
The object previously mapped at the specified key, or null.

Throws:
NullPointerException - If key is null.
ReferencedObjectNotFoundException - If an entry key is not found.

removeValue

public boolean removeValue(java.lang.Object value)
Removes the specified value from the hashtable. If more than one key maps to this element, the first such mapping that is found is removed.

Overrides:
removeValue in class OSHashtable
Parameters:
value - The element to search for, which must be nonnull.

Returns:
The true constant if the hash table was changed as a result of this operation (that is, if the value was an element of the hashtable). The false constant if the element is not in the hash table.

Throws:
NullPointerException - If value is null.
ReferencedObjectNotFoundException - If an entry value is not found.

clear

public void clear()
Removes all entries from the hash table.
Specified by:
clear in interface java.util.Map
Overrides:
clear in class OSHashtable

equals

public boolean equals(java.lang.Object obj)
Compares the specified Object with this Map for equality. Returns true if the given object is also a Map and the two Maps represent the same mappings. More formally, two Maps t1 and t2 represent the same mappings if t1.keySet().equals(t2.keySet()) and for every key k in t1.keySet(), (t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k))) . Note that this meets the JDK1.2 specification for Map.equals, but that it means that it is not appropriate to store an instance of OSHashMap in any hash-based collection, because its hash code will change if the OSHashMap is modified.
Specified by:
equals in interface java.util.Map
Overrides:
equals in class java.lang.Object
Parameters:
o - Object to be compared for equality with this Map.
Returns:
true if the specified Object is equal to this Map.

hashCode

public int hashCode()
Returns the hash code value for this Map. The hash code of a Map is defined to be the sum of the hashCodes of each Entry in the Map's entries view. This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode() for any two Maps t1 and t2, as required by the general contract of Object.hashCode. Note that this meets the JDK1.2 specification for Map.equals, but that it means that it is not appropriate to store an instance of OSHashMap in any hash-based collection, because its hash code will change if the OSHashMap is modified.

If the com.odi.debugHashCodes system property is set to true, and this method is called from a thread which is not associated with a session, then the method returns an arbitrary value instead of throwing com.odi.NoSessionException. Use this system property setting to permit Java debuggers to print instances of this class.

Specified by:
hashCode in interface java.util.Map
Overrides:
hashCode in class OSDictionary
See Also:
Object.hashCode(), Object.equals(java.lang.Object), Map.equals(java.lang.Object)


Copyright 2004 Progress Software Corporation. All rights reserved.