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 booleanThe 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 TypeMethodDescriptionvoidInserts the specified element at the specified position in this list.booleanAppends the specified element to the end of this list.booleanaddAll(int index, Collection<? extends T> c) Inserts all of the elements in the specified collection into this list, starting at the specified position.booleanaddAll(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.voidInserts the given element at the beginning of this list.voidAppends the given element to the end of this list.protected intCompare two elements.intinsertElement(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, toArrayMethods inherited from class java.util.AbstractSequentialList
iteratorMethods inherited from class java.util.AbstractList
equals, hashCode, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods 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:
addin interfaceCollection<T>- Specified by:
addin interfaceDeque<T>- Specified by:
addin interfaceList<T>- Specified by:
addin interfaceQueue<T>- Overrides:
addin 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:
addAllin interfaceCollection<T>- Specified by:
addAllin interfaceDeque<T>- Specified by:
addAllin interfaceList<T>- Overrides:
addAllin 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:
addAllin interfaceList<T>- Overrides:
addAllin 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:
addin interfaceList<T>- Overrides:
addin 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.
-