org.geotools.feature.collection
Class AbstractResourceList

java.lang.Object
  extended byorg.geotools.feature.collection.AbstractResourceCollection
      extended byorg.geotools.feature.collection.AbstractResourceList
All Implemented Interfaces:
java.util.Collection, java.util.List, ResourceCollection, ResourceList
Direct Known Subclasses:
AbstractFeatureList, SubResourceList

public abstract class AbstractResourceList
extends AbstractResourceCollection
implements ResourceList

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:

For read/write:

As usual override anything if you have a faster implementation, say based on a shapefile index.

Since:
GeoTools 2.2
Author:
Jody Garnett, Refractions Research, Inc.
See Also:
AbstractList

Field Summary
protected  int modCount
          The number of times this list has been modified.
 
Fields inherited from class org.geotools.feature.collection.AbstractResourceCollection
open
 
Constructor Summary
protected AbstractResourceList()
           
 
Method Summary
 void add(int index, java.lang.Object element)
          Inserts the specified element at the specified position in this list (optional operation).
 boolean add(java.lang.Object item)
          Appends element.
 boolean addAll(int index, java.util.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(java.util.Iterator close)
          Please override to cleanup after your own iterators, and any used resources.
 boolean equals(java.lang.Object o)
          Compares the specified object with this list for equality.
abstract  java.lang.Object get(int index)
          item at the specified index.
 int hashCode()
          Returns the hash code value for this list.
 int indexOf(java.lang.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(java.lang.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.
 java.util.ListIterator listIterator()
          Returns listIterator(0).
 java.util.ListIterator listIterator(int index)
          Returns a list iterator of the elements in this list from index on.
protected  java.util.Iterator openIterator()
          Returns a quick iterator that uses get and size methods.
 java.util.ListIterator openIterator(int index)
           
 java.lang.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
 java.lang.Object set(int index, java.lang.Object item)
          Replaces item in position index (optional operation).
 java.util.List subList(int fromIndex, int toIndex)
          view of the portion of this list between fromIndex up to toIndex.
 
Methods inherited from class org.geotools.feature.collection.AbstractResourceCollection
addAll, close, contains, containsAll, isEmpty, iterator, purge, remove, removeAll, retainAll, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface org.geotools.data.collection.ResourceCollection
close, iterator, purge
 

Field Detail

modCount

protected transient int modCount
The number of times this list has been modified.

Constructor Detail

AbstractResourceList

protected AbstractResourceList()
Method Detail

add

public boolean add(java.lang.Object item)
Appends element.

This implementation calls add(size(), o).

Note that this implementation throws an UnsupportedOperationException unless add(int, Object) is overridden.

Specified by:
add in interface java.util.List
Overrides:
add in class AbstractResourceCollection
Parameters:
item - element whose presence in this collection is to be ensured.
Returns:
true (as per the general contract of Collection.add).
Throws:
java.lang.UnsupportedOperationException - if the add method is not supported by this Set.
java.lang.ClassCastException - if the class of the specified element prevents it from being added to this set.
java.lang.IllegalArgumentException - some aspect of this element prevents it from being added to this collection.

get

public abstract java.lang.Object get(int index)
item at the specified index.

Specified by:
get in interface java.util.List
Parameters:
index - index of item
Returns:
the item at the specified index.
Throws:
java.lang.IndexOutOfBoundsException - if index is not between 0 and size

set

public java.lang.Object set(int index,
                            java.lang.Object item)
Replaces item in position index (optional operation).

This implementation always throws an UnsupportedOperationException.

Specified by:
set in interface java.util.List
Parameters:
index - index of element to replace.
Returns:
the element previously at the specified position.
Throws:
java.lang.UnsupportedOperationException - if the set method is not supported by this List.
java.lang.ClassCastException - if the class of the specified element prevents it from being added to this list.
java.lang.IllegalArgumentException - if some aspect of the specified element prevents it from being added to this list.
java.lang.IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index >= size()).

add

public void add(int index,
                java.lang.Object element)
Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This implementation always throws an UnsupportedOperationException.

Specified by:
add in interface java.util.List
Parameters:
index - index at which the specified element is to be inserted.
element - element to be inserted.
Throws:
java.lang.UnsupportedOperationException - if the add method is not supported by this list.
java.lang.ClassCastException - if the class of the specified element prevents it from being added to this list.
java.lang.IllegalArgumentException - if some aspect of the specified element prevents it from being added to this list.
java.lang.IndexOutOfBoundsException - index is out of range (index < 0 || index > size()).

remove

public java.lang.Object remove(int index)
Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

This implementation always throws an UnsupportedOperationException.

Specified by:
remove in interface java.util.List
Parameters:
index - the index of the element to remove.
Returns:
the element previously at the specified position.
Throws:
java.lang.UnsupportedOperationException - if the remove method is not supported by this list.
java.lang.IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index >= size()).

indexOf

public int indexOf(java.lang.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. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.

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.

Specified by:
indexOf in interface java.util.List
Parameters:
o - element to search for.
Returns:
the index in this List of the first occurence of the specified element, or -1 if the List does not contain this element.

lastIndexOf

public int lastIndexOf(java.lang.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. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.

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.

Specified by:
lastIndexOf in interface java.util.List
Parameters:
o - element to search for.
Returns:
the index in this list of the last occurence of the specified element, or -1 if the list does not contain this element.

clear

public void clear()
Removes all of the elements from this collection (optional operation).

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.

Specified by:
clear in interface java.util.List
Overrides:
clear in class AbstractResourceCollection
Throws:
java.lang.UnsupportedOperationException - if the clear method is not supported by this Collection.

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Inserts all of the elements in the specified collection into this list at the specified position (optional operation).

Note that this implementation throws an UnsupportedOperationException unless add(int, Object) is overridden.

Specified by:
addAll in interface java.util.List
Parameters:
index - index at which to insert the first element from the specified collection.
c - elements to be inserted into this List.
Returns:
true if this list changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if the addAll method is not supported by this list.
java.lang.ClassCastException - if the class of an element of the specified collection prevents it from being added to this List.
java.lang.IllegalArgumentException - some aspect an element of the specified collection prevents it from being added to this List.
java.lang.IndexOutOfBoundsException - index out of range (index < 0 || index > size()).
java.lang.NullPointerException - if the specified collection is null.

listIterator

public java.util.ListIterator listIterator()
Returns listIterator(0).

Specified by:
listIterator in interface java.util.List
Returns:
listIterator(0)
See Also:
listIterator(int)

listIterator

public java.util.ListIterator listIterator(int index)
Returns a list iterator of the elements in this list from index on.

Specified by:
listIterator in interface java.util.List
Parameters:
index -
Returns:
a list iterator from index *
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range
See Also:
modCount

openIterator

public java.util.ListIterator openIterator(int index)

openIterator

protected java.util.Iterator openIterator()
Returns a quick iterator that uses get and size methods.

As with all resource collections it is assumed that the iterator will be closed after use.

Specified by:
openIterator in class AbstractResourceCollection
Returns:
an iterator over the elements in this list in proper sequence.
See Also:
modCount

closeIterator

protected void closeIterator(java.util.Iterator close)
Description copied from class: AbstractResourceCollection
Please override to cleanup after your own iterators, and any used resources.

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.

Specified by:
closeIterator in class AbstractResourceCollection
Parameters:
close - Iterator, will not be null

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
view of the portion of this list between fromIndex up to toIndex.

Specified by:
subList in interface java.util.List
Parameters:
fromIndex -
toIndex -
Returns:
a view of the specified range within this list.
Throws:
java.lang.IndexOutOfBoundsException
java.lang.IllegalArgumentException - endpoint indices out of order

equals

public boolean equals(java.lang.Object o)
Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order.

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.

Specified by:
equals in interface java.util.List
Parameters:
o - the object to be compared for equality with this list.
Returns:
true if the specified object is equal to this list.

hashCode

public int hashCode()
Returns the hash code value for this list.

This implementation uses exactly the code that is used to define the list hash function in the documentation for the List.hashCode method.

Specified by:
hashCode in interface java.util.List
Returns:
the hash code value for this list.

removeRange

public void removeRange(int fromIndex,
                        int toIndex)
Removes from this list all of the elements whose index is between fromIndex upto toIndex

Specified by:
removeRange in interface ResourceList
Parameters:
fromIndex - index of first element to be removed.
toIndex - index after last element to be removed.


Copyright © GeoTools. All Rights Reserved.