org.jagatoo.commands
Class CommandBase

java.lang.Object
  extended by org.jagatoo.commands.CommandBase
All Implemented Interfaces:
Command
Direct Known Subclasses:
NoParamCommandBase

public abstract class CommandBase
extends java.lang.Object
implements Command

This abstract base class for the Command interface correctly overrides the hashCode() and equals(Object) methods.


Field Summary
protected  java.lang.Object[] paramsArray
           
 
Constructor Summary
CommandBase(java.lang.String key, int numParams)
           
CommandBase(java.lang.String key, java.lang.String text, int numParams)
           
 
Method Summary
 java.lang.Object[] createParametersArray(java.util.ArrayList<java.lang.String> parameters)
          Creates a parameters array for the given command line.
 boolean equals(java.lang.Object o)
          
 java.lang.String execute(java.lang.Boolean inputInfo, CommandLine commandLine)
          Executes this command.
 java.lang.String execute(CommandLine commandLine)
          Executes this command.
 java.lang.String execute(java.lang.Object[] parameters)
          Executes this command.
 java.lang.String getKey()
          
 java.lang.String getLocalizedText()
          
 int getNumParameters()
          
 java.lang.String getText()
          
 int hashCode()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jagatoo.commands.Command
execute, getParameterTypes
 

Field Detail

paramsArray

protected final java.lang.Object[] paramsArray
Constructor Detail

CommandBase

public CommandBase(java.lang.String key,
                   java.lang.String text,
                   int numParams)

CommandBase

public CommandBase(java.lang.String key,
                   int numParams)
Method Detail

getKey

public final java.lang.String getKey()

Specified by:
getKey in interface Command
Returns:
this command's key (like "bind" or "jump").

getText

public final java.lang.String getText()

Specified by:
getText in interface Command
Returns:
a descriptive text for this Command.
See Also:
Command.getLocalizedText()

getLocalizedText

public java.lang.String getLocalizedText()

Specified by:
getLocalizedText in interface Command
Returns:
a localozed descriptive text for this Command. You should prefer this method over Command.getText().

getNumParameters

public final int getNumParameters()

Specified by:
getNumParameters in interface Command
Returns:
the number of expected parameters.

createParametersArray

public java.lang.Object[] createParametersArray(java.util.ArrayList<java.lang.String> parameters)
Description copied from interface: Command
Creates a parameters array for the given command line.

Specified by:
createParametersArray in interface Command

execute

public final java.lang.String execute(java.lang.Object[] parameters)
                               throws CommandException
Executes this command.
If a CommandException is thrown, then only its info text is displayed.

Specified by:
execute in interface Command
Parameters:
parameters - the command's parameters
Returns:
this command's result if successful. Used to give the user a textual response to the command execution. May be null for simple commands.
Throws:
CommandException

execute

public java.lang.String execute(java.lang.Boolean inputInfo,
                                CommandLine commandLine)
                         throws CommandException
Executes this command.
If a CommandException is thrown, then only its info text is displayed.

Specified by:
execute in interface Command
Parameters:
inputInfo - this Boolean is true for a key-down or wheel-up and false for a key-up or wheel-down. The Command implementation must be aware of the fact, that this Boolean can be null.
commandLine - the CommandLine to extract the parameters array from
Returns:
this command's result if successful. Used to give the user a textual response to the command execution. May be null for simple commands.
Throws:
CommandException

execute

public java.lang.String execute(CommandLine commandLine)
                         throws CommandException
Executes this command.
If a CommandException is thrown, then only its info text is displayed.

Specified by:
execute in interface Command
Parameters:
commandLine - the CommandLine to extract the parameters array from
Returns:
this command's result if successful. Used to give the user a textual response to the command execution. May be null for simple commands.
Throws:
CommandException

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)

Overrides:
equals in class java.lang.Object