net.spy.util
Class LimitedList<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.AbstractSequentialList<E>
              extended by java.util.LinkedList<T>
                  extended by net.spy.util.LimitedList<T>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, java.util.Queue<T>

public class LimitedList<T>
extends java.util.LinkedList<T>

A LinkedList with a maximum capacity.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
LimitedList(int l)
          Get an instance of Queue.
 
Method Summary
 void add(int index, T o)
          Override add to enforce the limit.
 boolean add(T o)
          Override add to enforce the limit.
 boolean addAll(java.util.Collection<? extends T> c)
          Override addAll to enforce the limit.
 boolean addAll(int index, java.util.Collection<? extends T> c)
          Override addAll to enforce the limit.
 void addFirst(T o)
          Override addFirst to enforce the limit.
 void addLast(T o)
          Override addLast to enforce the limit.
 int getLimit()
          Get the maximum number of elements that may be stored in this list.
 void setLimit(int to)
          Dynamically reset the limit.
 
Methods inherited from class java.util.LinkedList
clear, clone, contains, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, peek, poll, remove, remove, remove, removeFirst, removeLast, set, size, toArray, toArray
 
Methods inherited from class java.util.AbstractSequentialList
iterator
 
Methods inherited from class java.util.AbstractList
equals, hashCode, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

LimitedList

public LimitedList(int l)
Get an instance of Queue.

Method Detail

setLimit

public void setLimit(int to)
Dynamically reset the limit. This will not have an effect on existing items, but will prevent new items from being added if the limit is exceeded.

Parameters:
to - the new limit value

getLimit

public int getLimit()
Get the maximum number of elements that may be stored in this list.


add

public void add(int index,
                T o)
Override add to enforce the limit.

Specified by:
add in interface java.util.List<T>
Overrides:
add in class java.util.LinkedList<T>
Parameters:
index - index at which to add
o - object to add
Throws:
java.lang.IndexOutOfBoundsException - if the limit is exceeded (or the parent size thinks it's too big).

add

public boolean add(T o)
Override add to enforce the limit.

Specified by:
add in interface java.util.Collection<T>
Specified by:
add in interface java.util.List<T>
Overrides:
add in class java.util.LinkedList<T>
Parameters:
o - object to add
Throws:
java.lang.IndexOutOfBoundsException - if the limit is exceeded (or the parent size thinks it's too big).

addFirst

public void addFirst(T o)
Override addFirst to enforce the limit.

Overrides:
addFirst in class java.util.LinkedList<T>
Parameters:
o - object to add
Throws:
java.lang.IndexOutOfBoundsException - if the limit is exceeded (or the parent size thinks it's too big).

addLast

public void addLast(T o)
Override addLast to enforce the limit.

Overrides:
addLast in class java.util.LinkedList<T>
Parameters:
o - object to add
Throws:
java.lang.IndexOutOfBoundsException - if the limit is exceeded (or the parent size thinks it's too big).

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends T> c)
Override addAll to enforce the limit.

Specified by:
addAll in interface java.util.List<T>
Overrides:
addAll in class java.util.LinkedList<T>
Parameters:
index - the index at which to add the collection
c - Collectoin of objects to add
Throws:
java.lang.IndexOutOfBoundsException - if the limit is exceeded (or the parent size thinks it's too big).

addAll

public boolean addAll(java.util.Collection<? extends T> c)
Override addAll to enforce the limit.

Specified by:
addAll in interface java.util.Collection<T>
Specified by:
addAll in interface java.util.List<T>
Overrides:
addAll in class java.util.LinkedList<T>
Parameters:
c - Collectoin of objects to add
Throws:
java.lang.IndexOutOfBoundsException - if the limit is exceeded (or the parent size thinks it's too big).


Copyright © 1995-2006 SPY Internetworking. All Rights Reserved.