PCJ API
Version 1.2

bak.pcj.set
Class LongRange

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

public class LongRange
extends Object
implements Comparable, Serializable

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

Constructor Detail

LongRange

public LongRange(long first,
                 long last)
Creates a new range of consecutive long values.

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

first

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

Returns:
the first long value in this range.

last

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

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

intersectionLength

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

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