|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectAbstractResourceCollection
AbstractResourceList
public abstract class AbstractResourceList
Starter for resource based list implementations.
Same deal as ResouceCollections - iterators that need to be closed. This implementation is set up for random access happy content, like an array list.
Read-only:
get(int index)
size()
For read/write:
set(index, element) - for fixed length
add(index, element) and remove(index) for dynamic length
AbstractList
modules/library/main (gt2-main.jar) (Maven report) (SVN head)| Field Summary | |
|---|---|
protected int |
modCount
The number of times this list has been modified. |
| Fields inherited from class AbstractResourceCollection |
|---|
open |
| Constructor Summary | |
|---|---|
protected |
AbstractResourceList()
|
| Method Summary | |
|---|---|
void |
add(int index,
Object element)
Inserts the specified element at the specified position in this list (optional operation). |
boolean |
add(Object item)
Appends element. |
boolean |
addAll(int index,
Collection c)
Inserts all of the elements in the specified collection into this list at the specified position (optional operation). |
void |
clear()
Removes all of the elements from this collection (optional operation). |
protected void |
closeIterator(Iterator close)
Please override to cleanup after your own iterators, and any used resources. |
boolean |
equals(Object o)
Compares the specified object with this list for equality. |
abstract Object |
get(int index)
item at the specified index. |
int |
hashCode()
Returns the hash code value for this list. |
int |
indexOf(Object o)
Returns the index in this list of the first occurence of the specified element, or -1 if the list does not contain this element. |
int |
lastIndexOf(Object o)
Returns the index in this list of the last occurence of the specified element, or -1 if the list does not contain this element. |
ListIterator |
listIterator()
Returns listIterator(0). |
ListIterator |
listIterator(int index)
Returns a list iterator of the elements in this list from index on. |
protected Iterator |
openIterator()
Returns a quick iterator that uses get and size methods. |
ListIterator |
openIterator(int index)
|
Object |
remove(int index)
Removes the element at the specified position in this list (optional operation). |
void |
removeRange(int fromIndex,
int toIndex)
Removes from this list all of the elements whose index is between fromIndex upto toIndex |
Object |
set(int index,
Object item)
Replaces item in position index (optional operation). |
List |
subList(int fromIndex,
int toIndex)
view of the portion of this list between fromIndex up to toIndex. |
| Methods inherited from class AbstractResourceCollection |
|---|
addAll, close, contains, containsAll, isEmpty, iterator, purge, remove, removeAll, retainAll, size, toArray, toArray, toString |
| Methods inherited from class Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface List |
|---|
addAll, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
| Methods inherited from interface ResourceCollection |
|---|
close, iterator, purge |
| Field Detail |
|---|
protected transient int modCount
| Constructor Detail |
|---|
protected AbstractResourceList()
| Method Detail |
|---|
public boolean add(Object item)
This implementation calls add(size(), o).
Note that this implementation throws an UnsupportedOperationException unless add(int, Object) is overridden.
add in interface Collectionadd in interface Listadd in class AbstractResourceCollectionitem - the Object element to be appended to this list.
UnsupportedOperationException - if the add method is not supported by this Set.
ClassCastException - if the class of the specified element prevents it from being
added to this set.
IllegalArgumentException - some aspect of this element prevents it from being added to
this collection.public abstract Object get(int index)
get in interface Listindex - index of item
IndexOutOfBoundsException - if index is not between 0 and size
public Object set(int index,
Object item)
This implementation always throws an UnsupportedOperationException.
set in interface Listindex - index of element to replace.item - the Object element to be stored at the specified position.
UnsupportedOperationException - if the set method is not supported by this List.
ClassCastException - if the class of the specified element prevents it from being
added to this list.
IllegalArgumentException - if some aspect of the specified element prevents it from
being added to this list.
IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index >= size()).
public void add(int index,
Object element)
This implementation always throws an UnsupportedOperationException.
add in interface Listindex - index at which the specified element is to be inserted.element - element to be inserted.
UnsupportedOperationException - if the add method is not supported by this list.
ClassCastException - if the class of the specified element prevents it from being
added to this list.
IllegalArgumentException - if some aspect of the specified element prevents it from
being added to this list.
IndexOutOfBoundsException - index is out of range (index <
0 || index > size()).public Object remove(int index)
This implementation always throws an UnsupportedOperationException.
remove in interface Listindex - the index of the element to remove.
UnsupportedOperationException - if the remove method is not supported by this
list.
IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index >= size()).public int indexOf(Object o)
This implementation first gets a list iterator (with listIterator()). Then, it iterates over the list until the specified element is found or the end of the list is reached.
indexOf in interface Listo - element to search for.
public int lastIndexOf(Object o)
This implementation first gets a list iterator that points to the end of the list (with listIterator(size())). Then, it iterates backwards over the list until the specified element is found, or the beginning of the list is reached.
lastIndexOf in interface Listo - element to search for.
public void clear()
This implementation calls removeRange(0, size()).
Note that this implementation throws an UnsupportedOperationException unless remove(int index) or removeRange(int fromIndex, int toIndex) is overridden.
clear in interface Collectionclear in interface Listclear in class AbstractResourceCollectionUnsupportedOperationException - if the clear method is not supported by this
Collection.
public boolean addAll(int index,
Collection c)
Note that this implementation throws an UnsupportedOperationException unless add(int, Object) is overridden.
addAll in interface Listindex - index at which to insert the first element from the specified
collection.c - elements to be inserted into this List.
UnsupportedOperationException - if the addAll method is not supported by this
list.
ClassCastException - if the class of an element of the specified collection
prevents it from being added to this List.
IllegalArgumentException - some aspect an element of the specified collection prevents
it from being added to this List.
IndexOutOfBoundsException - index out of range (index < 0
|| index > size()).
NullPointerException - if the specified collection is null.public ListIterator listIterator()
listIterator in interface ListlistIterator(int)public ListIterator listIterator(int index)
listIterator in interface Listindex -
IndexOutOfBoundsException - if the specified index is out of rangemodCountpublic ListIterator openIterator(int index)
protected Iterator openIterator()
As with all resource collections it is assumed that the iterator will be closed after use.
openIterator in class AbstractResourceCollectionmodCountprotected void closeIterator(Iterator close)
AbstractResourceCollectionAs 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.
closeIterator in class AbstractResourceCollectionclose - Iterator, will not be null
public List subList(int fromIndex,
int toIndex)
subList in interface ListfromIndex - toIndex -
IndexOutOfBoundsException
IllegalArgumentException - endpoint indices out of orderpublic boolean equals(Object o)
This implementation first checks if the specified object is this list. If so, it returns true; if not, it checks if the specified object is a list. If not, it returns false; if so, it iterates over both lists, comparing corresponding pairs of elements. If any comparison returns false, this method returns false. If either iterator runs out of elements before the other it returns false (as the lists are of unequal length); otherwise it returns true when the iterations complete.
equals in interface Collectionequals in interface Listequals in class Objecto - the object to be compared for equality with this list.
public int hashCode()
This implementation uses exactly the code that is used to define the list hash function in the documentation for the List.hashCode method.
hashCode in interface CollectionhashCode in interface ListhashCode in class Object
public void removeRange(int fromIndex,
int toIndex)
removeRange in interface ResourceListfromIndex - index of first element to be removed.toIndex - index after last element to be removed.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||