PCJ API
Version 1.2

bak.pcj.set
Class ByteRange

java.lang.Object
  extended bybak.pcj.set.ByteRange
All Implemented Interfaces:
Comparable, Serializable

public class ByteRange
extends Object
implements Comparable, Serializable

This class represents ranges of consecutive byte values.

Design note: Empty ranges cannot exist. It gives too many problems defining adjacency and intersections, and empty ranges are not really useful for their purpose of backing up range sets. It also removes the problem of overflow checking.

Since:
1.0
See Also:
Serialized Form

Constructor Summary
ByteRange(byte first, byte last)
          Creates a new range of consecutive byte values.
 
Method Summary
 boolean adjacentTo(ByteRange range)
          Indicates whether this range is adjacent to a specified range.
 boolean canMergeWith(ByteRange range)
          Indicates whether this can be merged with a specified range.
 int compareTo(Object obj)
          Compares this range with some object for order.
 boolean contains(byte v)
          Indicates whether a specified value is a member of this range.
 boolean equals(Object obj)
          Indicates whether this range is equal to some object.
 byte first()
          Returns the first byte value in this range.
 int hashCode()
          Returns a hash code value for this range.
 int intersectionLength(ByteRange range)
          Returns the length of the intersection between this range and a specified range.
 boolean intersects(ByteRange range)
          Indicates whether this range intersects a specified range.
 byte last()
          Returns the last byte value in this range.
 int length()
          Returns the number of values in this range.
 ByteRange mergeWith(ByteRange range)
          Creates a new range as a merge between this range and a specified range.
 String toString()
          Returns a string representation of this range.
 ByteRange tryMergeWith(ByteRange range)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteRange

public ByteRange(byte first,
                 byte last)
Creates a new range of consecutive byte values.

Parameters:
first - the first byte value in the range.
last - the last byte value in the range.
Throws:
IllegalArgumentException - if first > last.
Method Detail

first

public byte first()
Returns the first byte value in this range.

Returns:
the first byte value in this range.

last

public byte last()
Returns the last byte value in this range.

Returns:
the last byte value in this range.

length

public int length()
Returns the number of values in this range.

Returns:
the number of values in this range.

intersects

public boolean intersects(ByteRange range)
Indicates whether this range intersects a specified range.

Parameters:
range - the range with which to compare this range.
Returns:
true if this range has at least one value in common with the specified range.
Throws:
NullPointerException - if range is null.

adjacentTo

public boolean adjacentTo(ByteRange range)
Indicates whether this range is adjacent to a specified range.

Parameters:
range - the range with which to compare this range.
Returns:
true if this range is adjacent to the specified range.
Throws:
NullPointerException - if range is null.

canMergeWith

public boolean canMergeWith(ByteRange range)
Indicates whether this can be merged with a specified range. Two ranges can be merged if a range of consecutive values containing all values of both ranges exists.

Parameters:
range - the range to merge with.
Returns:
true if this range can be merged with the specified range; returns false otherwise.
Throws:
NullPointerException - if range is null.

mergeWith

public ByteRange mergeWith(ByteRange range)
Creates a new range as a merge between this range and a specified range.

Parameters:
range - the range with which to merge this range.
Throws:
NullPointerException - if range is null.
IllegalArgumentException - if this range cannot be merged with the specified range.

tryMergeWith

public ByteRange tryMergeWith(ByteRange range)

intersectionLength

public int intersectionLength(ByteRange range)
Returns the length of the intersection between this range and a specified range.

Parameters:
range - the range with which to intersect this rance.
Returns:
the length of the intersection between this range and a specified range.
Throws:
NullPointerException - if range is null.

contains

public boolean contains(byte v)
Indicates whether a specified value is a member of this range.

Parameters:
v - the value to test for membership.
Returns:
true if the specified value is a member of this range; returns false otherwise.

equals

public boolean equals(Object obj)
Indicates whether this range is equal to some object.

Parameters:
obj - the object with which to compare this range.
Returns:
true if this range is equal to the specified object; returns false otherwise.

compareTo

public int compareTo(Object obj)
Compares this range with some object for order.

Specified by:
compareTo in interface Comparable
Parameters:
obj - the object with which to compare this range.
Returns:
-1 if this range is less than obj; returns 1 if this range is greater than obj; returns 0 otherwise, in which case this.equals(obj) is true.
Throws:
NullPointerException - if obj is null.
ClassCastException - if obj is not of class ByteRange.

hashCode

public int hashCode()
Returns a hash code value for this range.

Returns:
a hash code value for this range.

toString

public String toString()
Returns a string representation of this range.

Returns:
a string representation of this range.

PCJ API
Version 1.2

Report a bug or request a feature.
Further information on the development and latest release of PCJ can be found at the project homepage.

Primitive Collections for Java is released under the GNU Lesser General Public License.
Copyright © 2002, 2003 Søren Bak. All Rights Reserved.

Hosted by SourceForge.net
SourceForge.net Logo