org.nuiton.util
Class BoundedList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<E>
              extended by org.nuiton.util.BoundedList<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess

public class BoundedList<E>
extends ArrayList<E>

ArrayList with minimum and maximum sizes. For each operation, the size is checked and the BoundedList to ensure that it is kept in the range.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
BoundedList()
          Creates a new BoundedList with the default capacity.
BoundedList(Collection<E> arg0)
          Creates a new BoundedList with the specified collection of elements.
BoundedList(int initialCapacity)
          Creates a new BoundedList with the specified initialCapacity.
BoundedList(int minSize, int maxSize)
          Creates a new empty BoundedList with the specified min and max sizes.
 
Method Summary
 boolean add(E o)
          Appends the specified element to the end of this list.
 void add(int index, E o)
          Inserts the specified element at the specified position in this list.
 boolean addAll(Collection<? extends E> c)
          Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collection's Iterator.
 boolean addAll(int index, Collection<? extends E> c)
          Inserts all of the elements in the specified Collection into this list, starting at the specified position.
 Object clone()
          Returns a shallow copy of this BoundedList instance
 boolean isFull()
          Indicates if the list size is at the maximum
 boolean isToMinimum()
          Indicates if the list size is to the minimum
 E remove(int index)
          Removes the element at the specified position in this list.
 boolean remove(Object o)
          Removes a single instance of the specified element from this list, if it is present (optional operation).
 boolean removeAll(Collection<?> c)
          Removes from this collection all of its elements that are contained in the specified collection (optional operation).
protected  void removeRange(int fromIndex, int toIndex)
          Removes from this List all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive.
 String toString()
           
 
Methods inherited from class java.util.ArrayList
clear, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, retainAll, subList
 

Constructor Detail

BoundedList

public BoundedList(int initialCapacity)
Creates a new BoundedList with the specified initialCapacity. The min size is set to 0 and the max size to the infinite.

Parameters:
initialCapacity -

BoundedList

public BoundedList()
Creates a new BoundedList with the default capacity. The min size is set to 0 and the max size to the infinite.


BoundedList

public BoundedList(Collection<E> arg0)
Creates a new BoundedList with the specified collection of elements. The min size is set to 0 and the max size to the infinite.

Parameters:
arg0 -

BoundedList

public BoundedList(int minSize,
                   int maxSize)
Creates a new empty BoundedList with the specified min and max sizes. Please be informed that -1 represents the infinite.

Parameters:
minSize -
maxSize -
Method Detail

isFull

public boolean isFull()
Indicates if the list size is at the maximum

Returns:
true is the maximum size has been reached

isToMinimum

public boolean isToMinimum()
Indicates if the list size is to the minimum

Returns:
true is the list size is the minimum size

add

public boolean add(E o)
Appends the specified element to the end of this list.

Specified by:
add in interface Collection<E>
Specified by:
add in interface List<E>
Overrides:
add in class ArrayList<E>
Parameters:
o - the Object to be added

add

public void add(int index,
                E o)
Inserts the specified element at the specified position in this list.

Specified by:
add in interface List<E>
Overrides:
add in class ArrayList<E>
Parameters:
index - the position where to add the Object
o - the Object to be added

addAll

public boolean addAll(Collection<? extends E> c)
Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collection's Iterator.

Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>
Overrides:
addAll in class ArrayList<E>
Parameters:
c - the collection of Objects to be added

addAll

public boolean addAll(int index,
                      Collection<? extends E> c)
Inserts all of the elements in the specified Collection into this list, starting at the specified position.

Specified by:
addAll in interface List<E>
Overrides:
addAll in class ArrayList<E>
Parameters:
index - the index where to start adding the collection of objects
c - the collection of Objects to be added

clone

public Object clone()
Returns a shallow copy of this BoundedList instance

Overrides:
clone in class ArrayList<E>

remove

public E remove(int index)
Removes the element at the specified position in this list.

Specified by:
remove in interface List<E>
Overrides:
remove in class ArrayList<E>
Parameters:
index - the position of the element to be removed

removeRange

protected void removeRange(int fromIndex,
                           int toIndex)
Removes from this List all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive.

Overrides:
removeRange in class ArrayList<E>
Parameters:
fromIndex - index of first element to be removed
toIndex - index after last element to be removed

remove

public boolean remove(Object o)
Removes a single instance of the specified element from this list, if it is present (optional operation).

Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>
Overrides:
remove in class ArrayList<E>

removeAll

public boolean removeAll(Collection<?> c)
Removes from this collection all of its elements that are contained in the specified collection (optional operation).

Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface List<E>
Overrides:
removeAll in class AbstractCollection<E>

toString

public String toString()
Overrides:
toString in class AbstractCollection<E>


Copyright © 2004-2009 CodeLutin. All Rights Reserved.