|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.geotools.feature.collection.AbstractResourceCollection
Collection supporting close( Iterator ).
This implementation is a port of java.util.Collection with support for the use of close( Iterator ). This will allow subclasses that make use of resources during iterator() to be uses safely.
Subclasses are reminded that they should construct their Iterator to return system resources once content has been exhuasted. While this class is safe, and we remind users, not all libraries that accept collections can be hacked.
We need to do the same things as for use of AbstractCollection - namely:
size
and openIterator ( w/ hasNext()
and next()
.)
and finally closeIteartor( iterator )
add( Object )
let that Iterator
do remove()
Why not play with iterator()
? Because we are keeping track of them for
later purge()
...
Field Summary | |
protected java.util.Set |
open
Set of open resource iterators |
Constructor Summary | |
protected |
AbstractResourceCollection()
|
Method Summary | |
boolean |
add(java.lang.Object o)
Implement to support modification. |
boolean |
addAll(java.util.Collection c)
Adds all of the elements in the specified collection to this collection (optional operation). |
void |
clear()
Removes all of the elements from this collection (optional operation). |
void |
close(java.util.Iterator close)
Clean up after any resources assocaited with this iteartor in a manner similar to JDO collections. |
protected abstract void |
closeIterator(java.util.Iterator close)
Please override to cleanup after your own iterators, and any used resources. |
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()
|
java.util.Iterator |
iterator()
Please implement! |
protected abstract java.util.Iterator |
openIterator()
Open a resource based Iterator, we will call close( iterator ). |
void |
purge()
Close any outstanding resources released by this resources. |
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). |
abstract int |
size()
Returns the number of elements in this collection. |
java.lang.Object[] |
toArray()
Array of all the elements. |
java.lang.Object[] |
toArray(java.lang.Object[] a)
|
java.lang.String |
toString()
Returns a string representation of this collection. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
equals, hashCode |
Field Detail |
protected final java.util.Set open
Constructor Detail |
protected AbstractResourceCollection()
Method Detail |
public boolean isEmpty()
isEmpty
in interface java.util.Collection
public boolean contains(java.lang.Object o)
This implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.
contains
in interface java.util.Collection
o
- object to be checked for containment in this collection.
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection
public java.lang.Object[] toArray(java.lang.Object[] a)
toArray
in interface java.util.Collection
public boolean add(java.lang.Object o)
add
in interface java.util.Collection
o
- element whose presence in this collection is to be ensured.
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.public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection
o
- element to be removed from this collection, if present.
java.lang.UnsupportedOperationException
- if the remove method is
not supported by this collection.public boolean containsAll(java.util.Collection c)
containsAll
in interface java.util.Collection
c
- collection to be checked for containment in this collection.
java.lang.NullPointerException
- if the specified collection is null.contains(Object)
public boolean addAll(java.util.Collection c)
addAll
in interface java.util.Collection
c
- collection whose elements are to be added to this collection.
java.lang.UnsupportedOperationException
- if this collection does not
support the addAll method.
java.lang.NullPointerException
- if the specified collection is null.add(Object)
public boolean removeAll(java.util.Collection c)
removeAll
in interface java.util.Collection
c
- elements to be removed from this collection.
java.lang.UnsupportedOperationException
- if the removeAll method
is not supported by this collection.
java.lang.NullPointerException
- if the specified collection is null.remove(Object)
,
contains(Object)
public boolean retainAll(java.util.Collection c)
retainAll
in interface java.util.Collection
c
- elements to be retained in this collection.
java.lang.UnsupportedOperationException
- if the retainAll method
is not supported by this Collection.
java.lang.NullPointerException
- if the specified collection is null.remove(Object)
,
contains(Object)
public void clear()
clear
in interface java.util.Collection
java.lang.UnsupportedOperationException
- if the clear method is
not supported by this collection.public java.lang.String toString()
public final java.util.Iterator iterator()
Note: If you return a ResourceIterator, the default implemntation of close( Iterator ) will know what to do.
iterator
in interface ResourceCollection
public abstract int size()
size
in interface java.util.Collection
public final void close(java.util.Iterator close)
Iterator iterator = collection.iterator();
try {
for( Iterator i=collection.iterator(); i.hasNext();){
Feature feature = (Feature) i.hasNext();
System.out.println( feature.getID() );
}
}
finally {
collection.close( iterator );
}
close
in interface ResourceCollection
close
- protected abstract java.util.Iterator openIterator()
Please subclass to provide your own iterator for the the ResourceCollection,
note iterator()
is implemented to call open()
and track the results in for later purge()
.
protected abstract void closeIterator(java.util.Iterator close)
As an example if the iterator was working off a File then the inputstream should be closed.
Subclass must call super.close( close ) to allow the list of open iterators to be adjusted.
close
- Iterator, will not be null
public void purge()
This method should be used with great caution, it is however available to allow the use of the ResourceCollection with algorthims that are unaware of the need to close iterators after use.
Example of using a normal Collections utility method:
Collections.sort( collection );
collection.purge();
purge
in interface ResourceCollection
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |