java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
net.luis.utils.collection.SortedList<E>
- Type Parameters:
E
- The type of the elements
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,List<E>
,SequencedCollection<E>
A list which is after every modification sorted
using the set comparator or if it is
using the set comparator or if it is
null
the natural order.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Comparator
<E> The comparator used to sort the list.The internal list.Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorsConstructorDescriptionSortedList
(E @NotNull ... elements) Constructs a new sorted list with the given elements.
The comparator is set tonull
.
The elements are wrapped in an internalArrayList
.SortedList
(@NotNull List<E> elements) Constructs a new sorted list with from the given list.
The comparator is set tonull
.
The list is not copied, it is used directly.SortedList
(@NotNull List<E> elements, @Nullable Comparator<E> comparator) Constructs a new sorted list from the given list and the comparator.
The list is not copied, it is used directly.SortedList
(@Nullable Comparator<E> comparator) SortedList
(@Nullable Comparator<E> comparator, E @NotNull ... elements) Constructs a new sorted list with the given elements and the comparator.
The elements are wrapped in an internalArrayList
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
The list is sorted after the element is added.private static <E> @NotNull List
<E> createList
(E @NotNull ... elements) get
(int index) boolean
The list is sorted after the element is removed.
The list is sorted after the element is added.void
setComparator
(@Nullable Comparator<E> comparator) Sets the comparator used to sort the list.int
size()
void
sort
(@Nullable Comparator<? super E> comparator) The list is sorted with the comparator of this list.Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, 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.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, spliterator, toArray, toArray
-
Field Details
-
internalList
The internal list. -
comparator
The comparator used to sort the list.
-
-
Constructor Details
-
SortedList
public SortedList() -
SortedList
- Parameters:
comparator
- The comparator used to sort the list
-
SortedList
Constructs a new sorted list with the given elements.
The comparator is set tonull
.
The elements are wrapped in an internalArrayList
.- Parameters:
elements
- The elements to add
-
SortedList
@SafeVarargs public SortedList(@Nullable @Nullable Comparator<E> comparator, E @NotNull ... elements) Constructs a new sorted list with the given elements and the comparator.
The elements are wrapped in an internalArrayList
.- Parameters:
comparator
- The comparator used to sort the listelements
- The elements to add
-
SortedList
Constructs a new sorted list with from the given list.
The comparator is set tonull
.
The list is not copied, it is used directly.- Parameters:
elements
- The list to use- Throws:
NullPointerException
- If the list is null
-
SortedList
Constructs a new sorted list from the given list and the comparator.
The list is not copied, it is used directly.- Parameters:
elements
- The list to usecomparator
- The comparator used to sort the list- Throws:
NullPointerException
- If the list is null
-
-
Method Details
-
createList
- Type Parameters:
E
- The type of the elements- Parameters:
elements
- The elements to add- Returns:
- The new list
- Throws:
NullPointerException
- If the elements are null
-
setComparator
Sets the comparator used to sort the list.- Parameters:
comparator
- The comparator to set
-
set
The list is sorted after the element is added. -
add
The list is sorted after the element is added. -
remove
The list is sorted after the element is removed.- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractCollection<E>
-
get
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
-
sort
The list is sorted with the comparator of this list.- Parameters:
comparator
- The ignored comparator
-