com.artima.place
Class ServerAddress

java.lang.Object
  |
  +--com.artima.place.ServerAddress
All Implemented Interfaces:
java.io.Serializable

public final class ServerAddress
extends java.lang.Object
implements java.io.Serializable

Holds a String host name and int port number. The host name must be in either quad or domain name form.

ServerAddress is not clonable because its immutable.

See Also:
Serialized Form

Constructor Summary
ServerAddress(java.lang.String host, int port)
          Constructs a ServerAddress with passed String host name and int port number.
 
Method Summary
 boolean equals(java.lang.Object o)
          Compares the specified Object with this ServerAddress for equality.
 java.lang.String getHost()
          Returns the String host name that's stored in this ServerAddress.
 int getPort()
          Returns the int port number that's stored in this ServerAddress.
 int hashCode()
          Returns the hash code value for this ServerAddress.
static boolean isValidHost(java.lang.String host)
          Returns true if passed String is a valid host name.
static boolean isValidPort(int port)
          Returns true if passed int is a valid port number.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerAddress

public ServerAddress(java.lang.String host,
                     int port)
Constructs a ServerAddress with passed String host name and int port number. The server host name should be in quad or domain name form, acceptable to the isValidHost method of this class.
Parameters:
host - a server host name in quad or domain name form
port - a server port number
Throws:
NullPointerException - if the host reference passed to this constructor is null
java.lang.IllegalArgumentException - if the port passed to this constructor is less than zero or greater than 65,535, or if the host is not a well-formed host name in quad or domain name form
Method Detail

getHost

public java.lang.String getHost()
Returns the String host name that's stored in this ServerAddress.
Returns:
the String host name held in this ServerAddress

getPort

public int getPort()
Returns the int port number that's stored in this ServerAddress.
Returns:
the port number held in this ServerAddress

equals

public boolean equals(java.lang.Object o)
Compares the specified Object with this ServerAddress for equality. Two ServerAddresss are semantically equal if their host names are semantically equal and their ports are equal.
Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare to this one.
Returns:
true if this object is semantically equal to the passed object.

hashCode

public int hashCode()
Returns the hash code value for this ServerAddress.
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code for this object.

isValidPort

public static boolean isValidPort(int port)
Returns true if passed int is a valid port number. To be valid, the passed int must be greater than or equal to zero and less than or equal to 65535.
Parameters:
port - a server port number
Returns:
true if the port number is valid

isValidHost

public static boolean isValidHost(java.lang.String host)
Returns true if passed String is a valid host name. To be valid, the passed int must be either a valid IP address in quad form or a well-formed domain name. This method does not verify that any particular IP address or domain name exists or is reachable, just that the String is well-formed.
Parameters:
host - a server host name in quad or domain name form
Returns:
true if the host name is valid