aQute.lib.collections
Class SortedList<T>

java.lang.Object
  extended by aQute.lib.collections.SortedList<T>
Type Parameters:
T -
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, Set<T>, SortedSet<T>

public class SortedList<T>
extends Object
implements SortedSet<T>, List<T>

An immutbale 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
SortedList(Collection<? extends Comparable<?>> x)
           
SortedList(Collection<? extends T> x, int start, int end, Comparator<T> cmp)
           
SortedList(Collection<T> x, Comparator<T> cmp)
           
SortedList(Comparator<T> cmp, T... x)
           
SortedList(T... x)
           
SortedList(T[] x, int start, int end, Comparator<T> comparator2)
           
 
Method Summary
 void add(int index, T element)
          Deprecated. 
 boolean add(T e)
           
 boolean addAll(Collection<? extends T> c)
           
 boolean addAll(int index, Collection<? extends T> c)
          Deprecated. 
 void clear()
           
 Comparator<? super T> comparator()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
static
<T> SortedSet<T>
empty()
           
 boolean equals(Object other)
          Deprecated. 
 T first()
           
static
<T extends Comparable<?>>
SortedList<T>
fromIterator(Iterator<T> it)
           
static
<T> SortedList<T>
fromIterator(Iterator<T> it, Comparator<T> cmp)
           
 T get(int index)
           
 Class<?> getType()
           
 boolean hasDuplicates()
           
 int hashCode()
          Deprecated. 
 SortedList<T> headSet(T toElement)
           
 int indexOf(Object o)
           
 boolean isEmpty()
           
 boolean isEqual(SortedList<T> list)
           
 boolean isSubSet()
           
 Iterator<T> iterator()
           
 T last()
           
 int lastIndexOf(Object o)
           
 ListIterator<T> listIterator()
           
 ListIterator<T> listIterator(int index)
           
 T remove(int index)
          Deprecated. 
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 T set(int index, T element)
          Deprecated. 
 void setType(Class<?> type)
           
 int size()
           
 SortedList<T> subList(int fromIndex, int toIndex)
           
 SortedList<T> subSet(T fromElement, T toElement)
           
 SortedSet<T> tailSet(T fromElement)
           
 Object[] toArray()
           
<X> X[]
toArray(X[] a)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SortedList

public SortedList(Collection<? extends Comparable<?>> x)

SortedList

public SortedList(Collection<T> x,
                  Comparator<T> cmp)

SortedList

public SortedList(T... x)

SortedList

public SortedList(Comparator<T> cmp,
                  T... x)

SortedList

public SortedList(T[] x,
                  int start,
                  int end,
                  Comparator<T> comparator2)

SortedList

public SortedList(Collection<? extends T> x,
                  int start,
                  int end,
                  Comparator<T> cmp)
Method Detail

size

public int size()
Specified by:
size in interface Collection<T>
Specified by:
size in interface List<T>
Specified by:
size in interface Set<T>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<T>
Specified by:
isEmpty in interface List<T>
Specified by:
isEmpty in interface Set<T>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<T>
Specified by:
contains in interface List<T>
Specified by:
contains in interface Set<T>

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>
Specified by:
iterator in interface List<T>
Specified by:
iterator in interface Set<T>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<T>
Specified by:
toArray in interface List<T>
Specified by:
toArray in interface Set<T>

toArray

public <X> X[] toArray(X[] a)
Specified by:
toArray in interface Collection<T>
Specified by:
toArray in interface List<T>
Specified by:
toArray in interface Set<T>

add

public boolean add(T e)
Specified by:
add in interface Collection<T>
Specified by:
add in interface List<T>
Specified by:
add in interface Set<T>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<T>
Specified by:
remove in interface List<T>
Specified by:
remove in interface Set<T>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<T>
Specified by:
containsAll in interface List<T>
Specified by:
containsAll in interface Set<T>

addAll

public boolean addAll(Collection<? extends T> c)
Specified by:
addAll in interface Collection<T>
Specified by:
addAll in interface List<T>
Specified by:
addAll in interface Set<T>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<T>
Specified by:
retainAll in interface List<T>
Specified by:
retainAll in interface Set<T>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<T>
Specified by:
removeAll in interface List<T>
Specified by:
removeAll in interface Set<T>

clear

public void clear()
Specified by:
clear in interface Collection<T>
Specified by:
clear in interface List<T>
Specified by:
clear in interface Set<T>

comparator

public Comparator<? super T> comparator()
Specified by:
comparator in interface SortedSet<T>

isSubSet

public boolean isSubSet()

subSet

public SortedList<T> subSet(T fromElement,
                            T toElement)
Specified by:
subSet in interface SortedSet<T>

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List<T>

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List<T>

tailSet

public SortedSet<T> tailSet(T fromElement)
Specified by:
tailSet in interface SortedSet<T>

headSet

public SortedList<T> headSet(T toElement)
Specified by:
headSet in interface SortedSet<T>

first

public T first()
Specified by:
first in interface SortedSet<T>

last

public T last()
Specified by:
last in interface SortedSet<T>

addAll

@Deprecated
public boolean addAll(int index,
                                 Collection<? extends T> c)
Deprecated. 

Specified by:
addAll in interface List<T>

get

public T get(int index)
Specified by:
get in interface List<T>

set

@Deprecated
public T set(int index,
                        T element)
Deprecated. 

Specified by:
set in interface List<T>

add

@Deprecated
public void add(int index,
                           T element)
Deprecated. 

Specified by:
add in interface List<T>

remove

@Deprecated
public T remove(int index)
Deprecated. 

Specified by:
remove in interface List<T>

listIterator

public ListIterator<T> listIterator()
Specified by:
listIterator in interface List<T>

listIterator

public ListIterator<T> listIterator(int index)
Specified by:
listIterator in interface List<T>

subList

public SortedList<T> subList(int fromIndex,
                             int toIndex)
Specified by:
subList in interface List<T>

equals

@Deprecated
public boolean equals(Object other)
Deprecated. 

Specified by:
equals in interface Collection<T>
Specified by:
equals in interface List<T>
Specified by:
equals in interface Set<T>
Overrides:
equals in class Object

hashCode

@Deprecated
public int hashCode()
Deprecated. 

Specified by:
hashCode in interface Collection<T>
Specified by:
hashCode in interface List<T>
Specified by:
hashCode in interface Set<T>
Overrides:
hashCode in class Object

isEqual

public boolean isEqual(SortedList<T> list)

getType

public Class<?> getType()

setType

public void setType(Class<?> type)

toString

public String toString()
Overrides:
toString in class Object

hasDuplicates

public boolean hasDuplicates()

fromIterator

public static <T extends Comparable<?>> SortedList<T> fromIterator(Iterator<T> it)

fromIterator

public static <T> SortedList<T> fromIterator(Iterator<T> it,
                                             Comparator<T> cmp)

empty

public static <T> SortedSet<T> empty()


Copyright © 2014 aQute SARL. All rights reserved.