PCJ API
Version 1.2

bak.pcj.set
Class IntRange

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

public class IntRange
extends Object
implements Comparable, Serializable

This class represents ranges of consecutive int 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
IntRange(int first, int last)
          Creates a new range of consecutive int values.
 
Method Summary
 boolean adjacentTo(IntRange range)
          Indicates whether this range is adjacent to a specified range.
 boolean canMergeWith(IntRange 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(int 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.
 int first()
          Returns the first int value in this range.
 int hashCode()
          Returns a hash code value for this range.
 int intersectionLength(IntRange range)
          Returns the length of the intersection between this range and a specified range.
 boolean intersects(IntRange range)
          Indicates whether this range intersects a specified range.
 int last()
          Returns the last int value in this range.
 int length()
          Returns the number of values in this range.
 IntRange mergeWith(IntRange range)
          Creates a new range as a merge between this range and a specified range.
 String toString()
          Returns a string representation of this range.
 IntRange tryMergeWith(IntRange range)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntRange

public IntRange(int first,
                int last)
Creates a new range of consecutive int values.

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

first

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

Returns:
the first int value in this range.

last

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

Returns:
the last int 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(IntRange 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(IntRange 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(IntRange 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 IntRange mergeWith(IntRange 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 IntRange tryMergeWith(IntRange range)

intersectionLength

public int intersectionLength(IntRange 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(int 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 IntRange.

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