com.jstatcom.model
Class JSCNumber

java.lang.Object
  extended by com.jstatcom.model.AbstractJSCData
      extended by com.jstatcom.model.JSCNumber
All Implemented Interfaces:
JSCData

public final class JSCNumber
extends AbstractJSCData

A number representation that conforms to the JSCData interface. Numbers are stored as Double objects.

Whenever the value of this data object changes, registered JSCDataListeners are notified via a JSCDataEvent. 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.

Author:
Markus Kraetzig

Field Summary
static javolution.xml.XmlFormat<JSCNumber> JSCNumber_XML
          XML format field for (de)serialization.
 
Constructor Summary
JSCNumber(java.lang.String name)
          Creates an empty JSCNumber.
JSCNumber(java.lang.String name, double value)
          Creates a JSCNumber from value.
JSCNumber(java.lang.String name, java.lang.Double value)
          Creates a JSCNumber from value.
 
Method Summary
 void clear()
          Clears this data object.
 JSCNumber copy()
          Gets a copy of the current object.
 double doubleVal()
          Gets the stored number as a double.
 java.lang.Double getNumber()
          Gets the stored Double value.
 int intVal()
          Gets the stored number as an int.
 boolean isEmpty()
          Gets whether this is empty.
 boolean isEqual(JSCData o)
          Gets whether the values of this data object and other are logically equal.
 boolean isNaN()
          Gets whether the value equals Double.NaN.
 java.lang.String name()
          Gets the name of the data object.
 void setNumber(java.lang.Double newValue)
          Sets the value of this to newValue and fires a JSCDataEvent of type: JSCDataEventTypes.VALUE_CHANGED if !
 void setVal(double newDouble)
          Sets the value of this to newDouble.
 JSCTypes type()
          Gets the type of this JSCData object.
 java.lang.Object value()
          Gets the underlying value, which is stored as a Double.
 
Methods inherited from class com.jstatcom.model.AbstractJSCData
addJSCDataListener, display, getJSCProperty, removeJSCDataListener, removeJSCProperty, setJSCProperty, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JSCNumber_XML

public static final javolution.xml.XmlFormat<JSCNumber> JSCNumber_XML
XML format field for (de)serialization.

Constructor Detail

JSCNumber

public JSCNumber(java.lang.String name)
Creates an empty JSCNumber.

Parameters:
name - the identifier of that object
Throws:
java.lang.IllegalArgumentException - if name is not valid or if (name == null)
See Also:
JSCConstants.isValidName(java.lang.String)

JSCNumber

public JSCNumber(java.lang.String name,
                 double value)
Creates a JSCNumber from value.

Parameters:
name - the identifier of that object
value - the double to be used as value
Throws:
java.lang.IllegalArgumentException - if name is not valid or if (name == null)
See Also:
JSCConstants.isValidName(java.lang.String)

JSCNumber

public JSCNumber(java.lang.String name,
                 java.lang.Double value)
Creates a JSCNumber from value.

Parameters:
name - the identifier of that object
value - the Double to be used as value
Throws:
java.lang.IllegalArgumentException - if name is not valid or if (name == null)
See Also:
JSCConstants.isValidName(java.lang.String)
Method Detail

clear

public void clear()
Clears this data object. Fires: if it was not empty before. After calling this method isEmpty returns true.


copy

public JSCNumber copy()
Description copied from interface: JSCData
Gets a copy of the current object. Implementations of this method must fulfil the two conditions: JSCDataListeners attached 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 a double.

Returns:
the value as double
Throws:
java.lang.IllegalStateException - if object is empty

getNumber

public java.lang.Double getNumber()
Gets the stored Double value.

Returns:
a Double or null if empty

intVal

public int intVal()
Gets the stored number as an int. The following special int values are returned: Note that during this operation information is potentially lost. Only the integer part is preserved, which is different from rounding.

Returns:
the result of getNumber().intValue()
Throws:
java.lang.IllegalStateException - if object is empty

isEmpty

public boolean isEmpty()
Gets whether this is empty. This method returns true, if value returns null.

Returns:
true if empty

isEqual

public boolean isEqual(JSCData o)
Description copied from interface: JSCData
Gets whether the values of this data object and other are logically equal.

Returns:
true if considered equal according to the logic of the representation
See Also:
JSCData

isNaN

public boolean isNaN()
Gets whether the value equals Double.NaN.

Returns:
true if this represents a missing value
Throws:
java.lang.IllegalStateException - if object is empty

name

public java.lang.String name()
Description copied from interface: JSCData
Gets the name of the data object. It must fulfil the requirements for variable names defined in JSCConstants.

Returns:
the name
See Also:
JSCData

setNumber

public void setNumber(java.lang.Double newValue)
Sets the value of this to newValue and fires a JSCDataEvent of type:

Parameters:
newValue - the new value

setVal

public void setVal(double newDouble)
Sets the value of this to newDouble. Fires a JSCDataEvent of type:

Parameters:
newDouble - the new double

type

public JSCTypes type()
Gets the type of this JSCData object.

Returns:
JSCTypes.NUMBER
See Also:
JSCTypes

value

public java.lang.Object value()
Gets the underlying value, which is stored as a Double.

Returns:
the value object or null if this is empty