maspack.util
Class DoubleInterval

java.lang.Object
  extended by maspack.util.RangeBase
      extended by maspack.util.NumericInterval
          extended by maspack.util.DoubleInterval
All Implemented Interfaces:
java.lang.Cloneable, Clonable, Range, Scannable

public class DoubleInterval
extends NumericInterval

A Range object which inspects a number to make sure it lies within a prescibed interval.


Field Summary
static DoubleInterval NonNegative
           
static DoubleInterval Positive
           
 
Fields inherited from interface maspack.util.Range
IllegalValue
 
Constructor Summary
DoubleInterval()
          Creates a DoubleRange which accepts any double value.
DoubleInterval(double lower, double upper)
          Creates a new DoubleRange that accepts any value in the closed interval [lower, upper].
DoubleInterval(NumericInterval rng)
          Creates a new DoubleRange which is a copy of an existing NumericRange one.
DoubleInterval(java.lang.String str)
          Creates a new DoubleRange from a specification string.
 
Method Summary
 DoubleInterval clone()
           
 void scan(ReaderTokenizer rtok, java.lang.Object ref)
          Scans this element from a ReaderTokenizer.
 void set(double lower, double upper)
          Sets this DoubleRange so that it accepts any value in the closed interval [lower, upper].
 void set(double lower, double upper, java.lang.String closure)
          Sets this DoubleRange so that it accepts any value within a specified interval.
 void set(NumericInterval rng)
          Sets this DoubleRange to the value of any NumericRange.
 void setLowerBound(double lower)
          Sets the lower bound for the interval of this DoubleRange.
 void setLowerBoundClosed(boolean closed)
          Sets the lower bound for the interval of this DoubleRange to be closed or open.
 void setUpperBound(double upper)
          Sets the upper bound for the interval of this DoubleRange.
 void setUpperBoundClosed(boolean closed)
          Sets the upper bound for the interval of this DoubleRange to be closed or open.
 java.lang.String toString()
           
 void write(java.io.PrintWriter pw, NumberFormat fmt, java.lang.Object ref)
          Writes a text description of this element to a PrintWriter.
 
Methods inherited from class maspack.util.NumericInterval
canClipToRange, clipToRange, contains, equals, equals, getLowerBound, getRange, getUpperBound, intersect, isBounded, isClosed, isEmpty, isLowerBoundClosed, isTypeCompatible, isUpperBoundClosed, isValid, makeValid, makeValid, merge, parse, validate, validate, withinRange, withinRange
 
Methods inherited from class maspack.util.RangeBase
isWritable, setError
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

Positive

public static DoubleInterval Positive

NonNegative

public static DoubleInterval NonNegative
Constructor Detail

DoubleInterval

public DoubleInterval()
Creates a DoubleRange which accepts any double value.


DoubleInterval

public DoubleInterval(double lower,
                      double upper)
Creates a new DoubleRange that accepts any value in the closed interval [lower, upper].

Parameters:
lower - interval lower bound
upper - interval upper bound

DoubleInterval

public DoubleInterval(NumericInterval rng)
Creates a new DoubleRange which is a copy of an existing NumericRange one.

Parameters:
rng - range to copy

DoubleInterval

public DoubleInterval(java.lang.String str)
               throws java.lang.IllegalArgumentException
Creates a new DoubleRange from a specification string. For the string syntax, see scan.

Parameters:
str - specification string for this DoubleRange
Throws:
java.lang.IllegalArgumentException - if the string is not in the correct format.
Method Detail

setLowerBound

public void setLowerBound(double lower)
Sets the lower bound for the interval of this DoubleRange.

Parameters:
lower - new lower interval bound

setLowerBoundClosed

public void setLowerBoundClosed(boolean closed)
Sets the lower bound for the interval of this DoubleRange to be closed or open.

Parameters:
closed - if true, sets the lower interval bound to be closed

setUpperBound

public void setUpperBound(double upper)
Sets the upper bound for the interval of this DoubleRange.

Parameters:
upper - new upper interval bound

setUpperBoundClosed

public void setUpperBoundClosed(boolean closed)
Sets the upper bound for the interval of this DoubleRange to be closed or open.

Parameters:
closed - if true, sets the upper interval bound to be closed

set

public void set(double lower,
                double upper)
Sets this DoubleRange so that it accepts any value in the closed interval [lower, upper].

Parameters:
lower - interval lower bound
upper - interval upper bound

set

public void set(NumericInterval rng)
Sets this DoubleRange to the value of any NumericRange.

Parameters:
rng - numeric range to copy

set

public void set(double lower,
                double upper,
                java.lang.String closure)
Sets this DoubleRange so that it accepts any value within a specified interval. The lower and upper bounds of the interval may be either open or closed, as specified by a string argument which should be set to one of four values:

Parameters:
lower - interval lower bound
upper - interval upper bound
closure - specifies whether the lower and upper bounds are open or closed
Throws:
java.lang.IllegalArgumentException - if the closure specification string is not one of "[]", "[)", "(]", or "()".

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

scan

public void scan(ReaderTokenizer rtok,
                 java.lang.Object ref)
          throws java.io.IOException
Scans this element from a ReaderTokenizer. The input should consist of five tokens, which specifiy the interval as follows:

Specified by:
scan in interface Scannable
Overrides:
scan in class RangeBase
Parameters:
rtok - Tokenizer from which to scan the element
ref - reference object (not used, may be null)
Throws:
java.io.IOException - if an I/O or formatting error occured

write

public void write(java.io.PrintWriter pw,
                  NumberFormat fmt,
                  java.lang.Object ref)
           throws java.io.IOException
Writes a text description of this element to a PrintWriter. The text description should be compatable with scan and complete enough to allow full reconstruction of the element.

Specified by:
write in interface Scannable
Overrides:
write in class RangeBase
Parameters:
pw - stream for writing the element
fmt - numeric formating information
ref - optional reference object which can be used for producing references to other objects
Throws:
java.io.IOException - if an I/O error occured

clone

public DoubleInterval clone()
Specified by:
clone in interface Clonable
Overrides:
clone in class NumericInterval