org.opennms.bb.dp.discovery.components
Class IPAddressRange

java.lang.Object
  |
  +--org.opennms.bb.dp.discovery.components.IPAddressRange

public class IPAddressRange
extends Object

The IPAddressRange object is used to encapsulate the starting and ending points of a continguous IPv4 Address range. The class can then generate either an Enumeration or Iterator that can be used to cycle through the range of addresses by the object's user.

Version:
$Revision: 1.5 $
Author:
Sowmya, Brian Weaver, OpenNMS

Inner Class Summary
private  class IPAddressRange.IPAddressRangeGenerator
          This class is used to enumerate or iterate through one contiguous set of IP addresses.
 
Field Summary
private  long m_begin
          The starting address for the object.
private  long m_end
          The ending address for the object.
 
Constructor Summary
IPAddressRange(InetAddress start, InetAddress end)
          Creates a new IPAddressRange object that can be used to encapsulate a contiguous range of IP Addresses.
IPAddressRange(String fromIP, String toIP)
          Creates a new IPAddressRange object that can be used to encapsulate a contiguous range of IP Addresses.
 
Method Summary
private static long byteToLong(byte b)
          Converts an 8-bit byte to a 64-bit long integer.
private static long convertToLong(byte[] addr)
          The convertToLong method takes an array of bytes and shifts them into a long value.
 Enumeration elements()
          Returns an Enumeration object that can be used to list out all the address contained in the encapsulated range.
 Iterator iterator()
          Returns an Iterator object that can be used to step through all the address encapsulated in the object.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_begin

private long m_begin
The starting address for the object.

m_end

private long m_end
The ending address for the object.
Constructor Detail

IPAddressRange

public IPAddressRange(String fromIP,
                      String toIP)
               throws UnknownHostException

Creates a new IPAddressRange object that can be used to encapsulate a contiguous range of IP Addresses. Once created the object can be used to get either an Iterator or Enumeration object to cycle through the list of address encapsulated by this object.

It is important to note that if the address for toIP is greater than fromIP, the values will be swapped so that the iteration is always from the lowest address to the highest address as defined by a 32-bit unsigned quantity.

Parameters:
fromIP - The starting address, resolved by InetAddress.
toIP - The ending address, resolved by InetAddress.
Throws:
UnknownHostException - Thrown by the InetAddress class if the hostname cannot be resolved.
See Also:
InetAddress.getByName(java.lang.String)

IPAddressRange

public IPAddressRange(InetAddress start,
                      InetAddress end)

Creates a new IPAddressRange object that can be used to encapsulate a contiguous range of IP Addresses. Once created the object can be used to get either an Iterator or Enumeration object to cycle through the list of address encapsulated by this object.

It is important to note that if the address for start is greater than end, the values will be swapped so that the iteration is always from the lowest address to the highest address as defined by a 32-bit unsigned quantity.

Parameters:
start - The starting address.
end - The ending address.
Method Detail

byteToLong

private static long byteToLong(byte b)

Converts an 8-bit byte to a 64-bit long integer. If the quantity is a sign extended negative number then the value of 256 is added to wrap the conversion into the range of [0..255].

Parameters:
b - The byte to convert
Returns:
The converted 64-bit unsigned value.

convertToLong

private static long convertToLong(byte[] addr)

The convertToLong method takes an array of bytes and shifts them into a long value. The bytes at the front of the array are shifted into the MSB of the long as each new byte is added to the LSB of the long. if the array is of sufficent size the first bytes of the array may be shifted out of the returned long.

Parameters:
addr - The array to convert to a long.
Returns:
The created long value.
Throws:
IllegalArgumentException - Thrown if the addr parameter is null.

iterator

public Iterator iterator()

Returns an Iterator object that can be used to step through all the address encapsulated in the object.


elements

public Enumeration elements()

Returns an Enumeration object that can be used to list out all the address contained in the encapsulated range.