org.garret.perst
Class PersistentCollection<T>

java.lang.Object
  extended by org.garret.perst.Persistent
      extended by org.garret.perst.PersistentResource
          extended by org.garret.perst.PersistentCollection
All Implemented Interfaces:
java.util.Collection, java.io.Externalizable, IPersistent, IResource, ITable, java.lang.Iterable, java.io.Serializable

public abstract class PersistentCollection<T>
extends PersistentResource
implements ITable<T>

See Also:
Serialized Form

Constructor Summary
PersistentCollection()
          Default constructor
PersistentCollection(Storage storage)
          Constructor of the collection associated with the specified storage
 
Method Summary
 boolean add(T o)
          Ensures that this collection contains the specified element (optional operation).
 boolean addAll(java.util.Collection<? extends T> c)
          Adds all of the elements in the specified collection to this collection (optional operation).
 boolean contains(java.lang.Object o)
          Returns true if this collection contains the specified element.
 boolean containsAll(java.util.Collection<?> c)
          Returns true if this collection contains all of the elements in the specified collection.
 boolean isEmpty()
          Returns true if this collection contains no elements.
 boolean remove(java.lang.Object o)
          Removes a single instance of the specified element from this collection, if it is present (optional operation).
 boolean removeAll(java.util.Collection<?> c)
          Removes from this collection all of its elements that are contained in the specified collection (optional operation).
 boolean retainAll(java.util.Collection<?> c)
          Retains only the elements in this collection that are contained in the specified collection (optional operation).
 java.util.Iterator<T> select(java.lang.Class cls, java.lang.String predicate)
          Select members of the collection using search predicate This iterator doesn't support remove() method.
 
Methods inherited from class org.garret.perst.PersistentResource
exclusiveLock, exclusiveLock, reset, sharedLock, sharedLock, unlock
 
Methods inherited from class org.garret.perst.Persistent
assignOid, deallocate, equals, getOid, getStorage, hashCode, invalidate, isDeleted, isModified, isPersistent, isRaw, load, loadAndModify, makePersistent, modify, onLoad, onStore, readExternal, recursiveLoading, store, writeExternal
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
add, addAll, clear, equals, hashCode, iterator, size, toArray, toArray
 

Constructor Detail

PersistentCollection

public PersistentCollection()
Default constructor


PersistentCollection

public PersistentCollection(Storage storage)
Constructor of the collection associated with the specified storage

Parameters:
storage - storage associated with the collection
Method Detail

add

public boolean add(T o)
Ensures that this collection contains the specified element (optional operation). 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.) Collections that support this operation may place limitations on what elements may be added to the collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

This implementation always throws an UnsupportedOperationException.

Parameters:
o - element whose presence in this collection is to be ensured.
Returns:
true if the collection changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if the add method is not supported by this collection.
java.lang.NullPointerException - if this collection does not permit null elements, and the specified element is null.
java.lang.ClassCastException - if the class of the specified element prevents it from being added to this collection.
java.lang.IllegalArgumentException - if some aspect of this element prevents it from being added to this collection.

addAll

public boolean addAll(java.util.Collection<? extends T> c)
Adds all of the elements in the specified collection to this collection (optional operation). 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 specified collection is this collection, and this collection is nonempty.)

This implementation iterates over the specified collection, and adds each object returned by the iterator to this collection, in turn.

Note that this implementation will throw an UnsupportedOperationException unless add is overridden (assuming the specified collection is non-empty).

Parameters:
c - collection whose elements are to be added to this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if this collection does not support the addAll method.
java.lang.NullPointerException - if the specified collection is null.
See Also:
add(Object)

contains

public boolean contains(java.lang.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==null ? e==null : o.equals(e)).

This implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.

Specified by:
contains in interface java.util.Collection
Parameters:
o - object to be checked for containment in this collection.
Returns:
true if this collection contains the specified element.

containsAll

public boolean containsAll(java.util.Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection.

This implementation iterates over the specified collection, checking each element returned by the iterator in turn to see if it's contained in this collection. If all elements are so contained true is returned, otherwise false.

Specified by:
containsAll in interface java.util.Collection
Parameters:
c - collection to be checked for containment in this collection.
Returns:
true if this collection contains all of the elements in the specified collection.
Throws:
java.lang.NullPointerException - if the specified collection is null.
See Also:
contains(Object)

isEmpty

public boolean isEmpty()
Returns true if this collection contains no elements.

This implementation returns size() == 0.

Specified by:
isEmpty in interface java.util.Collection
Returns:
true if this collection contains no elements.

remove

public boolean remove(java.lang.Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : 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).

This implementation iterates over the collection looking for the specified element. If it finds the element, it removes the element from the collection using the iterator's remove method.

Note that this implementation throws an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection contains the specified object.

Specified by:
remove in interface java.util.Collection
Parameters:
o - element to be removed from this collection, if present.
Returns:
true if the collection contained the specified element.
Throws:
java.lang.UnsupportedOperationException - if the remove method is not supported by this collection.

removeAll

public boolean removeAll(java.util.Collection<?> c)
Removes from this collection all of its elements that are contained in the specified collection (optional operation).

This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's so contained, it's removed from this collection with the iterator's remove method.

Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements in common with the specified collection.

Specified by:
removeAll in interface java.util.Collection
Parameters:
c - elements to be removed from this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if the removeAll method is not supported by this collection.
java.lang.NullPointerException - if the specified collection is null.
See Also:
remove(Object), contains(Object)

retainAll

public boolean retainAll(java.util.Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.

This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's not so contained, it's removed from this collection with the iterator's remove method.

Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements not present in the specified collection.

Specified by:
retainAll in interface java.util.Collection
Parameters:
c - elements to be retained in this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if the retainAll method is not supported by this Collection.
java.lang.NullPointerException - if the specified collection is null.
See Also:
remove(Object), contains(Object)

select

public java.util.Iterator<T> select(java.lang.Class cls,
                                    java.lang.String predicate)
Description copied from interface: ITable
Select members of the collection using search predicate This iterator doesn't support remove() method.

Specified by:
select in interface ITable
Parameters:
cls - class of index members
predicate - JSQL condition
Returns:
iterator through members of the collection matching search condition