de.cau.cs.kieler.sim.kiem.config.data
Class MostRecentCollection<T>

java.lang.Object
  extended by de.cau.cs.kieler.sim.kiem.config.data.MostRecentCollection<T>
Type Parameters:
T - The type of the items contained in the list.
All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, RandomAccess

public class MostRecentCollection<T>
extends Object
implements Collection<T>, RandomAccess, Cloneable, Serializable

This implements a collection that can update according to most recent use. New items will be added at index 0 and all items already in it will be pushed down. The oldest item may be deleted if the list is already at capacity.

If an item is added that is already in the list it will be moved to the top of the list.

Removing an item from the list has the same behavior as in a normal linked list.

See Also:
Serialized Form
Rating proposed yellow
(2010-01-27)

Constructor Summary
MostRecentCollection()
          Creates a new list with default capacity 10.
MostRecentCollection(int newCapacity)
          Create a new list.
MostRecentCollection(List<T> list)
          Creates a new handler for a given list.
MostRecentCollection(List<T> list, int capacityParam)
          Creates a new handler for a given list with a maximum capacity.
 
Method Summary
 boolean add(T e)
           Add a new item to the head of the list.
 boolean addAll(Collection<? extends T> c)
          
 void clear()
          
 MostRecentCollection<T> clone()
          Create a copy of this object, using a shallow copy.
 boolean contains(Object o)
          
 boolean containsAll(Collection<?> c)
          
 T get(int index)
          Get the element at the specified index.
 boolean isEmpty()
          
 Iterator<T> iterator()
          
 boolean remove(Object o)
          
 boolean removeAll(Collection<?> c)
          
 void replace(T oldElement, T newElement)
          Replaces the given element with the new one.
 boolean retainAll(Collection<?> c)
          
 int size()
          
 Object[] toArray()
          
<Type> Type[]
toArray(Type[] a)
          
 String toString()
          
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

MostRecentCollection

public MostRecentCollection()
Creates a new list with default capacity 10.


MostRecentCollection

public MostRecentCollection(int newCapacity)
Create a new list.

Parameters:
newCapacity - the maximum capacity of the list.

MostRecentCollection

public MostRecentCollection(List<T> list)
Creates a new handler for a given list.

Parameters:
list - the new list

MostRecentCollection

public MostRecentCollection(List<T> list,
                            int capacityParam)
Creates a new handler for a given list with a maximum capacity.

Parameters:
list - the new list
capacityParam - the maximum capacity of the list
Method Detail

add

public boolean add(T e)

Add a new item to the head of the list.

If the list already contains the new item it will be moved to the head and the rest of the list pushed down.

Specified by:
add in interface Collection<T>
Parameters:
e - the new element
Returns:
true if the element was added successfully

addAll

public boolean addAll(Collection<? extends T> c)

Specified by:
addAll in interface Collection<T>

clear

public void clear()

Specified by:
clear in interface Collection<T>

contains

public boolean contains(Object o)

Specified by:
contains in interface Collection<T>

containsAll

public boolean containsAll(Collection<?> c)

Specified by:
containsAll in interface Collection<T>

get

public T get(int index)
Get the element at the specified index.

Parameters:
index - index of the element to get.
Returns:
the element at the specified index.

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface Collection<T>

iterator

public Iterator<T> iterator()

Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>

remove

public boolean remove(Object o)

Specified by:
remove in interface Collection<T>

removeAll

public boolean removeAll(Collection<?> c)

Specified by:
removeAll in interface Collection<T>

retainAll

public boolean retainAll(Collection<?> c)

Specified by:
retainAll in interface Collection<T>

replace

public void replace(T oldElement,
                    T newElement)
Replaces the given element with the new one.

Parameters:
oldElement - the element to be replaced
newElement - the replacement element

size

public int size()

Specified by:
size in interface Collection<T>

toArray

public Object[] toArray()

Specified by:
toArray in interface Collection<T>

toArray

public <Type> Type[] toArray(Type[] a)

Specified by:
toArray in interface Collection<T>

toString

public String toString()

Overrides:
toString in class Object

clone

public MostRecentCollection<T> clone()
Create a copy of this object, using a shallow copy.

Overrides:
clone in class Object
Returns:
The new copy of the Object