PCJ API
Version 1.2

bak.pcj.set
Class CharRange

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

public class CharRange
extends Object
implements Comparable, Serializable

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

Constructor Detail

CharRange

public CharRange(char first,
                 char last)
Creates a new range of consecutive char values.

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

first

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

Returns:
the first char value in this range.

last

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

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

intersectionLength

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

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