org.rhq.enterprise.communications.command
Class CommandType

java.lang.Object
  extended by org.rhq.enterprise.communications.command.CommandType
All Implemented Interfaces:
Serializable, Comparable

public class CommandType
extends Object
implements Serializable, Comparable

Encapsulates the identification of a command type. This class is immutable.

Author:
John Mazzitelli
See Also:
Serialized Form

Constructor Summary
CommandType(CommandType original)
          Copy constructor for CommandType.
CommandType(String nameVersion)
          Constructor for CommandType given a string string that encodes both the command type name and version.
CommandType(String name, int version)
          Constructor for CommandType.
 
Method Summary
 int compareTo(Object obj)
          Used strictly to determine if one command type has a higher or lower version number than another with the same command type name.
 boolean equals(Object obj)
          CommandType objects are equal if they have the same name and same version.
 String getName()
          Returns the name of this command type.
 int getVersion()
          Returns the version number associated with this command type.
 int hashCode()
           
 String toString()
          This will return the name of the command following by the version (prefixed with a 'v') unless the version number is 1, in which case just the name is returned.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CommandType

public CommandType(String name,
                   int version)
            throws IllegalArgumentException
Constructor for CommandType.

Parameters:
name - the name of the command type
version - the version of the command type
Throws:
IllegalArgumentException - if name is null or empty

CommandType

public CommandType(CommandType original)
Copy constructor for CommandType.

Parameters:
original - the original object to copy

CommandType

public CommandType(String nameVersion)
            throws IllegalArgumentException
Constructor for CommandType given a string string that encodes both the command type name and version. The string must separate the name and version with a space. The version may simply be a number or (as with the format returned by toString()) may be prefixed with 'v'. Examples: "cmd 5", "cmd v5". If just the name was specified with no version, the version will default to 1.

Parameters:
nameVersion - command type name and version separated with a space
Throws:
IllegalArgumentException - if name is null or nameVersion was invalid
Method Detail

getName

public String getName()
Returns the name of this command type.

Returns:
name command type name

getVersion

public int getVersion()
Returns the version number associated with this command type.

Returns:
version version number

toString

public String toString()
This will return the name of the command following by the version (prefixed with a 'v') unless the version number is 1, in which case just the name is returned. For example, "mycommand v2" or "mycommand".

Overrides:
toString in class Object
See Also:
Object.toString()

equals

public boolean equals(Object obj)
CommandType objects are equal if they have the same name and same version.

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

compareTo

public int compareTo(Object obj)
              throws IllegalArgumentException
Used strictly to determine if one command type has a higher or lower version number than another with the same command type name. If the given object's command type name does not equal this object's command type name, an IllegalArgumentException is thrown - you cannot compare two command types with different names.

Specified by:
compareTo in interface Comparable
Throws:
IllegalArgumentException
See Also:
Comparable.compareTo(java.lang.Object)


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.