com.mhhe.clrs2e
Class Interval

java.lang.Object
  |
  +--com.mhhe.clrs2e.Interval
All Implemented Interfaces:
java.lang.Comparable

public class Interval
extends java.lang.Object
implements java.lang.Comparable

Implements an interval whose endpoints are real numbers.


Field Summary
protected  double high
          High endpoint of the interval.
protected  double low
          Low endpoint of the interval.
 
Constructor Summary
Interval(double low, double high)
          Initializes the endpoints of the interval.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this interval to another, based on their low endpoints.
 double getHigh()
          Returns the high endpoint of the interval.
 double getLow()
          Returns the low endpoint of the interval.
 boolean overlaps(com.mhhe.clrs2e.Interval i)
          Returns whether this interval overlaps another interval.
 java.lang.String toString()
          Returns the String representation of this interval in the form [low, high].
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

low

protected final double low
Low endpoint of the interval.


high

protected final double high
High endpoint of the interval.

Constructor Detail

Interval

public Interval(double low,
                double high)
Initializes the endpoints of the interval.

Parameters:
low - The low endpoint.
high - The high endpoint.
Method Detail

getLow

public double getLow()
Returns the low endpoint of the interval.


getHigh

public double getHigh()
Returns the high endpoint of the interval.


overlaps

public boolean overlaps(com.mhhe.clrs2e.Interval i)
Returns whether this interval overlaps another interval.

Parameters:
i - The other interval.
Returns:
true if this interval overlaps i, false otherwise.

toString

public java.lang.String toString()
Returns the String representation of this interval in the form [low, high].

Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Compares this interval to another, based on their low endpoints.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - The other Interval object.
Returns:
A negative integer if this Interval is less; 0 if the objects are equal; a positive integer if this Interval is greater.
Throws:
java.lang.ClassCastException - if o is not an Interval object.