Package jadex.collection
Class SortedList<T>
java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractList<T>
java.util.AbstractSequentialList<T>
java.util.LinkedList<T>
jadex.collection.SortedList<T>
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<T>
,Collection<T>
,Deque<T>
,List<T>
,Queue<T>
,SequencedCollection<T>
A sorted list allowing duplicates of elements
(unlike java.util.TreeSet).
The list is kept sorted, while elements are being added.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
The ordering direction of the list.protected Comparator
<? super T> The comparator to use (if any).Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty list with ascending order.SortedList
(boolean ascending) Constructs an empty list with given order.SortedList
(Comparator<? super T> comp, boolean ascending) Constructs an empty list with given order. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts the specified element at the specified position in this list.boolean
Appends the specified element to the end of this list.boolean
addAll
(int index, Collection<? extends T> c) Inserts all of the elements in the specified collection into this list, starting at the specified position.boolean
addAll
(Collection<? extends T> c) Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.void
Inserts the given element at the beginning of this list.void
Appends the given element to the end of this list.protected int
Compare two elements.int
insertElement
(int index, T obj) Insert an element into the list.Methods inherited from class java.util.LinkedList
clear, clone, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence, reversed, set, size, spliterator, toArray, toArray
Methods inherited from class java.util.AbstractSequentialList
iterator
Methods inherited from class java.util.AbstractList
equals, hashCode, listIterator, removeRange, subList
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, replaceAll, retainAll, sort, subList
-
Field Details
-
ascending
protected boolean ascendingThe ordering direction of the list. -
comp
The comparator to use (if any).
-
-
Constructor Details
-
SortedList
public SortedList()Constructs an empty list with ascending order. -
SortedList
public SortedList(boolean ascending) Constructs an empty list with given order.- Parameters:
ascending
- True, if the list should sort ascending.
-
SortedList
Constructs an empty list with given order.- Parameters:
comp
- A comparator to use for comparing elements.ascending
- True, if the list shoudl sort ascending.
-
-
Method Details
-
addFirst
Inserts the given element at the beginning of this list. -
addLast
Appends the given element to the end of this list. (Identical in function to the add method; included only for consistency.) -
add
Appends the specified element to the end of this list.- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceDeque<T>
- Specified by:
add
in interfaceList<T>
- Specified by:
add
in interfaceQueue<T>
- Overrides:
add
in classLinkedList<T>
- Parameters:
o
- element to be appended to this list.- Returns:
- true (as per the general contract of Collection.add).
-
addAll
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified Collection is this list, and this list is nonempty.)- Specified by:
addAll
in interfaceCollection<T>
- Specified by:
addAll
in interfaceDeque<T>
- Specified by:
addAll
in interfaceList<T>
- Overrides:
addAll
in classLinkedList<T>
- Parameters:
c
- the elements to be inserted into this list.- Returns:
- true if this list changed as a result of the call.
- Throws:
NullPointerException
- if the specified collection is null.
-
addAll
Inserts all of the elements in the specified collection into this list, starting at the specified position.- Specified by:
addAll
in interfaceList<T>
- Overrides:
addAll
in classLinkedList<T>
- Parameters:
index
- index at which to insert 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:
IndexOutOfBoundsException
- if the specified index is out of range (index < 0 || index > size()).NullPointerException
- if the specified collection is null.
-
add
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).- Specified by:
add
in interfaceList<T>
- Overrides:
add
in classLinkedList<T>
- Parameters:
index
- index at which the specified element is to be inserted.element
- element to be inserted.- Throws:
IndexOutOfBoundsException
- if the specified index is out of range (index < 0 || index > size()).
-
insertElement
Insert an element into the list.- Parameters:
index
- The index where to start insertion.obj
- The element to insert.- Returns:
- The index where the element was actually inserted.
-
compare
Compare two elements.
-