|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.lang.Number
com.davisor.data.SimpleNumberValue
SimpleNumberValue defines default implementations for NumberValue methods. SimpleNumberValue also inherits the Java
Number, which makes it compatible with many external
software components.
Simple number value objects contain a generic Java
Number instance that represent the object number
value. No explicit constrains are set for the exact implementation
of the Number instance, making convenient number
value assignments and type conversions possible.
Simple number values support also the concept of an unspecified
number value (null). An unspecified number value does
not take part in comparison or arithmetic operations, as
appropriate in each case. In particular, unspecified values are
not the same thing as using a default zero value, although
in some cases they may yield similar results.
SimpleNumberType,
Serialized Form| Field Summary | |
protected NumberType |
M_type
The type of this data (may be null). |
protected java.lang.Number |
M_value
Underlying number value (may be null). |
| Constructor Summary | |
protected |
SimpleNumberValue(NumberType type)
Create a new data object with given type. |
protected |
SimpleNumberValue(NumberType type,
java.lang.Number value)
Create a new data object with given type and initial value. |
protected |
SimpleNumberValue(SimpleNumberValue snv,
boolean deep)
Deep or shallow copy constructor. |
| Method Summary | |
abstract DataValue |
abs()
Returns absolute data value of current value. |
DataValue |
add(DataValue value)
Adds data values. |
byte |
byteValue()
Gets number byte value. |
DataValue |
ceil(DataValue precision)
Quantizes the current value up to an even value within given precision. |
int |
compareTo(java.lang.Object o)
Compares this number value object with another object. |
double |
deinterpolate(DataValue min,
DataValue max)
De-interpolates the current data value to a scalar value, in respect, with the given data value range. |
DataValue |
div(DataValue value)
Divides the current value with given value. |
double |
doubleValue()
Gets number double value. |
boolean |
equals(java.lang.Object o)
Tests if this object is equal with another object. |
float |
floatValue()
Gets the number float value. |
DataValue |
floor(DataValue precision)
Quantizes the current value down to an even value within given precision. |
java.lang.String |
getFormat()
Gets the type specification optimal for this particular value. |
static java.lang.String |
getFormat(double value)
Constructs a JavaDecimalFormat pattern suitable for
displaying values of the given magnitude. |
Type |
getType()
Gets the data type. |
int |
hashCode()
Returns a hash code value for the object. |
DataValue |
interpolate(double value,
DataValue max)
Interpolates the given scalar value to data value, in respect, with the range defined by this value and the given maximum value. |
int |
intValue()
Gets number int value. |
boolean |
isNull()
Tests if this data object value is undetermined. |
long |
longValue()
Gets number long value. |
DataValue |
max(DataValue value)
Finds the larger of this and the given data value. |
DataValue |
min(DataValue value)
Finds the smaller of two data value. |
DataValue |
mul(DataValue value)
Multiplies the current value with given value. |
abstract DataValue |
negate()
Returns the negation of current value. |
java.lang.Number |
numberValue()
Gets the data Number value. |
void |
setValue(byte value)
Sets the data byte value. |
abstract void |
setValue(double value)
Sets the data double value. |
void |
setValue(float value)
Sets the data float value. |
void |
setValue(int value)
Sets the data int value. |
abstract void |
setValue(long value)
Sets the data long value. |
abstract void |
setValue(java.lang.Number value)
Sets the data Number value. |
void |
setValue(short value)
Sets the data short value. |
short |
shortValue()
Gets number short value. |
DataValue |
sub(DataValue value)
Substracts a data value. |
java.lang.String |
toString()
Gets the string representation of this number value. |
java.lang.String |
toXML()
Gets the XML string representation of this value. |
DataValue |
unit(DataValue targetValue,
double maxSteps)
Gets the largest suitable unit step to represent a value change between this value and the given target value. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.davisor.data.DataValue |
setValue, toStatement |
| Methods inherited from interface com.davisor.core.Dupable |
dup |
| Field Detail |
protected NumberType M_type
protected java.lang.Number M_value
| Constructor Detail |
protected SimpleNumberValue(SimpleNumberValue snv,
boolean deep)
null source data will leave both the type and value
to null values.
snv - number value to be copied (may be null)deep - determines if the copying is deep or shallowgetType(),
Type.dup()protected SimpleNumberValue(NumberType type)
type - the type of data (may be null)
protected SimpleNumberValue(NumberType type,
java.lang.Number value)
type - the type of data (may be null)value - the data number value (may be null)| Method Detail |
public int compareTo(java.lang.Object o)
If one of the two values is null or
NaN, it will be considered the smaller of the two
values. If both values are null or
NaN, they will be considered equal. For an
alternative way to compare data values, please see DataValue.min(com.davisor.data.DataValue) and DataValue.max(com.davisor.data.DataValue).
compareTo in interface java.lang.Comparableo - object to compare this object with (may be null)
java.lang.ClassCastException - if the given object is not a Number
public Type getType()
throws InvalidDataException
getType in interface DataInvalidDataException - if type retrieval failspublic boolean isNull()
A simple number value is undetermined if the underlying number
object is null, it has a NaN double
value, or the double value can not be determined at all.
isNull in interface SerializableDataType.isNull(com.davisor.data.SerializableData)
public abstract DataValue abs()
throws InvalidDataException
Absolute values must satisfy a requirement that when added to any other value, the result must be greater than or equal to the original value.
abs in interface DataValueInvalidDataException - if absolute value can not be computed
public DataValue add(DataValue value)
throws InvalidDataException
add in interface DataValuevalue - a data value to be added to this data value
InvalidDataException - if the data values cannot be added.
public DataValue ceil(DataValue precision)
throws InvalidDataException
All number values are rounded off with the equation:
ceil(thisValue / precision) * precision
ceil in interface DataValueprecision - the precision within the quantization occurs
InvalidDataException - if precision was of unacceptable typefloor(com.davisor.data.DataValue)
public double deinterpolate(DataValue min,
DataValue max)
throws InvalidDataException
Number values are de-interpolated with the equation:
(thisValue - minValue) / (maxValue - minValue)
If current value is null, NaN is
returned. If either of the range values is null,
InvalidDataException is thrown.
deinterpolate in interface DataValuemin - a data value representing a range's lower limitmax - a data value representing a range's higher limit
InvalidDataException - if the de-interpolation failsDataValue.interpolate(double, com.davisor.data.DataValue),
DeinterpolationException,
TupleData.deinterpolate(com.davisor.data.DataValue, com.davisor.data.DataValue)
public DataValue div(DataValue value)
throws InvalidDataException
div in interface DataValuevalue - the divider
InvalidDataException - if current value cannot be divided with
given divider.
public DataValue floor(DataValue precision)
throws InvalidDataException
All number values are rounded off with the equation:
floor(thisValue / precision) * precision
floor in interface DataValueprecision - the precision within the quantization occurs
InvalidDataException - if precision was of unacceptable typeceil(com.davisor.data.DataValue)public java.lang.String getFormat()
This default implementation returns always null.
getFormat in interface DataValueData.getType()
public DataValue interpolate(double value,
DataValue max)
throws InvalidDataException
All number values can interpolate with this simple equation:
minValue + value * (maxValue - minValue)
interpolate in interface DataValuevalue - the scalar value to be interpolatedmax - a data value representing a range's higher limit
InvalidDataException - if interpolation failsDataValue.deinterpolate(com.davisor.data.DataValue, com.davisor.data.DataValue)
public DataValue max(DataValue value)
throws InvalidDataException
If the given value is not a Number, or
if it's double value can not be resolved for any reason, a
reference to this instance is returned. Otherwise,
if the current double value can not be resolved for any reason, a
reference to the given value is returned. Otherwise,
a reference to the object with the greater double value is
returned. If the values are equal, a reference to this
instance is returned.
max in interface DataValuevalue - a data value to be compared with this data value
InvalidDataException - if the data value cannot be comparedmin(com.davisor.data.DataValue),
compareTo(java.lang.Object)
public DataValue min(DataValue value)
throws InvalidDataException
If the given value is not a Number, or
if it's double value can not be resolved for any reason, a
reference to this instance is returned. Otherwise,
if the current double value can not be resolved for any reason, a
reference to the given value is returned. Otherwise,
a reference to the object with the smaller double value is
returned. If the values are equal, a reference to this
instance is returned.
min in interface DataValuevalue - a data value to be compared with this data value
InvalidDataException - if the data value cannot be comparedmax(com.davisor.data.DataValue),
compareTo(java.lang.Object)
public DataValue mul(DataValue value)
throws InvalidDataException
mul in interface DataValuevalue - the multiplier
InvalidDataException - if current value cannot be multiplied with
given multiplier
public abstract DataValue negate()
throws InvalidDataException
negate in interface DataValueInvalidDataException - if absolute value can not be computed
public DataValue sub(DataValue value)
throws InvalidDataException
sub in interface DataValuevalue - a data value to be substracted from this data value
InvalidDataException - if value can not be
substracted.public java.lang.String toXML()
This default implementation returns the object plain string representation, as it is assumed to contain no special characters.
toXML in interface DataValuetoString()
public DataValue unit(DataValue targetValue,
double maxSteps)
throws InvalidDataException
This method measures which u=x*10^n where x belongs to (1,2,5) would fit
nicely within the range between the current value and given target
value. The resulting unit step will be a DoubleData value of
u. If the target value is missing or equals to
this value, the range is considered to be equal to the absolute
value of current value.
unit in interface DataValuetargetValue - target value to be reached (may be null)maxSteps - maximum number of steps (zero leaves the choise open)
InvalidDataException - if target value is unsuitablepublic byte byteValue()
byteValue in interface NumberValuejava.lang.NullPointerException - if number value is not setNumberType.byteValue(java.lang.String, java.text.ParsePosition)public double doubleValue()
Please note, that a missing double value may be expressed either
with a Double.NaN value, or by throwing an
appropriate exception. This method will report a missing value by
throwing a NullPointerException. An exception is
used because an unexpected Double.NaN value may be
difficult to notice, and later trace back down to it's source.
This policy is also more consistent with integer numbers that do
not even have the option to use a NaN value.
doubleValue in interface NumberValuejava.lang.NullPointerException - if number value is not setNumberType.doubleValue(java.lang.String, java.text.ParsePosition)public float floatValue()
Please note, that a missing float value may be expressed either
with a Float.NaN value, or by throwing an
appropriate exception. This method will report a missing value by
throwing a NullPointerException. An exception is
used because an unexpected Float.NaN value may be
difficult to notice, and later trace back down to it's source.
This policy is also more consistent with integer numbers that do
not even have the option to use a NaN value.
floatValue in interface NumberValuejava.lang.NullPointerException - if number value is not setNumberType.floatValue(java.lang.String, java.text.ParsePosition)public int intValue()
intValue in interface NumberValuejava.lang.NullPointerException - if number value is not setNumberType.intValue(java.lang.String, java.text.ParsePosition)public long longValue()
longValue in interface NumberValuejava.lang.NullPointerException - if number value is not setNumberType.longValue(java.lang.String, java.text.ParsePosition)public short shortValue()
shortValue in interface NumberValuejava.lang.NullPointerException - if number value is not setNumberType.shortValue(java.lang.String, java.text.ParsePosition)public java.lang.Number numberValue()
numberValue in interface NumberValue
public void setValue(byte value)
throws InvalidDataException
This implementation forwards the call to setValue(short).
setValue in interface NumberValueInvalidDataException - if the value cannot
be converted to a byte value.
public abstract void setValue(double value)
throws InvalidDataException
setValue in interface NumberValueInvalidDataException - if the value cannot
be converted to a double value.
public void setValue(float value)
throws InvalidDataException
This implementation forwards the call to setValue(double).
setValue in interface NumberValueInvalidDataException - if the value cannot
be converted to a float value.
public void setValue(int value)
throws InvalidDataException
This implementation forwards the call to setValue(long).
setValue in interface NumberValueInvalidDataException - if the value cannot
be converted to a int value.
public abstract void setValue(java.lang.Number value)
throws InvalidDataException
setValue in interface NumberValueInvalidDataException - if the value cannot
be converted
public abstract void setValue(long value)
throws InvalidDataException
setValue in interface NumberValueInvalidDataException - if the value cannot
be converted to a long value.
public void setValue(short value)
throws InvalidDataException
This implementation forwards the call to setValue(int).
setValue in interface NumberValueInvalidDataException - if the value cannot
be converted to a short value.public boolean equals(java.lang.Object o)
SimpleNumberValue data objects are equal with any Number objects that share the same double value. In particular, the type of the other object does not matter.
public int hashCode()
public java.lang.String toString()
NumberType.stringValue(Number) method.
If current number type is null, number native
formatting is used. If current value is null or an
InvalidDataException occurs during number formatting,
the exception is silently ignored, and an empty string is returned.
toString in interface DataValueNumberType.stringValue(Number)public static java.lang.String getFormat(double value)
JavaDecimalFormat pattern suitable for
displaying values of the given magnitude.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||