de.frag.umlplugin.history
Class HistoryList<T>

java.lang.Object
  extended by de.frag.umlplugin.history.HistoryList<T>
All Implemented Interfaces:
java.lang.Iterable<T>

public class HistoryList<T>
extends java.lang.Object
implements java.lang.Iterable<T>

Bounded list for history storage.


Constructor Summary
HistoryList(int maxSize)
          Creates a new bounded list with given maximum size.
 
Method Summary
 void add(T element)
          Adds the given element to this list.
 boolean canStepBack()
          Checks whether a step back in the history is possible.
 boolean canStepForward()
          Checks whether a step forward in the history is possible.
 void clear()
          Clears this history.
 int getMaxSize()
          Gets the maximum size of this bounded list.
 java.util.Iterator<T> iterator()
          Gets iterator that iterates over all active elements in this history list.
 void rewind()
          Rewinds history to beginning.
 int size()
          Gets the current size of this list.
 T stepBack()
          Steps back in the history and returns the corresponing element.
 T stepForward()
          Steps forward in the history and returns the corresponing element.
 java.util.List<T> toList(boolean includeForwardableEntries)
          Converts this history list to a list.
 java.lang.String toString()
          Returns a string representation of the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HistoryList

public HistoryList(int maxSize)
Creates a new bounded list with given maximum size.

Parameters:
maxSize - maximum size
Method Detail

iterator

@NotNull
public java.util.Iterator<T> iterator()
Gets iterator that iterates over all active elements in this history list.

Specified by:
iterator in interface java.lang.Iterable<T>
Returns:
iterator for iterating over all elements in history "past".

clear

public void clear()
Clears this history.


add

public void add(@NotNull
                T element)
Adds the given element to this list. If the list size exceeds the maximum size after adding the element, the list start will be truncated. if the element is inserted somewhere in the middle of the list because of calls to stepBack(), then alle elements after the added element will be discarded.

Parameters:
element - element to add

stepBack

@NotNull
public T stepBack()
Steps back in the history and returns the corresponing element. Without calls to stepBack(), the result will be the element that was added just before the last added element.

Returns:
current element

stepForward

@NotNull
public T stepForward()
Steps forward in the history and returns the corresponing element.

Returns:
current element

rewind

public void rewind()
Rewinds history to beginning.


canStepBack

public boolean canStepBack()
Checks whether a step back in the history is possible.

Returns:
true, if a step back is possible; false, if the current position is already the first list position.

canStepForward

public boolean canStepForward()
Checks whether a step forward in the history is possible.

Returns:
true, if a step forward is possible; false, if the current position is already the last list position.

size

public int size()
Gets the current size of this list.

Returns:
current size

getMaxSize

public int getMaxSize()
Gets the maximum size of this bounded list.

Returns:
maximum size

toList

@NotNull
public java.util.List<T> toList(boolean includeForwardableEntries)
Converts this history list to a list.

Parameters:
includeForwardableEntries - true, if entries that can be enabled by calls to stepForward() should be included; false otherwise
Returns:
converted list

toString

@NotNull
public java.lang.String toString()
Returns a string representation of the list.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the list.