PCJ API
Version 1.2

bak.pcj.set
Class ShortRange

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

public class ShortRange
extends Object
implements Comparable, Serializable

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

Constructor Detail

ShortRange

public ShortRange(short first,
                  short last)
Creates a new range of consecutive short values.

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

first

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

Returns:
the first short value in this range.

last

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

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

intersectionLength

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

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