JavaGenes, NASA Ames. Written largely by Al Globus

gov.nasa.alsUtility
Class DoubleInterval

java.lang.Object
  extended bygov.nasa.alsUtility.DoubleInterval
All Implemented Interfaces:
java.io.Serializable

public class DoubleInterval
extends java.lang.Object
implements java.io.Serializable

implements an interval between two double values

See Also:
Serialized Form

Field Summary
protected  double bottom
          the lowest value in the interval
protected  boolean includeBottom
          does this interval include the bottom most value?
protected  boolean includeTop
          does this interval include to most value?
protected  double top
          the highest value in the interval
 
Constructor Summary
DoubleInterval()
          create an interval 0 to 1
DoubleInterval(double[] ofDoubles)
           
DoubleInterval(double x, boolean includeX, double y, boolean includeY)
           
DoubleInterval(double x, double y)
          create an interval with between x and y.
DoubleInterval(DoubleInterval i)
           
DoubleInterval(java.util.Vector ofDoubles)
           
 
Method Summary
 double distanceFrom(double value)
          how far outside of the interval is value?
 double equalIncrements(int divisions)
           
 void expand(double factor)
          change the interval of this by a factor keeping the center of the interval the same.
 void expandByAddition(double expandBy)
           
 void extendIfNecessary(double d)
           
 double get(int i)
           
 double high()
           
 double interval()
           
 boolean isBetween(double value)
           
 boolean isEmpty()
          are there any numbers that fall within this interval?
 boolean isPositive()
           
 double limitTo(double value)
           
 DoubleInterval limitTo(DoubleInterval interval)
           
 double low()
           
 double midPoint()
           
 boolean nearlyEqual(DoubleInterval other)
           
 double random()
          choose a random number in the interval (including the high and low values)
 double randomGaussian(double center, double sd)
          choose a random number in the interval from a Gaussian distribution
 double randomLog()
          choose a random number in the interval (including the high and low values) from a log distribution
 double randomLogFromBothEnds()
          choose a random number in the interval (including the high and low values) from a log distribution whether you start from the top or the bottom
 DoubleInterval set(double x, boolean includeX, double y, boolean includeY)
           
 DoubleInterval set(double x, double y)
          set the high and low values of the interval.
 DoubleInterval set(DoubleInterval interval)
          make this equal to interval
 DoubleInterval setHigh(double v)
           
 DoubleInterval setLow(double v)
           
 void setToExtremes(double[] array)
          set the bounds to the extreme values in array
 void setToExtremes(java.util.Vector ofDoubles)
           
 DoubleInterval setToLog()
          convert the top and bottom values to their natural logarithm
 double terpolate0to1(double value)
          interpolate or exterpolate to a 0-1 space
 java.lang.String toString()
           
 DoubleInterval translate(double distance)
          add distance to the top and bottom
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

bottom

protected double bottom
the lowest value in the interval


top

protected double top
the highest value in the interval


includeBottom

protected boolean includeBottom
does this interval include the bottom most value?


includeTop

protected boolean includeTop
does this interval include to most value?

Constructor Detail

DoubleInterval

public DoubleInterval()
create an interval 0 to 1


DoubleInterval

public DoubleInterval(double x,
                      double y)
create an interval with between x and y. Will figure out which is lowest.


DoubleInterval

public DoubleInterval(double x,
                      boolean includeX,
                      double y,
                      boolean includeY)

DoubleInterval

public DoubleInterval(DoubleInterval i)

DoubleInterval

public DoubleInterval(java.util.Vector ofDoubles)

DoubleInterval

public DoubleInterval(double[] ofDoubles)
Method Detail

isPositive

public boolean isPositive()

expand

public void expand(double factor)
change the interval of this by a factor keeping the center of the interval the same.

Parameters:
factor - the factor by which to change the size of the interval. factor < 1 will shrink the interval. factor > 1 will expand the interval. Negative factors with be converted to positive.

expandByAddition

public void expandByAddition(double expandBy)

midPoint

public double midPoint()

set

public DoubleInterval set(double x,
                          double y)
set the high and low values of the interval. Figures out which is lowest.


setLow

public DoubleInterval setLow(double v)

setHigh

public DoubleInterval setHigh(double v)

set

public DoubleInterval set(DoubleInterval interval)
make this equal to interval


set

public DoubleInterval set(double x,
                          boolean includeX,
                          double y,
                          boolean includeY)

limitTo

public DoubleInterval limitTo(DoubleInterval interval)

nearlyEqual

public boolean nearlyEqual(DoubleInterval other)

limitTo

public double limitTo(double value)

isBetween

public boolean isBetween(double value)

distanceFrom

public double distanceFrom(double value)
how far outside of the interval is value?


isEmpty

public boolean isEmpty()
are there any numbers that fall within this interval?


setToExtremes

public void setToExtremes(double[] array)
set the bounds to the extreme values in array


setToExtremes

public void setToExtremes(java.util.Vector ofDoubles)

extendIfNecessary

public void extendIfNecessary(double d)

toString

public java.lang.String toString()

random

public double random()
choose a random number in the interval (including the high and low values)


randomLogFromBothEnds

public double randomLogFromBothEnds()
choose a random number in the interval (including the high and low values) from a log distribution whether you start from the top or the bottom


randomGaussian

public double randomGaussian(double center,
                             double sd)
choose a random number in the interval from a Gaussian distribution

Parameters:
center - the mean of the Gaussian
sd - the standard deviation of the Gaussian

randomLog

public double randomLog()
choose a random number in the interval (including the high and low values) from a log distribution


terpolate0to1

public double terpolate0to1(double value)
interpolate or exterpolate to a 0-1 space


translate

public DoubleInterval translate(double distance)
add distance to the top and bottom


setToLog

public DoubleInterval setToLog()
convert the top and bottom values to their natural logarithm


low

public double low()
Returns:
bottom

high

public double high()
Returns:
top

get

public double get(int i)

interval

public double interval()

equalIncrements

public double equalIncrements(int divisions)
Returns:
a value that will divide the interval into division increments

JavaGenes, NASA Ames. Written largely by Al Globus