Class History

java.lang.Object
  |
  +--History

public class History
extends java.lang.Object

This class can be used to keep a history of objects. The history has a limited size and the when its capacity is reached the oldest entries will be removed as new are added.


Constructor Summary
History(int capacity)
          Creates a history with the given capacity.
 
Method Summary
 void addEntry(java.lang.Object entry)
          Adds an entry to the history.
 void clear()
          Used to clear the history.
 java.lang.Object entryAt(int index)
          Fetches a specific history entry.
 void replaceEntry(int index, java.lang.Object entry)
          Replaces a specific entry in the history with another.
 int size()
          Used to get the current size of the history.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

History

public History(int capacity)
Creates a history with the given capacity.
Parameters:
capacity - The number of entries the history can hold.
Method Detail

addEntry

public void addEntry(java.lang.Object entry)
Adds an entry to the history.
Parameters:
entry - The object to add.

entryAt

public java.lang.Object entryAt(int index)
Fetches a specific history entry. Note that the history is circular and the entry at history.size() is the same as the 0th entry.
Parameters:
index - The index of the entry to get, where 0 is the last entry.
Returns:
The object at the given index.

replaceEntry

public void replaceEntry(int index,
                         java.lang.Object entry)
Replaces a specific entry in the history with another.
Parameters:
index - The index of the entry to replace.
entry - The new entry to take its place.

clear

public void clear()
Used to clear the history.

size

public int size()
Used to get the current size of the history.
Returns:
The number of stored entries.