TUM CCSM Commons

edu.tum.cs.commons.math
Class Range

java.lang.Object
  extended by edu.tum.cs.commons.math.Range

public class Range
extends java.lang.Object

A class that represents ranges that may include or exclude the upper and lower bounds. This class is immutable.

Note: If a range is constructed where the upper and lower bounds are equal and one of them is exclusive, this range is considered empty, i.e. no number can be contained in it.

Version:
$Rev: 26268 $
Author:
deissenb, $Author: juergens $
Rating:
GREEN Hash: 71F5CBF843D6B94E6071CAF614C19E6B

Constructor Summary
Range(double lower, boolean lowerIsInclusive, double upper, boolean upperIsInclusive)
          Create range.
Range(double lower, double upper)
          Create range where both bounds are inclusive.
 
Method Summary
 boolean contains(double number)
          Checks is a number is contained in the range.
 boolean equals(java.lang.Object obj)
          Two ranges are equal if their bounds are equal and the flags that indicate if the bounds are inclusive or not are equal, too.
 java.lang.String format(java.text.NumberFormat numberFormat)
          String representation contains the bounds and brackets that indicate if the bounds are inclusive or exclusive.
 double getLower()
          Get lower bound.
 double getUpper()
          Get upper bound.
 int hashCode()
          Hash code includes bound and the flags that indicate if the bounds are inclusive or not.
 boolean isEmpty()
          Checks if a range is empty.
 boolean isLowerInclusive()
          Get flag that indicates if the lower bound is inclusive.
 boolean isUpperInclusive()
          Get flag that indicates if the upper bound is inclusive.
 double size()
          Returns the size of the range.
 java.lang.String toString()
          This forwards to format(null);.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Range

public Range(double lower,
             double upper)
Create range where both bounds are inclusive.


Range

public Range(double lower,
             boolean lowerIsInclusive,
             double upper,
             boolean upperIsInclusive)
Create range.

Parameters:
lower - lower bound
lowerIsInclusive - flag that indicates if lower bound is inclusive or not
upper - upper bound
upperIsInclusive - flag that indicates if upper bound is inclusive or not
Method Detail

contains

public boolean contains(double number)
Checks is a number is contained in the range.


hashCode

public int hashCode()
Hash code includes bound and the flags that indicate if the bounds are inclusive or not.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Two ranges are equal if their bounds are equal and the flags that indicate if the bounds are inclusive or not are equal, too. Empty ranges are considered equal regardless for there specific bounds.

Overrides:
equals in class java.lang.Object

getLower

public double getLower()
Get lower bound.


getUpper

public double getUpper()
Get upper bound.


isLowerInclusive

public boolean isLowerInclusive()
Get flag that indicates if the lower bound is inclusive.


isUpperInclusive

public boolean isUpperInclusive()
Get flag that indicates if the upper bound is inclusive.


isEmpty

public boolean isEmpty()
Checks if a range is empty.


size

public double size()
Returns the size of the range. In case of empty ranges this returns 0. Note that inclusiveness of bound is not relevant for this method.


toString

public java.lang.String toString()
This forwards to format(null);.

Overrides:
toString in class java.lang.Object

format

public java.lang.String format(java.text.NumberFormat numberFormat)
String representation contains the bounds and brackets that indicate if the bounds are inclusive or exclusive.

Parameters:
numberFormat - number format used for formatting the numbers. If this is null, no special formatting is applied.

TUM CCSM Commons

TUM CCSM Commons - 2.7