de.luschny.math.util
Class PositiveRange

java.lang.Object
de.luschny.math.util.PositiveRange
All Implemented Interfaces:
java.lang.Cloneable

public final class PositiveRange
extends java.lang.Object
implements java.lang.Cloneable

A PositiveRange is an intervall of integers, given by a lower bound L and an upper bound U, such that 0 <= L and L <= U. A PositiveRange is immutable.


Field Summary
private  int max
          
private  int min
          
 
Constructor Summary
PositiveRange(int low, int high)
          Creates a PositiveRange, i.e. a range of integers, such that 0 <= low <= high.
 
Method Summary
 java.lang.Object clone()
          Creates and returns a copy of this object.
 boolean contains(int value)
          Checks, if the given value lies within the range, i.e. min <= value and value <= max.
 boolean contains(PositiveRange range)
          Checks, if the given range is a subrange, i.e. this.min <= range.min and range.max <= this.max.
 boolean containsOrFail(int value)
          Checks, if the given value lies within the range, i.e. min <= value and value <= max. If the value ist not contained an IndexOutOfBoundsException will be raised.
 boolean containsOrFail(PositiveRange range)
          Checks, if the given range is a subrange, i.e. this.min <= range.min and range.max <= this.max. If the range ist not contained an IndexOutOfBoundsException will be raised.
 boolean equals(java.lang.Object o)
          Compares this range to the specified object.
 int getMax()
          Get upper bound (maximum) of the range.
 int getMin()
          Get the lower bound (minimum) of the range.
 int hashCode()
          A hash code value for this range.
 int size()
          Computes the size of the range.
 java.lang.String toString()
          Gets the range as a String.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

max

private final int max

min

private final int min
Constructor Detail

PositiveRange

public PositiveRange(int low,
                     int high)
Creates a PositiveRange, i.e. a range of integers, such that 0 <= low <= high.

Parameters:
low - The low bound (minimum) of the range.
high - The high bound (maximum) of the range.
Throws:
java.lang.IllegalArgumentException
Method Detail

clone

public java.lang.Object clone()
Creates and returns a copy of this object.

Overrides:
clone in class java.lang.Object
Returns:
A copy of this PositiveRange.

contains

public boolean contains(int value)
Checks, if the given value lies within the range, i.e. min <= value and value <= max.

Parameters:
value - The value to checked.
Returns:
True, if the range includes the value, false otherwise.
See Also:
containsOrFail(int value)

contains

public boolean contains(PositiveRange range)
Checks, if the given range is a subrange, i.e. this.min <= range.min and range.max <= this.max.

Parameters:
range - The range to be checked.
Returns:
True, if the given range lies within this range, false otherwise.
See Also:
containsOrFail(PositiveRange range)

containsOrFail

public boolean containsOrFail(int value)
Checks, if the given value lies within the range, i.e. min <= value and value <= max. If the value ist not contained an IndexOutOfBoundsException will be raised.

Parameters:
value - The value to checked.
Returns:
True, if the range includes the value, false otherwise.
Throws:
java.lang.IndexOutOfBoundsException

containsOrFail

public boolean containsOrFail(PositiveRange range)
Checks, if the given range is a subrange, i.e. this.min <= range.min and range.max <= this.max. If the range ist not contained an IndexOutOfBoundsException will be raised.

Parameters:
range - The range to be checked.
Returns:
True, if the given range lies within this range, otherwise an IndexOutOfBoundsException is thrown.
Throws:
java.lang.IndexOutOfBoundsException

equals

public boolean equals(java.lang.Object o)
Compares this range to the specified object. The result is true if and only if the argument is not null and is an range object that has the same bound values as this object.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object to compare with.
Returns:
True if the objects are the same; false otherwise.

getMax

public int getMax()
Get upper bound (maximum) of the range.

Returns:
The maximum of the range.

getMin

public int getMin()
Get the lower bound (minimum) of the range.

Returns:
The minimum of the range.

hashCode

public int hashCode()
A hash code value for this range.

Overrides:
hashCode in class java.lang.Object
Returns:
Returns a hash code for this.

size

public int size()
Computes the size of the range.

Returns:
The size of the range.

toString

public java.lang.String toString()

Gets the range as a String.

The format of the String is '[min,max]'.

Overrides:
toString in class java.lang.Object
Returns:
the String representation of this range.