antichess
Class MoveHistory<M extends Move>

java.lang.Object
  extended by antichess.MoveHistory<M>

public class MoveHistory<M extends Move>
extends Object

A linked-list implementation of the history of moves. Null Moves are permitted in the MoveHistory. MoveHistory's are immutable.

Specification Fields

Constructor Summary
MoveHistory(M lastMove)
          Creates a new MoveHistory m, with lastMove(m) = lastMove and an empty string as a timestamp.
MoveHistory(M lastMove, String timestamp)
          Creates a new MoveHistory with one Move
 
Method Summary
 MoveHistory<M> addMove(M move)
          Adds a move to the MoveHistory.
 MoveHistory<M> addMove(M move, String timestamp)
           
 List<M> getHistory()
           
 M getLastMove()
           
 String getLastMoveTime()
           
 List<String> getMoveTimes()
           
 MoveHistory<M> removeLastMove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MoveHistory

public MoveHistory(M lastMove)
Creates a new MoveHistory m, with lastMove(m) = lastMove and an empty string as a timestamp.

Parameters:
lastMove - the lastMove to add to the new MoveHistory.
Requires:
lastMove is a valid Move of type M
Effects:
Creates a MoveHistory with lastMove as its lastMove.

MoveHistory

public MoveHistory(M lastMove,
                   String timestamp)
Creates a new MoveHistory with one Move

Parameters:
lastMove - the lastMove to add to the new MoveHistory.
timestamp - the timestamp to associate with lastMove.
Requires:
  • lastMove is a valid Move of type M
  • timestamp is not null
Effects:
Creates a MoveHistory with lastMove as its lastMove, associated with the timestamp timestamp.
Method Detail

addMove

public MoveHistory<M> addMove(M move)
Adds a move to the MoveHistory. No timestamp is associated with the move.

Parameters:
move - the new Move to add to the MoveHistory
Returns:
the new MoveHistory with move added to the end of the old MoveHistory

addMove

public MoveHistory<M> addMove(M move,
                              String timestamp)
Parameters:
move - the new Move to add to the MoveHistory
timestamp - the timestamp to associate with this move.
Returns:
the new MoveHistory with move added to the end of the old MoveHistory.

removeLastMove

public MoveHistory<M> removeLastMove()
Returns:
The MoveHistory that has the last move removed from the end of the old MoveHistory.

getLastMove

public M getLastMove()
Returns:
the last move in the MoveHistory

getLastMoveTime

public String getLastMoveTime()
Returns:
the time the last move in the MoveHistory was made.

getHistory

public List<M> getHistory()
Returns:
a list of the moves in the MoveHistory from the earliest Move to the latest Move.

getMoveTimes

public List<String> getMoveTimes()
Returns:
a list of the moves timestamps in the MoveHistory from the earliest Move's timestamp to the latest Move's timestamp.