Class COM.odi.util.OSHashBag
java.lang.Object
|
+----COM.odi.util.OSHashBag
- public class OSHashBag
- extends Object
- implements IPersistent, Cloneable, Collection, FastContains, Serializable
OSHashBag implements a persistent collection, possibly containing
duplicates. OSHashBag implements the API specified by the java.util.Collection
interface. The equals() and hashCode() methods are reference-based, not
content-based (they differ in this way from the equals() and hashCode()
methods specified by java.util.Set and java.util.List).
Certain operations on OSHashBag that require comparison of objects
might cause ObjectStore to throw ReferencedObjectNotFoundException.
If this occurs, it indicates that one or more of the values
referenced by the underlying hash table cannot be accessed, most likely because
they have been destroyed. The OSHashBag class provides a
clearDestroyed() operation that can be used to remove entries that
contain these references to these destroyed objects.
Additional information about OSHashBag
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:
- IPersistent, Collection
-
OSHashBag()
- Create a new, empty OSHashBag.
-
OSHashBag(int)
- Create a new, empty OSHashBag,
and allocate a backing hashtable of the specified size.
-
add(Object)
- Ensures that this Collection contains the specified element.
-
addAll(Collection)
- Adds all of the elements in the specified Collection to this Collection,
if they were not already present.
-
clear()
- Removes all of the elements from this Collection.
-
clearDestroyed()
- Removes from the hash table all entries which reference destroyed objects
either as a key or value.
-
contains(Object)
- Returns true if this Collection contains the specified element.
-
containsAll(Collection)
- Returns true if this Collection contains all of the elements in the
specified Collection.
-
duplicateCount(Object)
- Returns the duplicate count for the specified element, or 0 if the
element is not contained in the bag.
-
hashCode()
- Returns the hash code for the object.
-
isEmpty()
- Returns true if this Collection contains no elements.
-
iterator()
- Returns an Iterator over the elements in this Collection.
-
remove(Object)
- Removes a single instance of the specified element from this Collection,
if it is present.
-
removeAll(Collection)
- Removes from this collection all of its elements that are contained in
the specified collection.
-
retainAll(Collection)
- Retains only the elements in this collection that are contained in the
specified collection.
-
size()
- Returns the number of elements in this Collection.
-
toArray()
- Returns an array containing all of the elements in this Collection.
OSHashBag
public OSHashBag()
- Create a new, empty OSHashBag.
OSHashBag
public OSHashBag(int initSize)
- Create a new, empty OSHashBag,
and allocate a backing hashtable of the specified size.
clearDestroyed
public void clearDestroyed()
- Removes from the hash table all entries which reference destroyed objects
either as a key or value. The current implementation of this method
requires that all key, value objects referenced by the OSHashtable be
fetched, which may require significant heap space.
duplicateCount
public int duplicateCount(Object o)
- Returns the duplicate count for the specified element, or 0 if the
element is not contained in the bag.
- Parameters:
- o - element whose presence in this Collection is to be tested.
size
public int size()
- Returns the number of elements in this Collection.
isEmpty
public boolean isEmpty()
- Returns true if this Collection contains no elements.
contains
public boolean contains(Object o)
- Returns true if this Collection contains the specified element. More
formally, returns true if and only if this Collection contains at least
one element
e
such that o.equals(e)
.
- Parameters:
- o - element whose presence in this Collection is to be tested.
iterator
public Iterator iterator()
- Returns an Iterator over the elements in this Collection. There are
no guarantees concerning the order in which the elements are returned.
toArray
public Object[] toArray()
- Returns an array containing all of the elements in this Collection.
The returned array will be "safe" in that no references to
it are maintained by the Collection. (In other words, this method must
allocate a new array even if the Collection is backed by an Array).
The caller is thus free to modify the returned array.
This method acts as bridge between array-based and Collection-based
APIs.
add
public boolean add(Object o)
- Ensures that this Collection contains the specified element.
Returns true if the Collection changed as a result of the
call. Returns false if this Collection does not permit duplicates and
already contains the specified element.
- Parameters:
- o - element whose presence in this Collection is to be ensured.
- Returns:
- true if the Collection changed as a result of the call.
remove
public boolean remove(Object o)
- Removes a single instance of the specified element from this Collection,
if it is present. More formally, removes an
element
e
such that o.equals(e)
,
if the Collection contains one or more such elements.
Returns true if the Collection contained the specified
element (or equivalently, if the Collection changed as a
result of the call).
- Parameters:
- o - element to be removed from this Collection, if present.
- Returns:
- true if the Collection changed as a result of the call.
containsAll
public boolean containsAll(Collection c)
- Returns true if this Collection contains all of the elements in the
specified Collection. Both this collection and the specified collection
are treated as sets for the purposes of this operation (that is, duplicate
elements are ignored).
- See Also:
- contains
addAll
public boolean addAll(Collection c)
- Adds all of the elements in the specified Collection to this Collection,
if they were not already present. Both this collection and the specified
collection are treated as sets for the purposes of this operations (that
is, duplicate elements are ignored).
The behavior of this operation is undefined if
the specified Collection is modified while the operation is in progress.
(This implies that the behavior of this call is undefined if the the
specified Collection is this Collection, and this Collection is
nonempty.)
- Parameters:
- c - elements to be inserted into this Collection.
- Returns:
- true if this Collection changed as a result of the call.
- See Also:
- add
removeAll
public boolean removeAll(Collection c)
- Removes from this collection all of its elements that are contained in
the specified collection. Both this collection and the specified
collection are treated as sets for the purposes of this operation (that
is, duplicate elements are ignored). After this call returns,
this collection will contains no elements in common with the specified
collection, even if this collection may have had duplicate elements.
- Parameters:
- c - elements to be removed from this Collection.
- Returns:
- true if this Collection changed as a result of the call.
- See Also:
- remove, contains
retainAll
public boolean retainAll(Collection coll)
- Retains only the elements in this collection that are contained in the
specified collection. In other words, removes from
this Collection all of its elements that are not contained in the
specified Collection. Both this collection and the specified collection
are treated as sets for the purposes of this operation (that is,
duplicate elements are ignored).
- Parameters:
- c - elements to be retained in this Collection.
- Returns:
- true if this Collection changed as a result of the call.
- See Also:
- remove, contains
clear
public void clear()
- Removes all of the elements from this Collection.
The Collection will be empty after this call returns.
hashCode
public int hashCode()
- Returns the hash code for the object.
- Overrides:
- hashCode in class Object
Copyright © 1996, 1997, 1998 Object Design, Inc. All rights reserved.