de.erichseifert.gral.util
Class SortedList<T extends Comparable<T>>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<T>
          extended by de.erichseifert.gral.util.SortedList<T>
Type Parameters:
T - Data type of stored elements.
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>

public class SortedList<T extends Comparable<T>>
extends AbstractList<T>

Resizable implementation of the List interface that automatically sorts all values. It implements the methods get, size, add, and size. The stored elements must implement the interface Comparable.


Constructor Summary
SortedList()
          Constructs an empty list with an initial capacity of ten.
SortedList(Collection<? extends T> c)
          Constructs a list containing the elements of the specified collection.
SortedList(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
 
Method Summary
 boolean add(T e)
           
 T get(int index)
           
 int indexOf(Object o)
           
 T remove(int index)
           
 int size()
           
 
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, iterator, lastIndexOf, listIterator, listIterator, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

SortedList

public SortedList(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - Initial capacity of the list.

SortedList

public SortedList(Collection<? extends T> c)
Constructs a list containing the elements of the specified collection.

Parameters:
c - Collection whose elements are to be added.

SortedList

public SortedList()
Constructs an empty list with an initial capacity of ten.

Method Detail

get

public T get(int index)
Specified by:
get in interface List<T extends Comparable<T>>
Specified by:
get in class AbstractList<T extends Comparable<T>>

size

public int size()
Specified by:
size in interface Collection<T extends Comparable<T>>
Specified by:
size in interface List<T extends Comparable<T>>
Specified by:
size in class AbstractCollection<T extends Comparable<T>>

add

public boolean add(T e)
Specified by:
add in interface Collection<T extends Comparable<T>>
Specified by:
add in interface List<T extends Comparable<T>>
Overrides:
add in class AbstractList<T extends Comparable<T>>

remove

public T remove(int index)
Specified by:
remove in interface List<T extends Comparable<T>>
Overrides:
remove in class AbstractList<T extends Comparable<T>>

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List<T extends Comparable<T>>
Overrides:
indexOf in class AbstractList<T extends Comparable<T>>


Copyright © 2009-2010. All Rights Reserved.