Package com.storedobject.common
Class SortedList<E extends Comparable<E>>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>
com.storedobject.common.SortedList<E>
- Type Parameters:
E- the type of elements maintained by this list, extendingComparable.
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,List<E>,RandomAccess,SequencedCollection<E>
A custom implementation of an ArrayList that maintains its elements in sorted order.
Elements are required to implement the
Comparable interface.- Author:
- Syam
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty SortedList with an initial capacity of ten.SortedList(int initialCapacity) Constructs an empty SortedList with the specified initial capacity.SortedList(Collection<E> c) Constructs a new SortedList with elements from the specified collection. -
Method Summary
Methods inherited from class java.util.ArrayList
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
public SortedList()Constructs an empty SortedList with an initial capacity of ten. This list automatically maintains the sorting order of its elements. Elements added to the list must implement theComparableinterface. -
SortedList
public SortedList(int initialCapacity) Constructs an empty SortedList with the specified initial capacity. This list automatically maintains the sorting order of its elements. Elements added to the list must implement theComparableinterface.- Parameters:
initialCapacity- the initial capacity of the list. The capacity represents the number of elements that the list can hold before needing to resize.- Throws:
IllegalArgumentException- if the specified initial capacity is negative.
-
SortedList
Constructs a new SortedList with elements from the specified collection. The elements in the collection are added while maintaining their natural order. Duplicate elements are not added to the list.- Parameters:
c- the collection containing elements to be added to the sorted list. All elements in the collection must implement theComparableinterface. Passing a null collection results in aNullPointerException.
-
-
Method Details
-
add
- Specified by:
addin interfaceCollection<E extends Comparable<E>>- Specified by:
addin interfaceList<E extends Comparable<E>>- Overrides:
addin classArrayList<E extends Comparable<E>>
-
set
-
add
-
addAll
- Specified by:
addAllin interfaceCollection<E extends Comparable<E>>- Specified by:
addAllin interfaceList<E extends Comparable<E>>- Overrides:
addAllin classArrayList<E extends Comparable<E>>
-
addAll
- Specified by:
addAllin interfaceList<E extends Comparable<E>>- Overrides:
addAllin classArrayList<E extends Comparable<E>>
-