|
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.EvilCommand<E>
E
- The type of mimicked result obtained by executing
this command. This command type always return null
as the result.@Participant(value="ConcreteCommand") public class EvilCommand<E>
An evil command is a test command that will
always fail during execution
and perhaps
on undo
as well by specifying that it is
undoable
while in reality it is not.
The same instance of a EvilCommand.EvilCommandException
is always thrown
to be easily identifiable in testing scenarios.
It still utilises a type parameter, E
, so it can mimic
commands delivering a certain type of value.
Evil commands are thread-safe and can be shared.
Nested Class Summary | |
---|---|
static class |
EvilCommand.EvilCommandException
The exception type thrown during execution and perhaps on undo of the
an evil command. |
Field Summary | |
---|---|
static EvilCommand.EvilCommandException |
ERROR
This command exception instance always thrown during the execution add perhaps during
undo as well. |
private boolean |
failOnUndo
True if this command will fail on undo, false if it only fails on execution. |
Constructor Summary | |
---|---|
EvilCommand()
Constructor. |
|
EvilCommand(boolean failOnUndo)
Constructor. |
Method Summary | |
---|---|
EvilCommand<E> |
copy()
Creates a copy of this command, excluding internal state information required for execution and undo. |
boolean |
equals(Object object)
Returns true if object is an evil command
set to fail in the same way as this command, otherwise
fails. |
List<Command<E>> |
execute()
Always throws ERROR . |
E |
getResult()
Returns the result of the execution of this
command. |
int |
hashCode()
Returns the hash code of this evil command. |
boolean |
isUndoable()
Returns true. |
String |
toString()
Returns the string representation of this evil command. |
E |
undo()
If this command is set to fail on undo, ERROR
is thrown. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final EvilCommand.EvilCommandException ERROR
execution
add perhaps during
undo
as well. Never null.
private final boolean failOnUndo
Constructor Detail |
---|
public EvilCommand()
This evil command will not fail on undo.
public EvilCommand(boolean failOnUndo)
failOnUndo
- True to fail on undo, false to only fail
during execution.Method Detail |
---|
public EvilCommand<E> copy()
Command
copy
in interface Command<E>
copy
in interface Copyable<Command<E>>
public boolean equals(Object object)
object
is an evil command
set to fail in the same way as this command, otherwise
fails.
equals
in class Object
object
- The object to test; can be null.
public List<Command<E>> execute() throws EvilCommand.EvilCommandException
ERROR
.
execute
in interface Command<E>
EvilCommand.EvilCommandException
- Always thrown.Command.undo()
public E getResult()
Command
execution
of this
command.
Invoking this method before execution will cause an illegal
state exception to be thrown. If undone
,
this command must be re-executed before the result can be
fetched again.
getResult
in interface Command<E>
public int hashCode()
hashCode
in class Object
public boolean isUndoable()
isUndoable
in interface Command<E>
public String toString()
toString
in class Object
public E undo() throws EvilCommand.EvilCommandException
ERROR
is thrown. Otherwise null is returned.
undo
in interface Command<E>
EvilCommand.EvilCommandException
- If this command is set to fail on
undo.
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |