Class SortedList<T>
java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractList<T>
java.util.ArrayList<T>
com.amalgamasimulation.utils.container.SortedList<T>
- Type Parameters:
T- the type of elements in this list
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<T>,Collection<T>,List<T>,RandomAccess,SequencedCollection<T>
- Direct Known Subclasses:
DoubleSortedList
List of elements that maintains order using the comparator specified at the
time of list's creation.
- Author:
- Andrey Malykhanov
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionSortedList(int size, Comparator<T> comparator) Constructs an empty sorted list with the specified initial capacity.SortedList(Collection<T> collection, Comparator<T> comparator) Constructs a sorted list containing the elements of the specified collection, in the order they are returned by the collection's iterator.SortedList(Comparator<T> comparator) Constructs an empty sorted list with an initial capacity of ten. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanAdds the specified element to this list.booleanaddAll(Collection<? extends T> collection) Returns the least element in this set greater than or equal to the given element, ornullif there is no such element.first()Returns the first element of this list, ornullif there is no such element (i.e.Returns the greatest element in this list less than or equal to the given element, ornullif there is no such element.intgetInsertionIndex(T element, boolean insertBefore) Returns an index at which the given element can be inserted to preserve order of the elements in this list.Returns a view of the portion of this list whose elements are strictly less than (or less than or equal to) the given element.last()Returns the last element of this list, ornullif there is no such element (i.e.Returns aListIteratorinstance pointing to the last item of this list.protected voidsetSortedElements(Collection<? extends T> collection) Returns a view of the portion of this list whose elements range from beginElement (inclusive or exclusive), to endElement (inclusive or exclusive).Returns a view of the portion of this list whose elements are greater than (or greater than or equal to) the given element.Methods inherited from class java.util.ArrayList
add, addAll, addFirst, addLast, clear, clone, contains, ensureCapacity, equals, forEach, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeIf, removeLast, removeRange, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll, reversed
-
Constructor Details
-
SortedList
Constructs an empty sorted list with an initial capacity of ten. The order of elements is defined by the given comparator.- Parameters:
comparator- comparator defining order of the elements
-
SortedList
Constructs an empty sorted list with the specified initial capacity. The order of elements is defined by the given comparator.- Parameters:
size- the initial capacity of the listcomparator- comparator defining order of the elements
-
SortedList
Constructs a sorted list containing the elements of the specified collection, in the order they are returned by the collection's iterator. The order of elements is defined by the given comparator.- Parameters:
collection- the collection whose elements are to be placed into this listcomparator- comparator defining order of the elements
-
-
Method Details
-
getInsertionIndex
Returns an index at which the given element can be inserted to preserve order of the elements in this list.- Parameters:
element- given elementinsertBefore- if true, the least possible index. If false, returns the greatest possible index- Returns:
- index at which the given element can be inserted to preserve order of the elements in this list
-
floor
Returns the greatest element in this list less than or equal to the given element, ornullif there is no such element.- Parameters:
element- given element- Returns:
- the greatest element less than or equal to the given element, or
nullif there is no such element
-
ceiling
Returns the least element in this set greater than or equal to the given element, ornullif there is no such element.- Parameters:
element- given element- Returns:
- the least element greater than or equal to the given element, or
nullif there is no such element
-
headList
Returns a view of the portion of this list whose elements are strictly less than (or less than or equal to) the given element.- Parameters:
element- given elementinclusive- iftrue, the list will contain elements that are equal to the given element- Returns:
- view of the portion of this list whose elements are strictly less than (or less than or equal to) the given element
-
tailList
Returns a view of the portion of this list whose elements are greater than (or greater than or equal to) the given element.- Parameters:
element- given elementinclusive- iftrue, the list will contain elements that are equal to the given element- Returns:
- view of the portion of this list whose elements are greater than (or greater than or equal to) the given element
-
subList
Returns a view of the portion of this list whose elements range from beginElement (inclusive or exclusive), to endElement (inclusive or exclusive).- Parameters:
beginElement- begin elementinclusiveBegin- iftrue, the list will contain elements that are equal to the beginElementendElement- end elementinclusiveEnd- iftrue, the list will contain elements that are equal to the endElement- Returns:
- view of the portion of this list whose elements range from beginElement (inclusive or exclusive), to endElement (inclusive or exclusive)
-
first
Returns the first element of this list, ornullif there is no such element (i.e. list is empty).- Returns:
- first element of this list, or
nullif there is no such element
-
last
Returns the last element of this list, ornullif there is no such element (i.e. list is empty).- Returns:
- last element of this list, or
nullif there is no such element
-
listIteratorAtLastItem
Returns aListIteratorinstance pointing to the last item of this list.- Returns:
ListIteratorinstance pointing to the last item of this list
-
add
-
add
Adds the specified element to this list. Allows to specify where this element must be inserted in the case of several other element existing in this list that are equal to the one being inserted.- Parameters:
element- the element being insertedinsertBefore- iftruethe element will be inserted before all other elements that are equal to the element being inserted. Otherwise, the element will be inserted after all such elements- Returns:
true(as specified byCollection.add(E))
-
addAll
-
setSortedElements
-
set
-