com.sun.multicast.allocation
Class AddressRange

java.lang.Object
  |
  +--com.sun.multicast.allocation.AddressRange

public class AddressRange
extends java.lang.Object

A range of network addresses.

Objects of this class and all values returned by their methods are immutable. That is, their values cannot change after they are constructed.


Constructor Summary
AddressRange(Address firstAddress, Address lastAddress)
          Creates an AddressRange with the specified addresses.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this AddressRange with the specified object for order.
 boolean contains(Address address)
          Checks whether this AddressRange contains a given Address.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
 long getAddressCount()
          Gets the number of addresses in this AddressRange.
 AddressType getAddressType()
          Gets the type of addresses in this AddressRange.
 Address getFirstAddress()
          Gets the first address in this AddressRange.
 Address getLastAddress()
          Gets the last address in this AddressRange.
 int hashCode()
          Returns a hash code value for the AddressRange.
 AddressRange merge(AddressRange otherRange)
          Returns an AddressRange represents the merger of this AddressRange with otherRange.
 boolean overlaps(AddressRange otherRange)
          Checks whether this AddressRange overlaps with another.
 java.lang.String toString()
          Returns a string representation of this AddressRange.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AddressRange

public AddressRange(Address firstAddress,
                    Address lastAddress)
Creates an AddressRange with the specified addresses.
Parameters:
startAddress - the first address in the range
endAddress - the last address in the range
Method Detail

getFirstAddress

public Address getFirstAddress()
Gets the first address in this AddressRange.
Returns:
the first address in this AddressRange

getLastAddress

public Address getLastAddress()
Gets the last address in this AddressRange.
Returns:
the last address in this AddressRange

getAddressCount

public long getAddressCount()
Gets the number of addresses in this AddressRange.
Returns:
the number of addresses in this AddressRange

getAddressType

public AddressType getAddressType()
Gets the type of addresses in this AddressRange.
Returns:
the type of addresses in this AddressRange

compareTo

public int compareTo(java.lang.Object o)
              throws java.lang.ClassCastException
Compares this AddressRange with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

AddressRanges are ordered first on the basis of first address and then on the basis of last address. That is, the first addresses in the ranges are compared. If they are not equal, this is the result of the range comparison. If they are equal, the last address ranges are compared and this is the result of the comparison. If the two AddressRanges cannot be compared (usually because they are of different AddressTypes), a ClassCastException is thrown.

This method imposes a total ordering on addresses of the same AddressRange.

Parameters:
o - the Object to compare against
Returns:
an integer reflecting the outcome of the comparison
Throws:
java.lang.ClassCastException - if the objects cannot be compared

overlaps

public boolean overlaps(AddressRange otherRange)
                 throws java.lang.ClassCastException
Checks whether this AddressRange overlaps with another.

If the two AddressRanges are of different AddressTypes, a ClassCastException is thrown.

Parameters:
otherRange - the AddressRange to check for overlap with
Returns:
true if this AddressRange overlaps with otherRange, false otherwise.

contains

public boolean contains(Address address)
                 throws java.lang.ClassCastException
Checks whether this AddressRange contains a given Address.

If the Address is not of the same AddressType as this AddressRange, a ClassCastException is thrown.

Parameters:
address - the Address to check for
Returns:
true if this AddressRange contains the Address, false otherwise.

merge

public AddressRange merge(AddressRange otherRange)
                   throws java.lang.ClassCastException
Returns an AddressRange represents the merger of this AddressRange with otherRange. If the two ranges do not overlap, the result will also include addresses that were not in either of the ranges. This method does not affect the values of either this AddressRange or otherRange.

If the two AddressRanges are of different AddressTypes, a ClassCastException is thrown.

Parameters:
otherRange - the AddressRange to merge with
Returns:
an AddressRange that represents the merger of this AddressRange with otherRange

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. Two AddressRanges are equal if and only if they have the same first and last addresses.
Overrides:
equals in class java.lang.Object
Parameters:
obj - the object with which to compare
Returns:
true if this object is the same as the reference object, false otherwise.

hashCode

public int hashCode()
Returns a hash code value for the AddressRange. The hash code values for two AddressRanges are equal if they are equal. However, it may be possible for two unequal AddressRanges to have the same hash code.
Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this AddressRange

toString

public java.lang.String toString()
Returns a string representation of this AddressRange.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this AddressRange


JavaTM Reliable MulticastTM Service version 1.1
Copyright (c) 2001, Sun Microsystems Laboratories, All rights reserved.