Algorithm
Development Kit 1.0

algs.model.interval
Class DiscreteInterval

java.lang.Object
  extended by algs.model.interval.DiscreteInterval
All Implemented Interfaces:
IInterval

public class DiscreteInterval
extends java.lang.Object
implements IInterval

Represents a discrete interval [left,right) that implements IInterval.

The interval [left,right) is closed on left, but open on right.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Constructor Summary
DiscreteInterval(int left, int right)
          Create a discrete interval whose left is strictly less than its right.
 
Method Summary
 boolean equals(java.lang.Object o)
          Compare DiscreteInterval objects.
 int getLeft()
          Return the left value of the interval.
 int getRight()
          Return the right value of the interval.
 int hashCode()
          Returns the hashCode for this DiscreteInterval.
 boolean intersects(int q)
          Determines if the q value is greater than or equal to getLeft() and strictly less than getRight()
 java.lang.String toString()
          Return reasonable String representation.
 boolean toTheLeft(int q)
          Determines if the q value is strictly less than the getLeft() value.
 boolean toTheRight(int q)
          Determines if the q value is greater than or equal to the getRight() value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DiscreteInterval

public DiscreteInterval(int left,
                        int right)
Create a discrete interval whose left is strictly less than its right.

Parameters:
left - leftmost value in interval (open)
right - rightmost value in interval (closed)
Method Detail

getLeft

public int getLeft()
Return the left value of the interval.

Specified by:
getLeft in interface IInterval
Returns:
left index whose value is strictly less than right index

getRight

public int getRight()
Return the right value of the interval.

Specified by:
getRight in interface IInterval
Returns:
right index whose value is strictly greater than left index

equals

public boolean equals(java.lang.Object o)
Compare DiscreteInterval objects. Note, as per IInterval contract, only compares against IInterval information.

Overrides:
equals in class java.lang.Object
Parameters:
o - object against which to compare.

hashCode

public int hashCode()
Returns the hashCode for this DiscreteInterval. Idea taken from java.awt.Point2D

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

toString

public java.lang.String toString()
Return reasonable String representation.

Overrides:
toString in class java.lang.Object

intersects

public boolean intersects(int q)
Description copied from interface: IInterval
Determines if the q value is greater than or equal to getLeft() and strictly less than getRight()

Specified by:
intersects in interface IInterval

toTheLeft

public boolean toTheLeft(int q)
Description copied from interface: IInterval
Determines if the q value is strictly less than the getLeft() value.

Specified by:
toTheLeft in interface IInterval

toTheRight

public boolean toTheRight(int q)
Description copied from interface: IInterval
Determines if the q value is greater than or equal to the getRight() value.

Specified by:
toTheRight in interface IInterval

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.