org.xith3d.utility.general
Class SortableList<E extends java.lang.Comparable<E>>

java.lang.Object
  extended by org.xith3d.utility.general.SortableList<E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>

public class SortableList<E extends java.lang.Comparable<E>>
extends java.lang.Object
implements java.util.List<E>

This is a java.util.List implementation, that provides insitu sorting of the elements.
This is very useful to work GC-friendly with Lists.
It also has singleton Iterators.


Constructor Summary
SortableList()
          Creates a new SortableList with an initial size of 16.
SortableList(int initialCapacity)
          Creates a new SortableList with an initial size of initialSize.
 
Method Summary
 boolean add(E element)
          
 void add(int index, E element)
          
 boolean addAll(java.util.Collection<? extends E> coll)
          
 boolean addAll(int index, java.util.Collection<? extends E> coll)
          
 void clear()
          
 java.lang.Object clone()
          Returns a shallow copy of this SortableList instance.
 boolean contains(java.lang.Object o)
          
 boolean containsAll(java.util.Collection<?> coll)
          
 void ensureCapacity(int minCapacity)
          Increases the capacity of this SortableList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
 E get(int index)
          
 int indexOf(java.lang.Object o)
          
 boolean isEmpty()
          
 java.util.Iterator<E> iterator()
          
 int lastIndexOf(java.lang.Object o)
          
 java.util.ListIterator<E> listIterator()
          
 java.util.ListIterator<E> listIterator(int index)
          
 E remove(int index)
          
 boolean remove(java.lang.Object o)
          
 boolean removeAll(java.util.Collection<?> coll)
          
 boolean retainAll(java.util.Collection<?> coll)
          
 E set(int index, E element)
          
 int size()
          
 void sort()
          Sets the list insutu using a mergesort.
 java.util.List<E> subList(int fromIndex, int toIndex)
          
 java.lang.Object[] toArray()
          
<T> T[]
toArray(T[] a)
          
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Constructor Detail

SortableList

public SortableList(int initialCapacity)
Creates a new SortableList with an initial size of initialSize.

Parameters:
initialCapacity -

SortableList

public SortableList()
Creates a new SortableList with an initial size of 16.

Method Detail

ensureCapacity

public void ensureCapacity(int minCapacity)
Increases the capacity of this SortableList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

Parameters:
minCapacity - the desired minimum capacity

size

public int size()

Specified by:
size in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
size in interface java.util.List<E extends java.lang.Comparable<E>>

add

public void add(int index,
                E element)

Specified by:
add in interface java.util.List<E extends java.lang.Comparable<E>>

add

public boolean add(E element)

Specified by:
add in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
add in interface java.util.List<E extends java.lang.Comparable<E>>

addAll

public boolean addAll(java.util.Collection<? extends E> coll)

Specified by:
addAll in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
addAll in interface java.util.List<E extends java.lang.Comparable<E>>

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends E> coll)

Specified by:
addAll in interface java.util.List<E extends java.lang.Comparable<E>>

clear

public void clear()

Specified by:
clear in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
clear in interface java.util.List<E extends java.lang.Comparable<E>>

contains

public boolean contains(java.lang.Object o)

Specified by:
contains in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
contains in interface java.util.List<E extends java.lang.Comparable<E>>

containsAll

public boolean containsAll(java.util.Collection<?> coll)

Specified by:
containsAll in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
containsAll in interface java.util.List<E extends java.lang.Comparable<E>>

get

public E get(int index)

Specified by:
get in interface java.util.List<E extends java.lang.Comparable<E>>

indexOf

public int indexOf(java.lang.Object o)

Specified by:
indexOf in interface java.util.List<E extends java.lang.Comparable<E>>

lastIndexOf

public int lastIndexOf(java.lang.Object o)

Specified by:
lastIndexOf in interface java.util.List<E extends java.lang.Comparable<E>>

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
isEmpty in interface java.util.List<E extends java.lang.Comparable<E>>

iterator

public java.util.Iterator<E> iterator()

Specified by:
iterator in interface java.lang.Iterable<E extends java.lang.Comparable<E>>
Specified by:
iterator in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
iterator in interface java.util.List<E extends java.lang.Comparable<E>>

listIterator

public java.util.ListIterator<E> listIterator(int index)

Specified by:
listIterator in interface java.util.List<E extends java.lang.Comparable<E>>

listIterator

public java.util.ListIterator<E> listIterator()

Specified by:
listIterator in interface java.util.List<E extends java.lang.Comparable<E>>

remove

public E remove(int index)

Specified by:
remove in interface java.util.List<E extends java.lang.Comparable<E>>

remove

public boolean remove(java.lang.Object o)

Specified by:
remove in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
remove in interface java.util.List<E extends java.lang.Comparable<E>>

removeAll

public boolean removeAll(java.util.Collection<?> coll)

Specified by:
removeAll in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
removeAll in interface java.util.List<E extends java.lang.Comparable<E>>

retainAll

public boolean retainAll(java.util.Collection<?> coll)

Specified by:
retainAll in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
retainAll in interface java.util.List<E extends java.lang.Comparable<E>>

set

public E set(int index,
             E element)

Specified by:
set in interface java.util.List<E extends java.lang.Comparable<E>>

subList

public java.util.List<E> subList(int fromIndex,
                                 int toIndex)

Specified by:
subList in interface java.util.List<E extends java.lang.Comparable<E>>

toArray

public java.lang.Object[] toArray()

Specified by:
toArray in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
toArray in interface java.util.List<E extends java.lang.Comparable<E>>

toArray

public <T> T[] toArray(T[] a)

Specified by:
toArray in interface java.util.Collection<E extends java.lang.Comparable<E>>
Specified by:
toArray in interface java.util.List<E extends java.lang.Comparable<E>>

clone

public java.lang.Object clone()
Returns a shallow copy of this SortableList instance. (The elements themselves are not copied.)

Overrides:
clone in class java.lang.Object
Returns:
a clone of this SortableList instance

sort

public void sort()
Sets the list insutu using a mergesort.

See Also:
Arrays.sort(Object[])