verinec.netsim.addresses
Class IPAddress

java.lang.Object
  extended by verinec.netsim.addresses.IPAddress
All Implemented Interfaces:
Comparable, IAddress
Direct Known Subclasses:
IPAddressNetmask

public class IPAddress
extends Object
implements IAddress

This class is an IPAddress that uses internally a four byte representation. e.g. 192.168.0.1

Version:
$Revision:835 $
Author:
Dominik Jungo

Field Summary
private  byte[] address
           
 
Constructor Summary
IPAddress()
          Constructs a new IPAddress with the value 0.0.0.0
IPAddress(byte i0, byte i1, byte i2, byte i3)
          Constructs a new IPAddress with the value i0.i1.i2.i3
IPAddress(Inet4Address address)
          Constructs a new IPAddress from a java Inet4Address
IPAddress(String address)
          Constructs a new IPAddress form a String.
 
Method Summary
 int compareTo(IPAddress address, int part)
          compares a part of an ip address.
 int compareTo(Object arg0)
           
 int compareToDigitByDigit(IPAddress arg0)
           
private  int compareToPart(IPAddress address, int part)
          Starts comparing recursively this Address with address from the part'th byte on.
 boolean equals(IAddress address)
          Tests if an address is equal to this address.
private  char getAddressClass()
          gets the subnet class of the address (a, b, c, d or e)
 byte getPart(int i)
          gets the i'th byte of this Address.
 IPAddress getsubnetMask()
          gets the default subnet mask for this address.
protected  void setPart(int i, byte a)
          Sets the i'th byte of the Address to the value a.
 byte[] toByteArray()
          returns the array of the 4 bytes of this address
 InetAddress toInetAddress()
          returns a InetAddress coressponding this Address
 String toString()
          get the IPAddress in the dotted string representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

address

private byte[] address
Constructor Detail

IPAddress

public IPAddress()
Constructs a new IPAddress with the value 0.0.0.0


IPAddress

public IPAddress(byte i0,
                 byte i1,
                 byte i2,
                 byte i3)
Constructs a new IPAddress with the value i0.i1.i2.i3

Parameters:
i0 - first byte of the Address
i1 - second byte of the Address
i2 - third byte of the Address
i3 - fourth byte of the Address

IPAddress

public IPAddress(Inet4Address address)
Constructs a new IPAddress from a java Inet4Address

Parameters:
address - a java Inet4Address

IPAddress

public IPAddress(String address)
Constructs a new IPAddress form a String.

Parameters:
address - in String representation with "."s between the four bytes. e.g "127.0.0.1"
Method Detail

compareTo

public int compareTo(IPAddress address,
                     int part)
compares a part of an ip address. a part means one of the four byte of the ip address

Parameters:
address - an address to compare
part - part to be compared
Returns:
a negative value if address is bigger than this address, 0 if they are equal and a positive value if this address is bigger.

compareTo

public int compareTo(Object arg0)
Specified by:
compareTo in interface Comparable
See Also:
Comparable.compareTo(java.lang.Object)

compareToDigitByDigit

public int compareToDigitByDigit(IPAddress arg0)

compareToPart

private int compareToPart(IPAddress address,
                          int part)
Starts comparing recursively this Address with address from the part'th byte on. Comparing is byte-wise.

Parameters:
address - an address to compare
part - starts comparing at this part value
Returns:
0 if the adresses are equal, -1 if this address is smaller and 1 if this address is bigger.

equals

public boolean equals(IAddress address)
Description copied from interface: IAddress
Tests if an address is equal to this address. Equal in this case does not mean the same address object but both represent the same address.

Specified by:
equals in interface IAddress
Parameters:
address - an address to compare with this Address
Returns:
true if both adresses have an equal String represenation, false otherwise.
See Also:
IAddress.equals(verinec.netsim.addresses.IAddress)

getAddressClass

private char getAddressClass()
gets the subnet class of the address (a, b, c, d or e)

Returns:
the subnet class of the address

getPart

public byte getPart(int i)
gets the i'th byte of this Address. i must be between 0 and 3.

Parameters:
i - the byte that should be returned
Returns:
the i'th byte of the Address

getsubnetMask

public IPAddress getsubnetMask()
gets the default subnet mask for this address. thee default subnet mask is one of the following:

Returns:
the default subnet mask for this address

setPart

protected void setPart(int i,
                       byte a)
Sets the i'th byte of the Address to the value a. i must be between 0 and 3.

Parameters:
i - the byte that sould be changed
a - the i'th byte value

toString

public String toString()
get the IPAddress in the dotted string representation. e.g. 192.168.0.1

Specified by:
toString in interface IAddress
Overrides:
toString in class Object
Returns:
this Address.
See Also:
IAddress.toString()

toInetAddress

public InetAddress toInetAddress()
                          throws UnknownHostException
returns a InetAddress coressponding this Address

Returns:
a InetAddress coressponding this Address
Throws:
UnknownHostException - if the InetAddress can't be build

toByteArray

public byte[] toByteArray()
returns the array of the 4 bytes of this address

Returns:
the array of the 4 bytes of this address

Copyright © 2005 Verinec, DIUF