|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.rode.thesis.command.SequenceCommand<E> dk.rode.thesis.command.ReverseCommand<E>
E
- The type of result obtained by executing this command.
The type corresponds to the type of values delivered by
the receiver sequence.@Participant(value="ConcreteCommand") public class ReverseCommand<E>
A reserve command command will reverse
a given sequence when it is executed
, if
possible.
Only currently reversible
sequences are affected by this command per default. However, a list of
commands can be supplied at construction time to be spawned during
execution for non-reversible sequences.
Undo of spawned commands is not handled by this command.
Field Summary | |
---|---|
private List<Command<E>> |
commands
Command instances to spawn in case the sequence is not reversible, if any. |
private Boolean |
reversed
True if this command successfully reversed a reversible sequence, false if not. |
Fields inherited from class dk.rode.thesis.command.SequenceCommand |
---|
result, sequence |
Constructor Summary | |
---|---|
ReverseCommand(ReverseCommand<E> command)
Copy constructor. |
|
ReverseCommand(Sequence<E> sequence)
Constructor. |
|
ReverseCommand(Sequence<E> sequence,
Command<E>... commands)
Constructor. |
Method Summary | |
---|---|
ReverseCommand<E> |
copy()
Creates a copy of this command, excluding internal state information required for execution and undo. |
protected List<Command<E>> |
doExecute(boolean saved)
Reverses the sequence if reversible and returns the current (same) value. |
boolean |
isUndoable()
Returns true if the receiving sequence is reversible ,
false if not. |
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 |
Field Detail |
---|
private final List<Command<E>> commands
Undo of spawned commands is not handled by this command.
Can be null.
private Boolean reversed
Will be null if this command has not been executed.
Constructor Detail |
---|
public ReverseCommand(ReverseCommand<E> command)
Commands to spawned, if any, will also be copied.
command
- The command to copy; cannot be null.
NullPointerException
- If command
is null.public ReverseCommand(@Participant(value="Receiver") Sequence<E> sequence)
sequence
- The sequence; cannot be null.
NullPointerException
- If sequence
is null.public ReverseCommand(@Participant(value="Receiver") Sequence<E> sequence, Command<E>... commands)
The commands supplied as commands
, if any, will be
spawned in order during execution
in case
sequence
cannot be reversed.
sequence
- The sequence; cannot be null.commands
- The commands to possible spawn; can be null or empty.
NullPointerException
- If sequence
is null.Method Detail |
---|
public ReverseCommand<E> copy()
Command
protected List<Command<E>> doExecute(boolean saved)
reversible
and returns the current (same) value. If the sequence is not reversible, the commands supplied at construction time will be spawned, if any.
doExecute
in class SequenceCommand<E>
saved
- True if the before state was successfully saved before
this method is invoked, false if not.
SequenceCommand.execute()
public boolean isUndoable()
reversible
,
false if not.
isUndoable
in interface Command<E>
isUndoable
in class SequenceCommand<E>
public E undo() throws CommandException
SequenceCommand
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.
undo
in interface Command<E>
undo
in class SequenceCommand<E>
CommandException
- In case this command is not undoable.
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |