com.jstatcom.model
Class JSCNumber
- java.lang.Object
-
- com.jstatcom.model.AbstractJSCData
-
- com.jstatcom.model.JSCNumber
-
- All Implemented Interfaces:
- JSCData
public final class JSCNumber extends AbstractJSCData
A number representation that conforms to theJSCDatainterface. Numbers are stored asDoubleobjects.Whenever the value of this data object changes, registered
JSCDataListenersare notified via aJSCDataEvent. If not otherwise stated, the event objects always contain the values before the change and after the change.This class is thread-safe. All access to mutable data is synchronized. All events are fired outside the synchronized blocks.
-
-
Field Summary
Fields Modifier and Type Field and Description static XmlFormat<JSCNumber>JSCNumber_XMLXML format field for (de)serialization.
-
Constructor Summary
Constructors Constructor and Description JSCNumber(java.lang.String name)Creates an emptyJSCNumber.JSCNumber(java.lang.String name, double value)Creates aJSCNumberfromvalue.JSCNumber(java.lang.String name, java.lang.Double value)Creates aJSCNumberfromvalue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Clearsthisdata object.JSCNumbercopy()Gets a copy of the current object.doubledoubleVal()Gets the stored number as adouble.java.lang.DoublegetNumber()Gets the storedDoublevalue.intintVal()Gets the stored number as anint.booleanisEmpty()Gets whetherthisis empty.booleanisEqual(JSCData o)Gets whether the values of this data object andotherare logically equal.booleanisNaN()Gets whether the value equalsDouble.NaN.java.lang.Stringname()Gets the name of the data object.voidsetNumber(java.lang.Double newValue)Sets the value of this tonewValueand fires aJSCDataEventof type:JSCDataEventTypes.VALUE_CHANGEDif!newValue.equals(getNumber())JSCDataEventTypes.EMPTY_STATEifnewValue != nulland this was empty beforeJSCDataEventTypes.EMPTY_STATEifnewValue == nulland this was not empty beforevoidsetVal(double newDouble)Sets the value of this tonewDouble.JSCTypestype()Gets the type of thisJSCDataobject.java.lang.Objectvalue()Gets the underlying value, which is stored as aDouble.-
Methods inherited from class com.jstatcom.model.AbstractJSCData
addJSCDataListener, display, getJSCProperty, removeJSCDataListener, removeJSCProperty, setJSCProperty, toString
-
-
-
-
Constructor Detail
-
JSCNumber
public JSCNumber(java.lang.String name)
Creates an emptyJSCNumber.- Parameters:
name- the identifier of that object- Throws:
java.lang.IllegalArgumentException- ifnameis not valid orif (name == null)- See Also:
JSCConstants.isValidName(java.lang.String)
-
JSCNumber
public JSCNumber(java.lang.String name, double value)Creates aJSCNumberfromvalue.- Parameters:
name- the identifier of that objectvalue- thedoubleto be used as value- Throws:
java.lang.IllegalArgumentException- ifnameis not valid orif (name == null)- See Also:
JSCConstants.isValidName(java.lang.String)
-
JSCNumber
public JSCNumber(java.lang.String name, java.lang.Double value)Creates aJSCNumberfromvalue.- Parameters:
name- the identifier of that objectvalue- theDoubleto be used as value- Throws:
java.lang.IllegalArgumentException- ifnameis not valid orif (name == null)- See Also:
JSCConstants.isValidName(java.lang.String)
-
-
Method Detail
-
clear
public void clear()
Clearsthisdata object. Fires:JSCDataEventTypes.EMPTY_STATEeventJSCDataEventTypes.VALUE_CHANGEDevent
isEmptyreturnstrue.
-
copy
public JSCNumber copy()
Description copied from interface:JSCDataGets a copy of the current object. Implementations of this method must fulfil the two conditions:a.isEqual(a.copy())- compares valuesa.getName().equals(a.copy().getName())- compares name
JSCDataListenersattached to the original object should not be copied.- Returns:
- a clonelike copy of the original object
- See Also:
JSCData
-
doubleVal
public double doubleVal()
Gets the stored number as adouble.- Returns:
- the value as
double - Throws:
java.lang.IllegalStateException- if object is empty
-
getNumber
public java.lang.Double getNumber()
Gets the storedDoublevalue.- Returns:
- a
Doubleornullif empty
-
intVal
public int intVal()
Gets the stored number as anint. The following specialintvalues are returned:- 0 if
value == Double.NaN Integer.MAX_VALUE if value == Double.POSITIVE_INFINITYInteger.MIN_VALUE if value == Double.NEGATIVE_INFINITY
- Returns:
- the result of
getNumber().intValue() - Throws:
java.lang.IllegalStateException- if object is empty
- 0 if
-
isEmpty
public boolean isEmpty()
Gets whetherthisis empty. This method returnstrue, ifvaluereturnsnull.- Returns:
trueif empty
-
isEqual
public boolean isEqual(JSCData o)
Description copied from interface:JSCDataGets whether the values of this data object andotherare logically equal.- Returns:
trueif considered equal according to the logic of the representation- See Also:
JSCData
-
isNaN
public boolean isNaN()
Gets whether the value equalsDouble.NaN.- Returns:
trueif this represents a missing value- Throws:
java.lang.IllegalStateException- if object is empty
-
name
public java.lang.String name()
Description copied from interface:JSCDataGets the name of the data object. It must fulfil the requirements for variable names defined inJSCConstants.- Returns:
- the name
- See Also:
JSCData
-
setNumber
public void setNumber(java.lang.Double newValue)
Sets the value of this tonewValueand fires aJSCDataEventof type:JSCDataEventTypes.VALUE_CHANGEDif!newValue.equals(getNumber())JSCDataEventTypes.EMPTY_STATEifnewValue != nulland this was empty beforeJSCDataEventTypes.EMPTY_STATEifnewValue == nulland this was not empty before
- Parameters:
newValue- the new value
-
setVal
public void setVal(double newDouble)
Sets the value of this tonewDouble. Fires aJSCDataEventof type:JSCDataEventTypes.VALUE_CHANGEDif the new value is not equal to the previousJSCDataEventTypes.EMPTY_STATEif this was empty before
- Parameters:
newDouble- the newdouble
-
type
public JSCTypes type()
Gets the type of thisJSCDataobject.- Returns:
JSCTypes.NUMBER- See Also:
JSCTypes
-
value
public java.lang.Object value()
Gets the underlying value, which is stored as aDouble.- Returns:
- the value object or
nullifthisis empty
-
-
DMelt 3.0 © DataMelt by jWork.ORG