public class ASTReal
extends java.lang.Object
This class is useful because Java passes all parameters to a method by value. Hence, in Java one cannot have a statement such as
bValid = isValidReal(String inputStr, double dResult)
where the isValidReal
method returns a validity (true/false) and
modifies dResult
to have the value parsed from inputStr
.
Passing objects rather than primitives such as double avoids this problem.
Copyright (c) 2018
Constructor and Description |
---|
ASTReal()
Class constructor.
|
ASTReal(double r)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
double |
getRealValue()
Gets the real value in the object
|
static ASTReal |
isValidReal(java.lang.String inputStr)
Checks to see if a valid number was entered, but don't display
any error messages unless flag is
ASTMisc.SHOW_ERRORS . |
static ASTReal |
isValidReal(java.lang.String inputStr,
boolean flag)
Checks to see if a valid number was entered, but don't display
any error messages unless flag is
ASTMisc.SHOW_ERRORS . |
boolean |
isValidRealObj()
Returns whether the object is a valid real number
|
void |
setRealValue(double r)
Sets the real value in the object
|
public ASTReal()
Since much of the usage of this class involves validating that a string has a valid real number, assume a new object is invalid until it is proven otherwise.
public ASTReal(double r)
Explicitly give an object a value.
r
- value for the new real objectpublic boolean isValidRealObj()
public double getRealValue()
public void setRealValue(double r)
r
- value to which the object is to be setpublic static ASTReal isValidReal(java.lang.String inputStr)
ASTMisc.SHOW_ERRORS
.
to let the calling routine display its own error messages.
This function is overloaded to allow flag to be an optional parameter. The default is to display error messages.
inputStr
- string to be validatedpublic static ASTReal isValidReal(java.lang.String inputStr, boolean flag)
ASTMisc.SHOW_ERRORS
.
to let the calling routine display its own error messages.
This function is overloaded to allow flag to be an optional parameter. The default is to display error messages.
inputStr
- string to be validatedflag
- ASTMisc.SHOW_ERRORS if an error message should be displayed