br.usp.ime.klava.segmentit.util
Class UndoRedo<T>

java.lang.Object
  extended by br.usp.ime.klava.segmentit.util.UndoRedo<T>
Type Parameters:
T - type of the states

public class UndoRedo<T>
extends java.lang.Object

Stores states from which is possible to undo/redo actions.

Author:
Bruno Klava

Constructor Summary
UndoRedo(int capacity)
          Creates a Undo/Redo structure that can store capacity states.
 
Method Summary
 void addNewState(T state)
          Adds a new state to the structure.
 T getCurrentState()
          Returns the current state.
 boolean isRedoAvailable()
          Returns if it is possible to go to a later state.
 boolean isUndoAvailable()
          Returns if it is possible to go to a previous state.
static void main(java.lang.String[] args)
           
 T redo()
          Returns the state after the current state.
 java.lang.String toString()
           
 T undo()
          Returns the state before the current state.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UndoRedo

public UndoRedo(int capacity)
Creates a Undo/Redo structure that can store capacity states.

Parameters:
capacity - the maximum number of states stored
Method Detail

isUndoAvailable

public boolean isUndoAvailable()
Returns if it is possible to go to a previous state.

Returns:
if it is possible to go to a previous state

isRedoAvailable

public boolean isRedoAvailable()
Returns if it is possible to go to a later state.

Returns:
if it is possible to go to a later state

undo

public T undo()
Returns the state before the current state.

Returns:
the state before the current state, null if there isn't any previous accessible state.

redo

public T redo()
Returns the state after the current state.

Returns:
the state after the current state, null if there isn't any later accessible state.

addNewState

public void addNewState(T state)
Adds a new state to the structure.

Parameters:
state - the state to be added to the structure

getCurrentState

public T getCurrentState()
Returns the current state.

Returns:
the current state, null if there isn't any state available

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)