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

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

java.lang.Object
  extended by dk.rode.thesis.command.LogCommand<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 LogCommand<E>
extends Object
implements Command<E>

A log command simply logs the operation performed on the receiver object.

A log command carries no state, and is considered undoable as to not interfere with regular commands.

Log commands are thread-safe and can be shared as they do not alter the receiver, only prints it to the log.

Author:
Gunni Rode / rode.dk

Field Summary
private  Object receiver
          The receiver object.
 
Constructor Summary
LogCommand(Object receiver)
          Constructor.
 
Method Summary
 LogCommand<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 this class and has the same receiver (compared using equals(Object).
 List<Command<E>> execute()
          Logs the string representation of the receiver object followed by ".execute()".
 E getResult()
          Returns the result of the execution of this command.
 int hashCode()
          Returns the hash code of this log command.
 boolean isUndoable()
          Returns true.
 String toString()
          Returns the string representation of this log command.
 E undo()
          Logs the string representation of the receiver object followed by ".undo()".
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

receiver

@Participant(value="Receiver")
private final Object receiver
The receiver object.

Never null.

Constructor Detail

LogCommand

public LogCommand(@Participant(value="Receiver")
                  Object receiver)
Constructor.

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

copy

public LogCommand<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 this class and has the same receiver (compared using equals(Object).

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()
Logs the string representation of the receiver object followed by ".execute()".

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 log 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 log command.

Overrides:
toString in class Object
Returns:
The string representation; never null.

undo

public E undo()
Logs the string representation of the receiver object followed by ".undo()".

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.