org.geotools.util
Class KeySortedList

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byjava.util.AbstractSequentialList
              extended byorg.geotools.util.KeySortedList
All Implemented Interfaces:
java.util.Collection, java.util.List, java.io.Serializable

public class KeySortedList
extends java.util.AbstractSequentialList
implements java.io.Serializable

List of elements sorted by a key which is not the element itself.

Since:
2.2
Version:
$Id: KeySortedList.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Simone Giannecchini, Martin Desruisseaux
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
KeySortedList()
          Creates a new, initially empty list.
 
Method Summary
 void add(java.lang.Comparable key, java.lang.Object element)
          Inserts the specified element at a position determined by the specified key.
 void clear()
          Removes all of the elements from this list.
 boolean containsKey(java.lang.Comparable key)
          Returns if the list contains an element added with the specified key.
 int count(java.lang.Comparable key)
          Returns the number of elements added with the specified key.
 java.lang.Object first(java.lang.Comparable key)
          Returns the first element added with the specified key.
 KeySortedList headList(java.lang.Comparable toKey)
          Returns a view of the portion of this list whose keys are strictly less than .
 java.lang.Object last(java.lang.Comparable key)
          Returns the last element added with the specified key.
 java.util.ListIterator listIterator(java.lang.Comparable fromKey)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the elements added with the specified key.
 java.util.ListIterator listIterator(int index)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position.
 int removeAll(java.lang.Comparable key)
          Removes all values that were added with the specified key.
 int size()
          Returns the number of elements in this list.
 KeySortedList tailList(java.lang.Comparable fromKey)
          Returns a view of the portion of this list whose keys are greater than or equal to .
 
Methods inherited from class java.util.AbstractSequentialList
add, addAll, get, iterator, remove, set
 
Methods inherited from class java.util.AbstractList
add, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, 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, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

KeySortedList

public KeySortedList()
Creates a new, initially empty list.

Method Detail

clear

public void clear()
Removes all of the elements from this list.

Specified by:
clear in interface java.util.List

size

public int size()
Returns the number of elements in this list.

Specified by:
size in interface java.util.List

add

public void add(java.lang.Comparable key,
                java.lang.Object element)
Inserts the specified element at a position determined by the specified key. If some elements were already inserted for the specified key, then this method do not replaces the old value (like what a Map would do), but instead add the new element with the same key.

Parameters:
key - Key to be used to find the right location.
element - Object to be inserted.

removeAll

public int removeAll(java.lang.Comparable key)
Removes all values that were added with the specified key. Returns the number of elements removed.


count

public int count(java.lang.Comparable key)
Returns the number of elements added with the specified key.


containsKey

public boolean containsKey(java.lang.Comparable key)
Returns if the list contains an element added with the specified key. This is equivalent to testing count(key) != 0.


first

public java.lang.Object first(java.lang.Comparable key)
                       throws java.util.NoSuchElementException
Returns the first element added with the specified key.

Parameters:
key - The key for the element to search for.
Returns:
The first element added with the specified key.
Throws:
java.util.NoSuchElementException - if there is no element for the specified key.

last

public java.lang.Object last(java.lang.Comparable key)
                      throws java.util.NoSuchElementException
Returns the last element added with the specified key.

Parameters:
key - The key for the element to search for.
Returns:
The last element added with the specified key.
Throws:
java.util.NoSuchElementException - if there is no element for the specified key.

listIterator

public java.util.ListIterator listIterator(java.lang.Comparable fromKey)
Returns a list iterator of the elements in this list (in proper sequence), starting at the elements added with the specified key.

Parameters:
fromKey - The key of the first element to returns.
Returns:
A list iterator of the elements in this list (in proper sequence).
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range.

listIterator

public java.util.ListIterator listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position. The specified index indicates the first element that would be returned by an initial call to the next() method.

Specified by:
listIterator in interface java.util.List
Parameters:
index - Index of first element to be returned from the list iterator.
Returns:
A list iterator of the elements in this list (in proper sequence).
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range.

headList

public KeySortedList headList(java.lang.Comparable toKey)
Returns a view of the portion of this list whose keys are strictly less than . The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa.

Parameters:
toKey - high endpoint (exclusive) of the sub list.
Returns:
A view of the specified initial range of this list.

tailList

public KeySortedList tailList(java.lang.Comparable fromKey)
Returns a view of the portion of this list whose keys are greater than or equal to . The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa.

Parameters:
fromKey - low endpoint (inclusive) of the sub list.
Returns:
A view of the specified final range of this list.


Copyright © GeoTools. All Rights Reserved.