csli.util.collections
Class SortedList<E extends Comparable<? super E>>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by csli.util.collections.SortedList<E>
Type Parameters:
E -
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>, Set<E>, SortedSet<E>

public class SortedList<E extends Comparable<? super E>>
extends AbstractList<E>
implements List<E>, SortedSet<E>

Red-black binary search tree. Basically I needed a SortedSet that was less set-like and more list-like. Main difference from SortedSet: allows multiple elements that compare as equal, and random access

Author:
jefe

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SortedList()
          Constructors.
SortedList(Collection<? extends E> elements)
           
SortedList(Comparator<? super E> comparator)
           
 
Method Summary
 boolean add(E o)
           
 void clear()
           
 Comparator<? super E> comparator()
           
protected  int compare(E x, E y)
           
 boolean contains(Object o)
           
 E first()
           
 E get(int index)
           
 SortedList<E> headSet(E toElement)
           
 Iterator<E> iterator()
           
 E last()
           
static void main(String[] args)
           
 E middle()
           
 int size()
           
 SortedSet<E> subSet(E fromElement, E toElement)
           
 SortedList<E> tailSet(E fromElement)
           
 
Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, addAll, addAll, containsAll, equals, hashCode, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, subList, toArray, toArray
 

Constructor Detail

SortedList

public SortedList()
Constructors.


SortedList

public SortedList(Collection<? extends E> elements)

SortedList

public SortedList(Comparator<? super E> comparator)
Method Detail

get

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

add

public boolean add(E o)
Specified by:
add in interface Collection<E extends Comparable<? super E>>
Specified by:
add in interface List<E extends Comparable<? super E>>
Specified by:
add in interface Set<E extends Comparable<? super E>>
Overrides:
add in class AbstractList<E extends Comparable<? super E>>

contains

public boolean contains(Object o)
                 throws ClassCastException
Specified by:
contains in interface Collection<E extends Comparable<? super E>>
Specified by:
contains in interface List<E extends Comparable<? super E>>
Specified by:
contains in interface Set<E extends Comparable<? super E>>
Overrides:
contains in class AbstractCollection<E extends Comparable<? super E>>
Throws:
ClassCastException - if parameter is not of type E.

compare

protected int compare(E x,
                      E y)

clear

public void clear()
Specified by:
clear in interface Collection<E extends Comparable<? super E>>
Specified by:
clear in interface List<E extends Comparable<? super E>>
Specified by:
clear in interface Set<E extends Comparable<? super E>>
Overrides:
clear in class AbstractList<E extends Comparable<? super E>>

size

public int size()
Specified by:
size in interface Collection<E extends Comparable<? super E>>
Specified by:
size in interface List<E extends Comparable<? super E>>
Specified by:
size in interface Set<E extends Comparable<? super E>>
Specified by:
size in class AbstractCollection<E extends Comparable<? super E>>

first

public E first()
Specified by:
first in interface SortedSet<E extends Comparable<? super E>>

last

public E last()
Specified by:
last in interface SortedSet<E extends Comparable<? super E>>

middle

public E middle()

comparator

public Comparator<? super E> comparator()
Specified by:
comparator in interface SortedSet<E extends Comparable<? super E>>

headSet

public SortedList<E> headSet(E toElement)
Specified by:
headSet in interface SortedSet<E extends Comparable<? super E>>

tailSet

public SortedList<E> tailSet(E fromElement)
Specified by:
tailSet in interface SortedSet<E extends Comparable<? super E>>

subSet

public SortedSet<E> subSet(E fromElement,
                           E toElement)
Specified by:
subSet in interface SortedSet<E extends Comparable<? super E>>

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E extends Comparable<? super E>>
Specified by:
iterator in interface Collection<E extends Comparable<? super E>>
Specified by:
iterator in interface List<E extends Comparable<? super E>>
Specified by:
iterator in interface Set<E extends Comparable<? super E>>
Overrides:
iterator in class AbstractList<E extends Comparable<? super E>>

main

public static void main(String[] args)