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

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

java.lang.Object
  extended by dk.rode.thesis.command.NullCommand<E>
Type Parameters:
E - The type of result obtained by executing this command. This command type always return null as the result.
All Implemented Interfaces:
Command<E>, Copyable<Command<E>>, StrictCopyable<Command<E>>

@Participant(value="ConcreteCommand")
public class NullCommand<E>
extends Object
implements Command<E>

A null command performs no operation on execute or on undo, is always considered undoable, and carries no state.

Null commands are thread-safe and can be shared.

Author:
Gunni Rode / rode.dk

Constructor Summary
NullCommand()
          No-arg constructor.
 
Method Summary
 NullCommand<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 instance of a NullCommand.
 List<Command<E>> execute()
          Does nothing.
 E getResult()
          Returns the result of the execution of this command.
 int hashCode()
          Returns the hash code of this null command.
 boolean isUndoable()
          Returns true.
 String toString()
          Returns the string representation of this null command.
 E undo()
          Does nothing.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NullCommand

public NullCommand()
No-arg constructor.

Method Detail

copy

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

Specified by:
copy in interface Command<E>
Specified by:
copy in interface Copyable<Command<E>>
Returns:
A new instance of this command; never null.

equals

public boolean equals(Object object)
Returns true if object is an instance of a NullCommand.

Overrides:
equals in class Object
Parameters:
object - The object to test; can be null.
Returns:
True if equal, false if not.

execute

public List<Command<E>> execute()
Does nothing.

Specified by:
execute in interface Command<E>
Returns:
Always null.
See Also:
Command.undo()

getResult

public E getResult()
Description copied from interface: Command
Returns the result of the 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.

Specified by:
getResult in interface Command<E>
Returns:
Always null.

hashCode

public int hashCode()
Returns the hash code of this null command.

Overrides:
hashCode in class Object
Returns:
The hash code.

isUndoable

public boolean isUndoable()
Returns true.

Specified by:
isUndoable in interface Command<E>
Returns:
True.

toString

public String toString()
Returns the string representation of this null command.

Overrides:
toString in class Object
Returns:
The string representation; never null.
See Also:
ObjectPolicy.ID

undo

public E undo()
Does nothing.

Specified by:
undo in interface Command<E>
Returns:
Always null.

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.