mapss.dif.attributes
Class Interval

java.lang.Object
  extended by mapss.dif.attributes.Interval

public class Interval
extends java.lang.Object

Defines one dimensional inclusive or exclusive intervals. Intervals are immutable.

Version:
$Id: Interval.java 362 2007-02-25 21:08:57Z plishker $
Author:
Fuat Keceli based on a file by Shahrooz Shahparnia

Constructor Summary
Interval(double point)
          Creates a point: [a,a].
Interval(double lowerBound, boolean includesLow, double higherBound, boolean includesHigh)
          Creates an interval.
 
Method Summary
protected  boolean _isValid(double lowerBound, boolean includesLow, double higherBound, boolean includesHigh)
          Check if the change to the bounds can be applied or not.
 int compare(Interval interval)
          Compares two intervals.
 boolean contains(double value)
          Check if a given value is within this interval or not.
 double getHighValue()
          Return the higher bound of this interval.
 double getLowValue()
          Return the lower bound of this interval.
 boolean includesHigh()
          True if the interval includes the higher bound.
 boolean includesLow()
          True if the interval includes the low value.
 boolean intersects(Interval interval)
           
 java.lang.String toString()
          Return the string equivalent of this interval.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Interval

public Interval(double point)
Creates a point: [a,a].

Parameters:
point - The point to create.

Interval

public Interval(double lowerBound,
                boolean includesLow,
                double higherBound,
                boolean includesHigh)
Creates an interval.

Parameters:
lowerBound - The lower bound of the interval.
includesLow - True if the lower bound is to be included in the interval.
higherBound - The lower bound of the interval.
includesHigh - True if the higher bound is to be included in the interval.
Throws:
java.lang.IllegalArgumentException - If the interval is not valid.
Method Detail

compare

public int compare(Interval interval)
Compares two intervals.

Parameters:
interval - Interval to compare with this one.
Returns:
0 if intervals intersect. 1 if all of this interval's values are bigger, -1 otherwise.

contains

public boolean contains(double value)
Check if a given value is within this interval or not.

Parameters:
value - The given value.
Returns:
True if the given value is within the interval.

getHighValue

public double getHighValue()
Return the higher bound of this interval.

Returns:
The higher bound of this interval.

getLowValue

public double getLowValue()
Return the lower bound of this interval.

Returns:
The lower bound of this interval.

includesHigh

public boolean includesHigh()
True if the interval includes the higher bound.

Returns:
True if the interval includes the higher bound.

includesLow

public boolean includesLow()
True if the interval includes the low value.

Returns:
True if the interval includes the lower bound.

intersects

public boolean intersects(Interval interval)
Parameters:
interval - Interval to compare with.
Returns:
True if two intervals share any points.

toString

public java.lang.String toString()
Return the string equivalent of this interval.

Overrides:
toString in class java.lang.Object
Returns:
Return the string equivalent of this interval.

_isValid

protected boolean _isValid(double lowerBound,
                           boolean includesLow,
                           double higherBound,
                           boolean includesHigh)
Check if the change to the bounds can be applied or not.

Parameters:
lowerBound - The lower bound of the interval.
includesLow - True if the lower bound is to be included in the interval.
higherBound - The lower bound of the interval.
includesHigh - True if the higher bound is to be included in the interval.