com.foxsmart.ic.net
Class IpAddress

java.lang.Object
  extended by com.foxsmart.ic.net.IpAddress
All Implemented Interfaces:
Host, java.io.Serializable

public class IpAddress
extends java.lang.Object
implements Host

The IpAddress class represents an individual network IP address. The IP Address has the form of A.B.C.D (e.g. 255.255.255.0) and contains 4 parts. Each part of the IP Address is a digit that ranges from 0-255.

See Also:
Serialized Form

Constructor Summary
IpAddress(java.net.InetAddress inetAddress)
          Constructs an IP Address based on an InetAddress format.
IpAddress(int a, int b, int c, int d)
          Constructs an IP Address based on the individual pieces.
IpAddress(java.lang.String ipAddress)
          Constructs an IP Address object based on a string representation of one.
 
Method Summary
 boolean equals(java.lang.Object ipAddressObject)
          Determines if 2 IP Address objects are equal.
 int getA()
          Gets the "A" portion of the IP Address.
 int getB()
          Gets the "B" portion of the IP Address.
 int getC()
          Gets the "C" portion of the IP Address.
 int getD()
          Gets the "D" portion of the IP Address.
static IpAddress getLocalHostAddress()
          Returns the IP Address of the localhost.
static void main(java.lang.String[] args)
          Test driver.
 java.lang.String toString()
          Returns the string representation of the IP Address.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IpAddress

public IpAddress(int a,
                 int b,
                 int c,
                 int d)
          throws java.lang.IllegalArgumentException
Constructs an IP Address based on the individual pieces. Each piece must contain a number between 0 and 255.

Parameters:
a - The A part of the IP Address
b - The B part of the IP Address
c - The C part of the IP Address
d - The D part of the IP Address
Throws:
java.lang.IllegalArgumentException - if the piece is out of range.

IpAddress

public IpAddress(java.lang.String ipAddress)
          throws java.lang.IllegalArgumentException
Constructs an IP Address object based on a string representation of one. (i.e. A.B.C.D).

Parameters:
ipAddress - The IP Address in the form of A.B.C.D as a string.
Throws:
java.lang.IllegalArgumentException - if the format is invalid.

IpAddress

public IpAddress(java.net.InetAddress inetAddress)
Constructs an IP Address based on an InetAddress format.

Parameters:
inetAddress - The IP Address
Throws:
java.lang.IllegalArgumentException - if the format is invalid.
Method Detail

toString

public java.lang.String toString()
Returns the string representation of the IP Address.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object ipAddressObject)
Determines if 2 IP Address objects are equal.

Overrides:
equals in class java.lang.Object
Parameters:
ipAddressObject - The IP Address to compare.
Returns:
True if the 2 IP Addresses are equal or false if not.

getA

public int getA()
Gets the "A" portion of the IP Address.

Returns:
the "A" portion.

getB

public int getB()
Gets the "B" portion of the IP Address.

Returns:
the "B" portion.

getC

public int getC()
Gets the "C" portion of the IP Address.

Returns:
the "C" portion.

getD

public int getD()
Gets the "D" portion of the IP Address.

Returns:
the "D" portion.

getLocalHostAddress

public static IpAddress getLocalHostAddress()
                                     throws java.net.UnknownHostException
Returns the IP Address of the localhost.

Returns:
The IP Address of the localhost.
Throws:
java.net.UnknownHostException - if the IP Address of the localhost could not be determined.

main

public static void main(java.lang.String[] args)
Test driver.

Parameters:
args - The arguments.


Copyright © 2005-2008 Fox Smart, Inc. All Rights Reserved.