Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.command
Class NextCommand<E>

java.lang.Object
  extended by dk.rode.thesis.command.SequenceCommand<E>
      extended by dk.rode.thesis.command.NextCommand<E>
Type Parameters:
E - The type of result obtained by executing this command. The type corresponds to the type of values delivered by the receiver sequence.
All Implemented Interfaces:
Command<E>, Copyable<Command<E>>, StrictCopyable<Command<E>>

@Participant(value="ConcreteCommand")
public class NextCommand<E>
extends SequenceCommand<E>

A next command command will invoke next() on its receiving sequence when it is executed.

Next commands are undoable if the receiving sequence is a reversible and/or a memorizable sequence!

Author:
Gunni Rode / rode.dk

Field Summary
 
Fields inherited from class dk.rode.thesis.command.SequenceCommand
result, sequence
 
Constructor Summary
NextCommand(Sequence<E> sequence)
          Constructor.
 
Method Summary
 NextCommand<E> copy()
          Creates a copy of this command, excluding internal state information required for execution and undo.
protected  List<Command<E>> doExecute(boolean saved)
          Sets the result of the execution to the next sequence value.
 boolean isUndoable()
          Returns true if this command has been executed and the receiving sequence used by this command is either memorizable and/or reversible.
 E undo()
          Performs undo of this sequence command if possible.
 
Methods inherited from class dk.rode.thesis.command.SequenceCommand
equals, execute, getResult, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NextCommand

public NextCommand(@Participant(value="Receiver")
                   Sequence<E> sequence)
Constructor.

Parameters:
sequence - The sequence; cannot be null.
Throws:
NullPointerException - If sequence is null.
Method Detail

copy

public NextCommand<E> copy()
Description copied from interface: Command
Creates a copy of this command, excluding internal state information required for execution and undo.

Returns:
A new instance of this command; never null.

doExecute

protected List<Command<E>> doExecute(boolean saved)
Sets the result of the execution to the next sequence value.

Specified by:
doExecute in class SequenceCommand<E>
Parameters:
saved - True if the before state was successfully saved before this method is invoked, false if not.
Returns:
A list of spawned commands, if any, to be executed by the command processor currently executing this command. Can be null or empty.
See Also:
SequenceCommand.execute()

isUndoable

public boolean isUndoable()
Returns true if this command has been executed and the receiving sequence used by this command is either memorizable and/or reversible.

Specified by:
isUndoable in interface Command<E>
Overrides:
isUndoable in class SequenceCommand<E>
Returns:
True if undoable, false if not.

undo

public E undo()
       throws CommandException
Description copied from class: SequenceCommand
Performs undo of this sequence command if possible.

If this command is not undoable an exception will be thrown. If this command cannot be undone otherwise, null will be returned.

The command result value is cleared.

Specified by:
undo in interface Command<E>
Overrides:
undo in class SequenceCommand<E>
Returns:
If this command could be undone, the (new) current sequence value is returned; otherwise null.
Throws:
CommandException - In case this command is not undoable.

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.