org.apache.commons.lang.math

Class Range

Known Direct Subclasses:
DoubleRange, FloatRange, IntRange, LongRange, NumberRange

public abstract class Range
extends java.lang.Object

Range represents a range of numbers of the same type.

Specific subclasses hold the range values as different types. Each subclass should be immutable and Serializable if possible.

Version:
$Id: Range.java,v 1.5 2003/08/18 02:22:24 bayard Exp $

Author:
Stephen Colebourne

Since:
2.0

Constructor Summary

Range()
Constructs a new range.

Method Summary

boolean
containsDouble(Number value)
Tests whether the specified Number occurs within this range using double comparison..
boolean
containsDouble(double value)
Tests whether the specified double occurs within this range using double comparison.
boolean
containsFloat(Number value)
Tests whether the specified Number occurs within this range using float comparison.
boolean
containsFloat(float value)
Tests whether the specified float occurs within this range using float comparison.
boolean
containsInteger(Number value)
Tests whether the specified Number occurs within this range using int comparison..
boolean
containsInteger(int value)
Tests whether the specified int occurs within this range using int comparison.
boolean
containsLong(Number value)
Tests whether the specified Number occurs within this range using long comparison..
boolean
containsLong(long value)
Tests whether the specified long occurs within this range using long comparison.
boolean
containsNumber(Number number)
Tests whether the specified Number occurs within this range.
boolean
containsRange(Range range)
Tests whether the specified range occurs entirely within this range.
boolean
equals(Object obj)
Compares this range to another object to test if they are equal.
double
getMaximumDouble()
Gets the maximum number in this range as a double.
float
getMaximumFloat()
Gets the maximum number in this range as a float.
int
getMaximumInteger()
Gets the maximum number in this range as a int.
long
getMaximumLong()
Gets the maximum number in this range as a long.
Number
getMaximumNumber()
Gets the maximum number in this range.
double
getMinimumDouble()
Gets the minimum number in this range as a double.
float
getMinimumFloat()
Gets the minimum number in this range as a float.
int
getMinimumInteger()
Gets the minimum number in this range as a int.
long
getMinimumLong()
Gets the minimum number in this range as a long.
Number
getMinimumNumber()
Gets the minimum number in this range.
int
hashCode()
Gets a hashCode for the range.
boolean
overlapsRange(Range range)
Tests whether the specified range overlaps with this range.
String
toString()
Gets the range as a String.

Constructor Details

Range

public Range()
Constructs a new range.

Method Details

containsDouble

public boolean containsDouble(Number value)

Parameters:
value - the double to test, may be null

Returns:
true if the specified number occurs within this range by double comparison


containsDouble

public boolean containsDouble(double value)

Parameters:
value - the double to test

Returns:
true if the specified number occurs within this range by double comparison


containsFloat

public boolean containsFloat(Number value)

Parameters:
value - the float to test, may be null

Returns:
true if the specified number occurs within this range by float comparison


containsFloat

public boolean containsFloat(float value)

Parameters:
value - the float to test

Returns:
true if the specified number occurs within this range by float comparison


containsInteger

public boolean containsInteger(Number value)

Parameters:
value - the integer to test, may be null

Returns:
true if the specified number occurs within this range by int comparison


containsInteger

public boolean containsInteger(int value)

Parameters:
value - the int to test

Returns:
true if the specified number occurs within this range by int comparison


containsLong

public boolean containsLong(Number value)

Parameters:
value - the long to test, may be null

Returns:
true if the specified number occurs within this range by long comparison


containsLong

public boolean containsLong(long value)

Parameters:
value - the long to test

Returns:
true if the specified number occurs within this range by long comparison


containsNumber

public boolean containsNumber(Number number)
Tests whether the specified Number occurs within this range.

The exact comparison implementation varies by subclass. It is intended that an int specific subclass will compare using int comparison.

null is handled and returns false.

Parameters:
number - the number to test, may be null

Returns:
true if the specified number occurs within this range


containsRange

public boolean containsRange(Range range)
Tests whether the specified range occurs entirely within this range.

The exact comparison implementation varies by subclass. It is intended that an int specific subclass will compare using int comparison.

null is handled and returns false.

This implementation uses the containsNumber(Number) method. Subclasses may be able to optimise this.

Parameters:
range - the range to test, may be null

Returns:
true if the specified range occurs entirely within this range; otherwise, false


equals

public boolean equals(Object obj)

Parameters:
obj - the reference object with which to compare

Returns:
true if this object is equal


getMaximumDouble

public double getMaximumDouble()

Returns:
the maximum number in this range


getMaximumFloat

public float getMaximumFloat()

Returns:
the maximum number in this range


getMaximumInteger

public int getMaximumInteger()

Returns:
the maximum number in this range


getMaximumLong

public long getMaximumLong()

Returns:
the maximum number in this range


getMaximumNumber

public Number getMaximumNumber()
Gets the maximum number in this range.

Returns:
the maximum number in this range


getMinimumDouble

public double getMinimumDouble()

Returns:
the minimum number in this range


getMinimumFloat

public float getMinimumFloat()

Returns:
the minimum number in this range


getMinimumInteger

public int getMinimumInteger()

Returns:
the minimum number in this range


getMinimumLong

public long getMinimumLong()

Returns:
the minimum number in this range


getMinimumNumber

public Number getMinimumNumber()
Gets the minimum number in this range.

Returns:
the minimum number in this range


hashCode

public int hashCode()

Returns:
a hash code value for this object


overlapsRange

public boolean overlapsRange(Range range)
Tests whether the specified range overlaps with this range.

The exact comparison implementation varies by subclass. It is intended that an int specific subclass will compare using int comparison.

null is handled and returns false.

This implementation uses the containsNumber(Number) and containsRange(Range) methods. Subclasses may be able to optimise this.

Parameters:
range - the range to test, may be null

Returns:
true if the specified range overlaps with this range; otherwise, false


toString

public String toString()

Returns:
the String representation of this range


Copyright © 2001-2003 - Apache Software Foundation