Package aQute.lib.collections
Class SortedList<T>
- java.lang.Object
-
- aQute.lib.collections.SortedList<T>
-
- Type Parameters:
T
-
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.List<T>
,java.util.Set<T>
,java.util.SortedSet<T>
public class SortedList<T> extends java.lang.Object implements java.util.SortedSet<T>, java.util.List<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
Constructors Constructor Description SortedList(C... x)
SortedList(java.util.Collection<? extends java.lang.Comparable<? super T>> x)
SortedList(java.util.Collection<? extends T> x, int start, int end, java.util.Comparator<? super T> cmp)
SortedList(java.util.Collection<? extends T> x, java.util.Comparator<? super T> cmp)
SortedList(java.util.Comparator<? super T> cmp, T... x)
SortedList(T[] x, int start, int end, java.util.Comparator<? super T> cmp)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(int index, T element)
Deprecated.boolean
add(T e)
boolean
addAll(int index, java.util.Collection<? extends T> c)
Deprecated.boolean
addAll(java.util.Collection<? extends T> c)
void
clear()
java.util.Comparator<? super T>
comparator()
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
static <T> java.util.SortedSet<T>
empty()
boolean
equals(java.lang.Object other)
Deprecated.T
first()
static <T extends java.lang.Comparable<? super T>>
SortedList<T>fromIterator(java.util.Iterator<? extends T> it)
static <T> SortedList<T>
fromIterator(java.util.Iterator<? extends T> it, java.util.Comparator<? super T> cmp)
T
get(int index)
java.lang.Class<?>
getType()
boolean
hasDuplicates()
int
hashCode()
Deprecated.SortedList<T>
headSet(T toElement)
int
indexOf(java.lang.Object o)
boolean
isEmpty()
boolean
isEqual(SortedList<T> list)
boolean
isSubSet()
java.util.Iterator<T>
iterator()
T
last()
int
lastIndexOf(java.lang.Object o)
java.util.ListIterator<T>
listIterator()
java.util.ListIterator<T>
listIterator(int index)
T
remove(int index)
Deprecated.boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
retainAll(java.util.Collection<?> c)
T
set(int index, T element)
Deprecated.void
setType(java.lang.Class<?> type)
int
size()
java.util.Spliterator<T>
spliterator()
SortedList<T>
subList(int fromIndex, int toIndex)
SortedList<T>
subSet(T fromElement, T toElement)
java.util.SortedSet<T>
tailSet(T fromElement)
java.lang.Object[]
toArray()
<X> X[]
toArray(X[] a)
java.lang.String
toString()
-
-
-
Method Detail
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(java.lang.Object o)
-
iterator
public java.util.Iterator<T> iterator()
-
toArray
public java.lang.Object[] toArray()
-
toArray
public <X> X[] toArray(X[] a)
-
add
public boolean add(T e)
-
remove
public boolean remove(java.lang.Object o)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
addAll
public boolean addAll(java.util.Collection<? extends T> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
clear
public void clear()
-
comparator
public java.util.Comparator<? super T> comparator()
- Specified by:
comparator
in interfacejava.util.SortedSet<T>
-
isSubSet
public boolean isSubSet()
-
subSet
public SortedList<T> subSet(T fromElement, T toElement)
- Specified by:
subSet
in interfacejava.util.SortedSet<T>
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOf
in interfacejava.util.List<T>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOf
in interfacejava.util.List<T>
-
tailSet
public java.util.SortedSet<T> tailSet(T fromElement)
- Specified by:
tailSet
in interfacejava.util.SortedSet<T>
-
headSet
public SortedList<T> headSet(T toElement)
- Specified by:
headSet
in interfacejava.util.SortedSet<T>
-
addAll
@Deprecated public boolean addAll(int index, java.util.Collection<? extends T> c)
Deprecated.- Specified by:
addAll
in interfacejava.util.List<T>
-
set
@Deprecated public T set(int index, T element)
Deprecated.- Specified by:
set
in interfacejava.util.List<T>
-
add
@Deprecated public void add(int index, T element)
Deprecated.- Specified by:
add
in interfacejava.util.List<T>
-
remove
@Deprecated public T remove(int index)
Deprecated.- Specified by:
remove
in interfacejava.util.List<T>
-
listIterator
public java.util.ListIterator<T> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<T>
-
listIterator
public java.util.ListIterator<T> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<T>
-
subList
public SortedList<T> subList(int fromIndex, int toIndex)
- Specified by:
subList
in interfacejava.util.List<T>
-
equals
@Deprecated public boolean equals(java.lang.Object other)
Deprecated.
-
hashCode
@Deprecated public int hashCode()
Deprecated.
-
isEqual
public boolean isEqual(SortedList<T> list)
-
getType
public java.lang.Class<?> getType()
-
setType
public void setType(java.lang.Class<?> type)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hasDuplicates
public boolean hasDuplicates()
-
fromIterator
public static <T extends java.lang.Comparable<? super T>> SortedList<T> fromIterator(java.util.Iterator<? extends T> it)
-
fromIterator
public static <T> SortedList<T> fromIterator(java.util.Iterator<? extends T> it, java.util.Comparator<? super T> cmp)
-
empty
public static <T> java.util.SortedSet<T> empty()
-
spliterator
public java.util.Spliterator<T> spliterator()
-
-