org.opensha.commons.param.constraint.impl
Class DoubleConstraint

java.lang.Object
  extended by org.opensha.commons.param.constraint.AbstractParameterConstraint<Double>
      extended by org.opensha.commons.param.constraint.impl.DoubleConstraint
All Implemented Interfaces:
Serializable, Named, ParameterConstraint<Double>

public class DoubleConstraint
extends AbstractParameterConstraint<Double>

Title: DoubleConstraint

Description: A doubleConstraint represents a range of allowed values between a min and max double value, inclusive. The main purpose of this class is to call isAllowed() which will return true if the value is withing the range. Null values may or may not be allowed. See the ParameterConstraint javadocs for further documentation.

Note: It is up to the programmer using this class to ensure that the min value is less than the max value. As an enhancement to this class setting min and max could be validated that min is not greater than max.

Version:
1.0
Author:
Sid Hellman, Steven W. Rock
See Also:
AbstractParameterConstraint, Serialized Form

Field Summary
protected static String C
          Class name for debugging.
protected static boolean D
          If true print out debug statements.
protected  Double max
          The maximum value allowed in this constraint, inclusive
protected  Double min
          The minimum value allowed in this constraint, inclusive
 
Fields inherited from class org.opensha.commons.param.constraint.AbstractParameterConstraint
editable, name, nullAllowed
 
Constructor Summary
DoubleConstraint()
          No-Arg Constructor, constraints are null so all values allowed
DoubleConstraint(double min, double max)
          Constructor for the DoubleConstraint object.
DoubleConstraint(Double min, Double max)
          Constructor for the DoubleConstraint object.
 
Method Summary
 Object clone()
          Creates a copy of this object instance so the original cannot be altered.
 Double getMax()
          Gets the max allowed value of this constraint
 Double getMin()
          Returns the min allowed value of this constraint.
 boolean isAllowed(double d)
          Checks if the passed in value is within the min and max, inclusive of the end points.
 boolean isAllowed(Double d)
          Checks if the passed in value is within the min and max, inclusive of the end points.
 void setMinMax(double min, double max)
          Sets the min and max values allowed in this constraint.
 void setMinMax(Double min, Double max)
          Sets the min and max values allowed in this constraint.
 String toString()
          returns the classname of the constraint, and the min & max as a debug string
 
Methods inherited from class org.opensha.commons.param.constraint.AbstractParameterConstraint
checkEditable, getName, isEditable, isNullAllowed, setName, setNonEditable, setNullAllowed
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

C

protected static final String C
Class name for debugging.

See Also:
Constant Field Values

D

protected static final boolean D
If true print out debug statements.

See Also:
Constant Field Values

min

protected Double min
The minimum value allowed in this constraint, inclusive


max

protected Double max
The maximum value allowed in this constraint, inclusive

Constructor Detail

DoubleConstraint

public DoubleConstraint()
No-Arg Constructor, constraints are null so all values allowed


DoubleConstraint

public DoubleConstraint(double min,
                        double max)
Constructor for the DoubleConstraint object. Sets the min and max values allowed in this constraint. No checks are performed that min and max are consistant with each other.

Parameters:
min - The min value allowed
max - The max value allowed

DoubleConstraint

public DoubleConstraint(Double min,
                        Double max)
Constructor for the DoubleConstraint object. Sets the min and max values allowed in this constraint. No checks are performed that min and max are consistant with each other.

Parameters:
min - The min value allowed
max - The max value allowed
Method Detail

setMinMax

public void setMinMax(double min,
                      double max)
               throws EditableException
Sets the min and max values allowed in this constraint. No checks are performed that min and max are consistant with each other.

Parameters:
min - The new min value
max - The new max value
Throws:
EditableException - Thrown when the constraint or parameter containing this constraint has been made non-editable.

setMinMax

public void setMinMax(Double min,
                      Double max)
               throws EditableException
Sets the min and max values allowed in this constraint. No checks are performed that min and max are consistant with each other.

Parameters:
min - The new min value
max - The new max value
Throws:
EditableException - Thrown when the constraint or parameter containing this constraint has been made non-editable.

getMin

public Double getMin()
Returns the min allowed value of this constraint.


getMax

public Double getMax()
Gets the max allowed value of this constraint


isAllowed

public boolean isAllowed(Double d)
Checks if the passed in value is within the min and max, inclusive of the end points. First the value is chekced if it's null and null values are allowed. Then it checks the passed in object is a Double. If the constraint min and max values are null, true is returned, else the value is compared against the min and max values. If any of these checks fails false is returned. Otherwise true is returned.

Parameters:
obj - The object to check if allowed.
Returns:
True if this is a Double and one of the allowed values.

isAllowed

public boolean isAllowed(double d)
Checks if the passed in value is within the min and max, inclusive of the end points. First the value is checked if it's null and null values are allowed. If the constraint min and max values are null, true is returned, else the value is compared against the min and max values. If any of these checks fails false is returned. Otherwise true is returned.

Parameters:
obj - The object to check if allowed.
Returns:
True if this is one of the allowed values.

toString

public String toString()
returns the classname of the constraint, and the min & max as a debug string

Overrides:
toString in class Object

clone

public Object clone()
Creates a copy of this object instance so the original cannot be altered.

Specified by:
clone in interface ParameterConstraint<Double>
Specified by:
clone in class AbstractParameterConstraint<Double>
Returns:
Exact copy of this object's state.