com.discoversites.util.collections
Class BoundedTreeSet<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.TreeSet<T>
              extended by com.discoversites.util.collections.BoundedTreeSet<T>
Type Parameters:
T - The type of element to be stored the BoundedTreeSet
All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, NavigableSet<T>, Set<T>, SortedSet<T>

public class BoundedTreeSet<T>
extends TreeSet<T>

An implementation of TreeSet that restricts the size of the tree to the size specified at construction. If adding an element to BoundedTreeSet results in the size of the set being maxSize + 1 then the element at the last position is removed. If maxSize is not specified then Integer.MAX_VALUE is used.

BoundedTreeSet is backed by the standard Java TreeSet implementation.

Author:
Mark
See Also:
Serialized Form

Constructor Summary
BoundedTreeSet()
           
BoundedTreeSet(Collection<? extends T> c)
           
BoundedTreeSet(Comparator<? super T> c)
           
BoundedTreeSet(int maxSize)
           
BoundedTreeSet(int maxSize, Collection<? extends T> c)
           
BoundedTreeSet(int maxSize, Comparator<? super T> comparator)
           
BoundedTreeSet(int maxSize, SortedSet<T> s)
           
BoundedTreeSet(SortedSet<T> set)
           
 
Method Summary
 boolean add(T element)
           
 boolean addAll(Collection<? extends T> c)
           
 
Methods inherited from class java.util.TreeSet
ceiling, clear, clone, comparator, contains, descendingIterator, descendingSet, first, floor, headSet, headSet, higher, isEmpty, iterator, last, lower, pollFirst, pollLast, remove, size, subSet, subSet, tailSet, tailSet
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

BoundedTreeSet

public BoundedTreeSet()

BoundedTreeSet

public BoundedTreeSet(Collection<? extends T> c)
Parameters:
c - A Collection of elements to be added to this BoundedTreeSet

BoundedTreeSet

public BoundedTreeSet(Comparator<? super T> c)
Parameters:
c - A Comparator implementation to be used for sorting the elements in this BoundedTreeSet

BoundedTreeSet

public BoundedTreeSet(SortedSet<T> set)
Parameters:
set - A SortedSet containing pre-sorted objects to be added to this BoundedTreeSet

BoundedTreeSet

public BoundedTreeSet(int maxSize,
                      Collection<? extends T> c)
Parameters:
maxSize - The max size of this BoundedTreeSet
c - A Collection of elements to be added to this BoundedTreeSet

BoundedTreeSet

public BoundedTreeSet(int maxSize,
                      Comparator<? super T> comparator)
Parameters:
maxSize - The max size of this BoundedTreeSet
comparator - A Comparator implementation to be used for sorting the elements in this BoundedTreeSet

BoundedTreeSet

public BoundedTreeSet(int maxSize,
                      SortedSet<T> s)
Parameters:
maxSize - The max size of this BoundedTreeSet
s - A SortedSet containing pre-sorted objects to be added to this BoundedTreeSet

BoundedTreeSet

public BoundedTreeSet(int maxSize)
Parameters:
maxSize - The max size of this BoundedTreeSet
Method Detail

add

public boolean add(T element)
Specified by:
add in interface Collection<T>
Specified by:
add in interface Set<T>
Overrides:
add in class TreeSet<T>

addAll

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