com.voytechs.jnetstream.primitive.address
Class IpNetwork

java.lang.Object
  extended by com.voytechs.jnetstream.primitive.address.Address
      extended by com.voytechs.jnetstream.primitive.address.IpNetwork
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class IpNetwork
extends Address
implements java.lang.Comparable

This class manipulates a IP address as a network address it requires 2 values, address and netmask. Netmask is applied to the various operations that this class supports such as comparisons and sorting.

Version:
$Revision: 1.4 $
Author:
Mark Bednarczyk
See Also:
Serialized Form

Field Summary
static boolean debug1
           
 
Fields inherited from class com.voytechs.jnetstream.primitive.address.Address
address, debug, DEFAULT_NUMBER_BASE, format, separator
 
Constructor Summary
IpNetwork(Address ip, int bitsInMask)
           
IpNetwork(Address ip, IpNetmask mask)
           
IpNetwork(byte[] byteAddress, IpNetmask mask)
           
IpNetwork(java.lang.String network, int bitsInMask)
          This form initializes the network number by creating a netmask from the number of bits within the mask.
IpNetwork(java.lang.String network, IpNetmask mask)
           
 
Method Summary
 int compareTo(byte[] comp)
           
 int compareTo(java.lang.Object o)
           
 boolean equals(java.lang.Object o)
          Compare our byte values for IP address to the object's.
 Address getLowerBounds()
          A getter method which returns lower network boundary based on the netmasked network address.
 IpNetmask getNetmask()
           
 Address getNetmasked()
          Returns an Address with the netmask applied to it.
 Address getUpperBounds()
          A getter moethd which returns the upper network boundary based on the netmasked networked address.
 boolean isPartOf(java.lang.Object o)
           
static void main(java.lang.String[] args)
          Test function for IpNetwork
static IpNetwork parseIpNetwork(java.lang.String networkString)
          Parse the string representing a network entry.
 byte[] toByteArray()
          Overrides the default byteArrayValue method and applies the network netmask to the IP number.
 java.lang.String toString()
          Convert to dot notation string representation of the address
 
Methods inherited from class com.voytechs.jnetstream.primitive.address.Address
AND, AND, byteArrayValue, compare, compare, EOR, EOR, getByte, getByte, getRadix, INVERT, INVERT, longToByteArray, OR, OR, parseByteArray, setAddress, setByteArrayAddress, setFormat, setFormat, setRadix, setSeparator, stringValue, toString, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

debug1

public static final boolean debug1
See Also:
Constant Field Values
Constructor Detail

IpNetwork

public IpNetwork(java.lang.String network,
                 int bitsInMask)
This form initializes the network number by creating a netmask from the number of bits within the mask. Mask value will be created. (ie. 24 = 255.255.255.0)

Parameters:
network - The network number IP address
bitsInMask -

IpNetwork

public IpNetwork(java.lang.String network,
                 IpNetmask mask)

IpNetwork

public IpNetwork(byte[] byteAddress,
                 IpNetmask mask)

IpNetwork

public IpNetwork(Address ip,
                 int bitsInMask)

IpNetwork

public IpNetwork(Address ip,
                 IpNetmask mask)
Method Detail

getNetmask

public IpNetmask getNetmask()

getLowerBounds

public Address getLowerBounds()
A getter method which returns lower network boundary based on the netmasked network address.


getUpperBounds

public Address getUpperBounds()
A getter moethd which returns the upper network boundary based on the netmasked networked address.


toByteArray

public byte[] toByteArray()
Overrides the default byteArrayValue method and applies the network netmask to the IP number.

Overrides:
toByteArray in class Address
Returns:
IP number with applied netmask.

getNetmasked

public Address getNetmasked()
Returns an Address with the netmask applied to it. If the base network number was set to anything other than the correct number for the netmask, the base number is trunkated based on the netmask with the following calculation: base & netmask

Returns:
Trunkated base network number.

equals

public boolean equals(java.lang.Object o)
Description copied from class: Address
Compare our byte values for IP address to the object's. If length do not match then the objects are considered unequal. If byte counts are the same then a byte for byte comparison is made and appropriate result return.

Overrides:
equals in class Address
Parameters:
o - Address object to campare to.
Returns:
true means both objects are equal. This means both Addresss have the same number of bytes and each of those bytes is equal (==).

isPartOf

public boolean isPartOf(java.lang.Object o)

parseIpNetwork

public static IpNetwork parseIpNetwork(java.lang.String networkString)
Parse the string representing a network entry. Network entries have a network number and a mask separator by '/' character.

Parameters:
networkString - String network in form 'n1.n2.n3.n4/m1.m2.m3.m4'

toString

public java.lang.String toString()
Description copied from class: Address
Convert to dot notation string representation of the address

Overrides:
toString in class Address
Returns:
IP address in the dot notation.

compareTo

public int compareTo(byte[] comp)

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class Address

main

public static void main(java.lang.String[] args)
Test function for IpNetwork

Parameters:
args - command line arguments