Class COM.odi.util.OSTreeMap
java.lang.Object
|
+----COM.odi.util.OSTreeMap
- public class OSTreeMap
- extends Object
- implements IPersistent, Map
OSTreeMap is an abstract class that implements the COM.odi.util.Map
interface with a persistent B-tree. Note that instances of (subclasses
of) this class must be persistent.
This class is included in PSE Pro, but not in PSE.
Additional information about OSTreeMap
is in the user guide.
The keys are Objects and the values are Objects. Any concrete
subclass of OSTreeMap must implement the following two
methods, to translate object-keys into byte arrays (the internal
format the the B-tree stores):
byte[] keyToByteArray(Object key, byte[] keyEncoding);
Object byteArrayToKey(byte[] keyEncoding);
The following exceptions 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; or because the OSTreeMap was created in
a transaction that was subsequently aborted.
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.
-
OSTreeMap(Placement, int, boolean, boolean)
- Creates an OSTreeMap.
-
byteArrayToKey(byte[])
-
Decodes a byte-array encoding of a key into an instance of the key type.
-
clear()
- Removes all mappings from this Map.
-
contains(Object)
- Returns true if this Map maps one or more keys to this value.
-
containsKey(Object)
- Returns true if this Map contains a mapping for the specified key.
-
containsValue(Object)
- Returns true if this Map maps one or more keys to this value.
-
entries()
- Returns a Collection view of the mappings contained in this Map.
-
equals(Object)
- Compares the specified Object with this Map for equality.
-
get(Object)
- Returns the value to which this Map maps the specified key.
-
hashCode()
- UNSUPPORTED IN THIS RELEASE OF PSE.
-
isEmpty()
- Returns true if this Map contains no key-value mappings.
-
isSizeMaintained()
- Determines if this map maintains its size.
-
keySet()
- Returns a Set view of the keys contained in this Map.
-
keyToByteArray(Object, byte[])
-
Encodes a key into a byte array.
-
maintainSize(boolean)
- Modifies the map to maintain or not maintain information about its size.
-
put(Object, Object)
- Associates the specified value with the specified key in this Map
(optional operation).
-
putAll(Map)
- Copies all of the mappings from the specified Map to this Map.
-
remove(Object)
- Removes the mapping for this key from this Map if present (optional
operation).
-
size()
- Returns the number of key-value mappings in this Map.
-
sizeEstimate()
- For maps that do not maintain their size, returns the size computed by the
last call to size().
-
values()
- Returns a Collection view of the values contained in this Map.
OSTreeMap
protected OSTreeMap(Placement placement,
int keySize,
boolean fixedSizeKeys,
boolean export)
- Creates an OSTreeMap. Note that the database containing the placement needs
to be open for update and an update transaction needs to be in progress.
- Parameters:
- placement - The database or segment in which to create the OSTreeMap.
- keySize - The size of the key -- must be a number greater than 0. If
variable size keys are permitted, this is the size key which can be stored
without using overflow storage. Note that three combinations of key size
and key variability are handled specially to provide better efficiency: 4
and 8 byte fixed sized keys, and 28 byte variable sized keys.
- fixedSizeKeys - True indicates that the keys have a fixed maximum length
of keySize (keys smaller than this fixed maximum behave as if they were padded
with zeros to keySize);
false indicates that the keys are of variable length, in which case the keySize
is interpreted as the size that the btree should attempt to store without recourse
to overflow key storage.
- export - If true, make the map an exported object.
- Throws: NoTransactionInProgressException
- If no transaction is in
progress.
- Throws: ObjectStoreException
- If the current thread is not associated
with a session and there is no global session.
- Throws: UpdateReadOnlyException
- If there is a read-only transaction in
progress or if the database is open read-only.
size
public int size()
- Returns the number of key-value mappings in this Map.
sizeEstimate
public int sizeEstimate()
- For maps that do not maintain their size, returns the size computed by the
last call to size(). For other maps, does the same thing as size().
- Returns:
- The estimated size.
- See Also:
- isSizeMaintained, maintainSize
isSizeMaintained
public boolean isSizeMaintained()
- Determines if this map maintains its size.
- Returns:
- True if the map maintains its size, otherwise false.
- See Also:
- sizeEstimate, maintainSize
maintainSize
public void maintainSize(boolean maintainSize)
- Modifies the map to maintain or not maintain information about its size.
Maps maintain their size by default. For maps that maintain their size,
putting or removing entries from the map requires a write lock on the top
of the tree, which produces a concurrency hot-spot when using ObjectStore.
Maps that do not maintain their size do not have this concurrency problem
for putting or removing entries, but need to scan the entire tree to
determine the size.
Note that iterators on maps which do not maintain their size do not detect
concurrent modifications.
- Parameters:
- maintainSize - If true, causes the map to maintain its size. If
false, causes the map to not maintain its size.
- See Also:
- sizeEstimate, isSizeMaintained
isEmpty
public boolean isEmpty()
- Returns true if this Map contains no key-value mappings.
containsValue
public boolean containsValue(Object value)
- Returns true if this Map maps one or more keys to this value.
More formally, returns true if and only if this Map contains at
least one mapping to a value
v
such that
(value==null ? v==null : value.equals(v))
.
- Parameters:
- value - value whose presence in this Map is to be tested.
contains
public boolean contains(Object value)
- Returns true if this Map maps one or more keys to this value.
Same as containsValue.
containsKey
public boolean containsKey(Object key)
- Returns true if this Map contains a mapping for the specified key.
- Parameters:
- key - key whose presence in this Map is to be tested.
get
public Object get(Object key)
- Returns the value to which this Map maps the specified key.
Returns null if the Map contains no mapping for this key. A return
value of null does not necessarily indicate that the Map
contains no mapping for the key; it's also possible that the Map
explicitly maps the key to null. The containsKey operation may be
used to distinguish these two cases.
- Parameters:
- key - key whose associated value is to be returned.
- See Also:
- containsKey
put
public Object put(Object key,
Object value)
- Associates the specified value with the specified key in this Map
(optional operation). If the Map previously contained a mapping for
this key, the old value is replaced.
- 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 null if there
was no mapping for key. (A null return can also indicate that
the Map previously associated null with the specified key,
if the implementation supports null values.)
- Throws: ClassCastException
- class of the specified key or value
prevents it from being stored in this Map.
- Throws: IllegalArgumentException
- some aspect of this key or value
prevents it from being stored in this Map.
- Throws: NullPointerException
- this Map does not permit null keys
or values, and the specified key or value is null.
remove
public Object remove(Object key)
- Removes the mapping for this key from this Map if present (optional
operation).
- Parameters:
- key - key whose mapping is to be removed from the Map.
- Returns:
- previous value associated with specified key, or null if there
was no mapping for key. (A null return can also indicate that
the Map previously associated null with the specified key,
if the implementation supports null values.)
putAll
public void putAll(Map m)
- Copies all of the mappings from the specified Map to this Map.
These mappings will replace any mappings that
this Map had for any of the keys currently in the specified Map.
- Parameters:
- t - Mappings to be stored in this Map.
- Throws: ClassCastException
- class of a key or value in the specified
Map prevents it from being stored in this Map.
- Throws: IllegalArgumentException
- some aspect of a key or value in the
specified Map prevents it from being stored in this Map.
- Throws: NullPointerException
- this Map does not permit null keys
or values, and the specified key or value is null.
clear
public void clear()
- Removes all mappings from this Map.
keySet
public Set keySet()
- Returns a Set view of the keys contained in this Map. The Set is
backed by the Map, so changes to the Map are reflected in the Set,
and vice-versa. (If the Map is modified while while an iteration over
the Set is in progress, the results of the iteration are undefined.)
The Set supports element removal (which removes the corresponding
mapping from the Map) via the Iterator.remove, Set.remove, removeAll
retainAll, and clear operations. It does not support the add or
addAll operations.
values
public Collection values()
- Returns a Collection view of the values contained in this Map. The
Collection is backed by the Map, so changes to the Map are
reflected in the Collection, and vice-versa. (If the Map is
modified while while an iteration over the Collection is in progress,
the results of the iteration are undefined.) The Collection supports
element removal (which removes the corresponding mapping from the
Map) via the Iterator.remove, Collection.remove, removeAll,
retainAll and clear operations. It does not support the add or
addAll operations.
entries
public Set entries()
- Returns a Collection view of the mappings contained in this Map.
Each element in this collection is a Map.Entry. The Collection is
backed by the Map, so changes to the Map are reflected in the
Collection, and vice-versa. (If the Map is modified while while an
iteration over the Collection is in progress, the results of the
iteration are undefined.) The Collection supports element removal
(which removes the corresponding mapping from the Map) via the
Iterator.remove, Collection.remove, removeAll, retainAll and clear
operations. It does not support the add or addAll operations.
equals
public boolean equals(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)))
. This ensures that the equals method works properly across
different implementations of the Map interface.
- Parameters:
- o - Object to be compared for equality with this Map.
- Returns:
- true if the specified Object is equal to this Map.
- Overrides:
- equals in class Object
hashCode
public int hashCode()
- UNSUPPORTED IN THIS RELEASE OF PSE. THIS METHOD WILL BE CHANGED
TO PROVIDE A BEHAVIOR COMPATIBLE WITH THE JDK1.2 MAP SPECIFICATION,
WHEN THE JDK1.2 IS RELEASED.
- Throws: UnsupportedOperationException
- this operation is not supported.
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.
- Overrides:
- hashCode in class Object
- See Also:
- hashCode, equals, equals
keyToByteArray
public abstract byte[] keyToByteArray(Object key,
byte keyEncoding[])
- Encodes a key into a byte array. Concrete subclasses of OSTreeMap
must implement this method.
- Parameters:
- key - key to be encoded.
- keyEncoding - a byte[] to use as a buffer for the returned
encoding. If this is null, or is too small to hold the encoding,
then a new byte[] will be alloacated and returned.
byteArrayToKey
public abstract Object byteArrayToKey(byte key[])
- Decodes a byte-array encoding of a key into an instance of the key type.
Concrete subclasses of OSTreeMap must implement this method.
- Parameters:
- key - The byte-array encoding of a key.
- Returns:
- The key object corresponding to the byte-array encoding.
Copyright © 1996, 1997, 1998 Object Design, Inc. All rights reserved.