Package aQute.lib.collections
Class SortedList<T>
java.lang.Object
aQute.lib.collections.SortedList<T>
- Type Parameters:
T-
- All Implemented Interfaces:
Iterable<T>,Collection<T>,List<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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Comparator<? super T>private static final SortedList<?>private final intprivate final T[]private final intprivate Class<?> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateprivateSortedList(SortedList<T> other, int start, int end) 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>private intbooleanbooleancontainsAll(Collection<?> c) static <T> SortedSet<T>empty()booleanDeprecated.private intFind the first element that is equal or bigger than the given elementfirst()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 class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
replaceAll, sort
-
Field Details
-
EMPTY
-
list
-
start
private final int start -
end
private final int end -
comparator
-
type
-
-
Constructor Details
-
SortedList
-
SortedList
-
SortedList
-
SortedList
-
SortedList
-
SortedList
-
SortedList
-
SortedList
private SortedList()
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
-
iterator
-
toArray
-
toArray
public <X> X[] toArray(X[] a) -
add
-
remove
-
containsAll
- Specified by:
containsAllin interfaceCollection<T>- Specified by:
containsAllin interfaceList<T>- Specified by:
containsAllin interfaceSet<T>
-
addAll
-
retainAll
-
removeAll
-
clear
public void clear() -
comparator
- Specified by:
comparatorin interfaceSortedSet<T>
-
compare
-
isSubSet
public boolean isSubSet() -
subSet
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<T>
-
find
Find the first element that is equal or bigger than the given element- Parameters:
toElement-- Returns:
- absolute index (not relative!), returns end if not found
-
tailSet
-
headSet
-
first
-
last
-
addAll
Deprecated. -
get
-
set
Deprecated. -
add
Deprecated. -
remove
Deprecated. -
listIterator
- Specified by:
listIteratorin interfaceList<T>
-
listIterator
- Specified by:
listIteratorin interfaceList<T>
-
subList
-
equals
Deprecated. -
hashCode
Deprecated. -
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>
-