net.kano.joscar.snac
Class CmdType

java.lang.Object
  extended byCmdType

public final class CmdType
extends java.lang.Object

Represents a single SNAC command type, or a group of all SNAC command types in a single family, or all SNAC commands. In practice, provides a means of listening for a specific set of commands on a SNAC connection.


Field Summary
static int ALL
          A family type or command type that indicates all families or all command types within a family, depending on whether it is used as a family type or command type, respectively.
static CmdType CMDTYPE_ALL
          A CmdType that represents all possible command types.
 
Constructor Summary
CmdType(int family)
          Creates a CmdType matching all commands in the given family.
CmdType(int family, int command)
          Creates a CmdType matching the given command in the given family.
 
Method Summary
 boolean equals(java.lang.Object o)
          Returns true if these two objects represent the same set of SNAC commands; false otherwise.
 int getCommand()
          Returns the SNAC command type ("subtype") of the command represented by this CmdType, or CmdType.ALL if this object represents every command in a given family.
 int getFamily()
          Returns the SNAC family of the command(s) represented by this CmdType, or CmdType.ALL if all commands in all families are represented.
 int hashCode()
          Returns a hash code relatively unique to this set of SNAC commands.
static CmdType ofCmd(SnacCommand command)
          Returns a CmdType that represents the command type of the given SNAC command object.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ALL

public static final int ALL
A family type or command type that indicates all families or all command types within a family, depending on whether it is used as a family type or command type, respectively.

See Also:
Constant Field Values

CMDTYPE_ALL

public static final CmdType CMDTYPE_ALL
A CmdType that represents all possible command types. Equivalent to a new CmdType instantiated using new CmdType(CmdType.ALL, CmdType.ALL). In fact, that's what it is.

Constructor Detail

CmdType

public CmdType(int family)
Creates a CmdType matching all commands in the given family. Using this constructor is the equivalent to using CmdType(family, CmdType.ALL). Note that family can be CmdType.ALL, but it is recommended to simply use CmdType.CMDTYPE_ALL instead of creating a new instance.

Parameters:
family - the SNAC family for this CmdType, or CmdType.ALL

CmdType

public CmdType(int family,
               int command)
        throws java.lang.IllegalArgumentException
Creates a CmdType matching the given command in the given family. command can be CmdType.ALL, in which case this object will match all commands in the given family. family can also be CmdType.ALL, if and only if command is CmdType.ALL as well, in which case this object will match all possible commands.

Parameters:
family - the family of the commands to represent, or CmdType.ALL
command - the command type ("subtype") of the command to represent, or CmdType.ALL
Throws:
java.lang.IllegalArgumentException - if family is CmdType.ALL and command is not, or if either family or command are not CmdType.ALL or positive numbers
Method Detail

ofCmd

public static CmdType ofCmd(SnacCommand command)
Returns a CmdType that represents the command type of the given SNAC command object.

Parameters:
command - a SNAC command
Returns:
a command type object representing the type of the given SNAC command

getFamily

public final int getFamily()
Returns the SNAC family of the command(s) represented by this CmdType, or CmdType.ALL if all commands in all families are represented.

Returns:
the SNAC family of the command(s) represented by this object, or CmdType.ALL

getCommand

public final int getCommand()
Returns the SNAC command type ("subtype") of the command represented by this CmdType, or CmdType.ALL if this object represents every command in a given family. Also, if getFamily() returns CmdType.ALL, this method will return CmdType.ALL as well, indicating that all commands in all families are represented.

Returns:
the SNAC command type of the command represented, or Cmd.ALL

equals

public boolean equals(java.lang.Object o)
Returns true if these two objects represent the same set of SNAC commands; false otherwise.

Parameters:
o - the other CmdType to compare to
Returns:
whether this and the given object represent the exact same set of SNAC commands

hashCode

public int hashCode()
Returns a hash code relatively unique to this set of SNAC commands.

Returns:
a hash code

toString

public java.lang.String toString()