org.geotools.util
Class KeySortedList<K extends java.lang.Comparable<K>,V>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.AbstractSequentialList<V>
              extended by org.geotools.util.KeySortedList<K,V>
Type Parameters:
K - The type of keys in the sorted list, to be used for sorting.
V - The type of elements in the list.
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<V>, java.util.Collection<V>, java.util.List<V>

public class KeySortedList<K extends java.lang.Comparable<K>,V>
extends java.util.AbstractSequentialList<V>
implements java.io.Serializable

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

This class is not thread-safe. Synchronizations (if wanted) are user's reponsability.

Since:
2.2
Version:
$Id: KeySortedList.java 30792 2008-06-23 19:19:58Z 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(K key, V 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(K key)
          Returns true if the list contains an element added with the specified key.
 int count(K key)
          Returns the number of elements added with the specified key.
 V first(K key)
          Returns the first element added with the specified key.
 KeySortedList<K,V> headList(K toKey)
          Returns a view of the portion of this list whose keys are strictly less than toKey.
 V last(K key)
          Returns the last element added with the specified key.
 java.util.ListIterator<V> listIterator(int index)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position.
 java.util.ListIterator<V> listIterator(K fromKey)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the elements added with the specified key.
 int removeAll(K key)
          Removes all values that were added with the specified key.
 int size()
          Returns the number of elements in this list.
 KeySortedList<K,V> tailList(K fromKey)
          Returns a view of the portion of this list whose keys are greater than or equal to fromKey.
 
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.Collection<V>
Specified by:
clear in interface java.util.List<V>
Overrides:
clear in class java.util.AbstractList<V>

size

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

Specified by:
size in interface java.util.Collection<V>
Specified by:
size in interface java.util.List<V>
Specified by:
size in class java.util.AbstractCollection<V>

add

public void add(K key,
                V 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(K key)
Removes all values that were added with the specified key.

Parameters:
key - The key of values to remove.
Returns:
The number of elements removed.

count

public int count(K key)
Returns the number of elements added with the specified key.

Parameters:
key - The key of elements to count.
Returns:
The number of elements inserted with the given key.

containsKey

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


first

public V first(K 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 V last(K 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<V> listIterator(K 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<V> 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<V>
Specified by:
listIterator in class java.util.AbstractSequentialList<V>
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<K,V> headList(K toKey)
Returns a view of the portion of this list whose keys are strictly less than toKey. 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<K,V> tailList(K fromKey)
Returns a view of the portion of this list whose keys are greater than or equal to fromKey. 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 © 1996-2010 Geotools. All Rights Reserved.