Package org.geotools.util
Class KeySortedList<K extends Comparable<K>,V>
Object
AbstractCollection<E>
AbstractList<E>
AbstractSequentialList<V>
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:
Serializable
,Iterable<V>
,Collection<V>
,List<V>
public class KeySortedList<K extends Comparable<K>,V>
extends AbstractSequentialList<V>
implements 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
- Author:
- Simone Giannecchini, Martin Desruisseaux
- See Also:
-
Field Summary
Fields inherited from class AbstractList
modCount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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) Returnstrue
if the list contains an element added with the specified key.int
Returns the number of elements added with the specified key.Returns the first element added with the specified key.Returns a view of the portion of this list whose keys are strictly less thantoKey
.Returns the last element added with the specified key.listIterator
(int index) Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position.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
Removes all values that were added with the specified key.int
size()
Returns the number of elements in this list.Returns a view of the portion of this list whose keys are greater than or equal tofromKey
.Methods inherited from class AbstractList
add, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList
Methods inherited from class AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
Methods inherited from interface Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Constructor Details
-
KeySortedList
public KeySortedList()Creates a new, initially empty list.
-
-
Method Details
-
clear
public void clear()Removes all of the elements from this list.- Specified by:
clear
in interfaceCollection<K extends Comparable<K>>
- Specified by:
clear
in interfaceList<K extends Comparable<K>>
- Overrides:
clear
in classAbstractList<V>
-
size
public int size()Returns the number of elements in this list.- Specified by:
size
in interfaceCollection<K extends Comparable<K>>
- Specified by:
size
in interfaceList<K extends Comparable<K>>
- Specified by:
size
in classAbstractCollection<V>
-
add
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 aMap
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
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
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
-
first
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:
NoSuchElementException
- if there is no element for the specified key.
-
last
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:
NoSuchElementException
- if there is no element for the specified key.
-
listIterator
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:
IndexOutOfBoundsException
- if the index is out of range.
-
listIterator
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 thenext()
method.- Specified by:
listIterator
in interfaceList<K extends Comparable<K>>
- Specified by:
listIterator
in classAbstractSequentialList<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:
IndexOutOfBoundsException
- if the index is out of range.
-
headList
Returns a view of the portion of this list whose keys are strictly less thantoKey
. 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
Returns a view of the portion of this list whose keys are greater than or equal tofromKey
. 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.
-