Class SortedList<T>
java.lang.Object
aQute.lib.collections.SortedList<T>
- Type Parameters:
T-
- All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, SequencedCollection<T>, SequencedSet<T>, Set<T>, SortedSet<T>
An immutable list that sorts objects by their natural order or through a
comparator. It has convenient methods/constructors to create it from
collections and iterators. Why not maintain the lists in their sorted form?
Well, TreeMaps are quite expensive ... I once profiled bnd and was shocked
how much memory the Jar class took due to the TreeMaps. I could not easily
change it unfortunately. The other reason is that Parameters uses a
LinkedHashMap because the preferred order should be the declaration order.
However, sometimes you need to sort the keys by name. Last, and most
important reason, is that sometimes you do not know what collection you have
or it is not available in a sort ordering (MultiMap for example) ... I found
myself sorting these things over and over again and decided to just make an
immutable SortedList that is easy to slice and dice
-
Constructor Summary
ConstructorsModifierConstructorDescription<C extends Comparable<? super T>>SortedList(C... x) SortedList(Collection<? extends Comparable<? super T>> x) SortedList(Collection<? extends T> x, int start, int end, Comparator<? super T> cmp) SortedList(Collection<? extends T> x, Comparator<? super T> cmp) SortedList(Comparator<? super T> cmp, T... x) SortedList(T[] x, int start, int end, Comparator<? super T> cmp) -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.booleanbooleanaddAll(int index, Collection<? extends T> c) Deprecated.booleanaddAll(Collection<? extends T> c) voidclear()Comparator<? super T> booleanbooleancontainsAll(Collection<?> c) static <T> SortedSet<T> empty()booleanDeprecated.first()static <T extends Comparable<? super T>>
SortedList<T> fromIterator(Iterator<? extends T> it) static <T> SortedList<T> fromIterator(Iterator<? extends T> it, Comparator<? super T> cmp) get(int index) Class<?> getType()booleaninthashCode()Deprecated.intbooleanisEmpty()booleanisEqual(SortedList<T> list) booleanisSubSet()iterator()last()intlistIterator(int index) remove(int index) Deprecated.booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) Deprecated.voidintsize()subList(int fromIndex, int toIndex) Object[]toArray()<X> X[]toArray(X[] a) toString()Methods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, replaceAll, reversed, sortMethods inherited from interface SortedSet
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, reversed
-
Constructor Details
-
SortedList
-
SortedList
-
SortedList
-
SortedList
-
SortedList
-
SortedList
-
-
Method Details
-
size
-
isEmpty
-
contains
-
iterator
-
toArray
-
toArray
-
add
-
remove
-
containsAll
- Specified by:
containsAllin interfaceCollection<T>- Specified by:
containsAllin interfaceList<T>- Specified by:
containsAllin interfaceSet<T>
-
addAll
-
retainAll
-
removeAll
-
clear
-
comparator
- Specified by:
comparatorin interfaceSortedSet<T>
-
isSubSet
public boolean isSubSet() -
subSet
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<T>
-
tailSet
-
headSet
-
first
-
last
-
addAll
Deprecated. -
get
-
set
-
add
Deprecated. -
remove
-
listIterator
- Specified by:
listIteratorin interfaceList<T>
-
listIterator
- Specified by:
listIteratorin interfaceList<T>
-
subList
-
equals
-
hashCode
-
isEqual
-
getType
-
setType
-
toString
-
hasDuplicates
public boolean hasDuplicates() -
fromIterator
public static <T extends Comparable<? super T>> SortedList<T> fromIterator(Iterator<? extends T> it) -
fromIterator
-
empty
-
spliterator
- Specified by:
spliteratorin interfaceCollection<T>- Specified by:
spliteratorin interfaceIterable<T>- Specified by:
spliteratorin interfaceList<T>- Specified by:
spliteratorin interfaceSet<T>- Specified by:
spliteratorin interfaceSortedSet<T>
-