net.sourceforge.obby4j
Class Command

java.lang.Object
  extended by net.sourceforge.obby4j.Command

public class Command
extends java.lang.Object

A command of the obby protocol as sent between clients and servers.


Constructor Summary
Command(Protocol.Keyword keyword)
          Creates a parameterless command with the given keyword.
Command(Protocol.Keyword keyword, java.lang.String... params)
          Creates a command from a keyword and a number of parameters.
 
Method Summary
 void addParameter(java.lang.String param)
          Adds a parameters.
 int getIntParam(int idx)
          Returns the parameter at the given index as an int.
 Protocol.Keyword getKeyword()
           
 java.lang.String getParam(int idx)
          Returns the parameter at the given index.
 java.lang.String[] getParams()
          Returns all parameters of a command.
static Command parseCommand(java.lang.String line)
          Parses a single line received from a server into a Command instance.
 java.lang.String toString()
          Returns a String representation of a command exactly as it would be send over the network.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Command

public Command(Protocol.Keyword keyword)
Creates a parameterless command with the given keyword.

Parameters:
keyword - the keyword

Command

public Command(Protocol.Keyword keyword,
               java.lang.String... params)
Creates a command from a keyword and a number of parameters.

Parameters:
keyword - the keyword
params - the parameters
Method Detail

addParameter

public void addParameter(java.lang.String param)
Adds a parameters.

Parameters:
param -

getIntParam

public int getIntParam(int idx)
Returns the parameter at the given index as an int.

Parameters:
idx - the index of the parameter
Returns:
the parameter at the index as an int
Throws:
java.lang.NumberFormatException - if the parameter can't be parsed as an int

getKeyword

public Protocol.Keyword getKeyword()
Returns:
the keyword of this command

getParam

public java.lang.String getParam(int idx)
Returns the parameter at the given index.

Parameters:
idx - the index of the parameter
Returns:
the parameter at the index

getParams

public java.lang.String[] getParams()
Returns all parameters of a command.

Returns:
an array of all parameters

parseCommand

public static Command parseCommand(java.lang.String line)
Parses a single line received from a server into a Command instance.

Parameters:
line - a single line as received from a server
Returns:
a Command instance representing the line

toString

public java.lang.String toString()
Returns a String representation of a command exactly as it would be send over the network.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the command