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 int
private final T[]
private final int
private Class<?>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
private
SortedList
(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 TypeMethodDescriptionvoid
Deprecated.boolean
boolean
addAll
(int index, Collection<? extends T> c) Deprecated.boolean
addAll
(Collection<? extends T> c) void
clear()
Comparator<? super T>
private int
boolean
boolean
containsAll
(Collection<?> c) static <T> SortedSet<T>
empty()
boolean
Deprecated.private int
Find 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()
boolean
int
hashCode()
Deprecated.int
boolean
isEmpty()
boolean
isEqual
(SortedList<T> list) boolean
isSubSet()
iterator()
last()
int
listIterator
(int index) remove
(int index) Deprecated.boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) Deprecated.void
int
size()
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, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods 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:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceList<T>
- Specified by:
containsAll
in interfaceSet<T>
-
addAll
-
retainAll
-
removeAll
-
clear
public void clear() -
comparator
- Specified by:
comparator
in interfaceSortedSet<T>
-
compare
-
isSubSet
public boolean isSubSet() -
subSet
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in 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:
listIterator
in interfaceList<T>
-
listIterator
- Specified by:
listIterator
in 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:
spliterator
in interfaceCollection<T>
- Specified by:
spliterator
in interfaceIterable<T>
- Specified by:
spliterator
in interfaceList<T>
- Specified by:
spliterator
in interfaceSet<T>
- Specified by:
spliterator
in interfaceSortedSet<T>
-