com.jstatcom.model
Class JSCInt
- java.lang.Object
-
- com.jstatcom.model.AbstractJSCData
-
- com.jstatcom.model.JSCInt
-
- All Implemented Interfaces:
- JSCData
public final class JSCInt extends AbstractJSCData
An integer representation that conforms to theJSCDatainterface. Values are stored asIntegerobjects.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<JSCInt>JSCInt_XMLXML format field for (de)serialization.
-
Constructor Summary
Constructors Constructor and Description JSCInt(java.lang.String name)Creates an emptyJSCInt.JSCInt(java.lang.String name, boolean value)Creates aJSCIntfrom a boolean value.JSCInt(java.lang.String name, int value)Creates aJSCIntfrom an integer value.JSCInt(java.lang.String name, java.lang.Integer value)Creates aJSCIntfromvalue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Clearsthisdata object.JSCIntcopy()Gets a copy of the current object.doubledoubleVal()Gets the stored integer as adouble.java.lang.IntegergetInt()Gets the storedIntegervalue.intintVal()Gets the stored integer.booleanisEmpty()Gets whetherthisis empty.booleanisEqual(JSCData o)Gets whether the values of this data object andotherare logically equal.booleanisNonZero()Gets whether the stored value is not zero.java.lang.Stringname()Gets the name of the data object.voidsetInt(java.lang.Integer 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(int newInt)Sets the value of this tonewInt.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
-
JSCInt
public JSCInt(java.lang.String name)
Creates an emptyJSCInt.- Parameters:
name- the identifier of that object- Throws:
java.lang.IllegalArgumentException- ifnameis not valid orif (name == null)- See Also:
JSCConstants.isValidName(java.lang.String)
-
JSCInt
public JSCInt(java.lang.String name, int value)Creates aJSCIntfrom an integer value.- Parameters:
name- the identifier of that objectvalue- theintto be used as value- Throws:
java.lang.IllegalArgumentException- ifnameis not valid orif (name == null)- See Also:
JSCConstants.isValidName(java.lang.String)
-
JSCInt
public JSCInt(java.lang.String name, boolean value)Creates aJSCIntfrom a boolean value.- Parameters:
name- the identifier of that objectvalue- iftrue, set integer value to 1, iffalseset integer value to 0- Throws:
java.lang.IllegalArgumentException- ifnameis not valid orif (name == null)- See Also:
JSCConstants.isValidName(java.lang.String)
-
JSCInt
public JSCInt(java.lang.String name, java.lang.Integer value)Creates aJSCIntfromvalue.- Parameters:
name- the identifier of that objectvalue- theIntegerto 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 JSCInt 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 integer as adouble.- Returns:
- the value as
double - Throws:
java.lang.IllegalStateException- if object is empty
-
getInt
public java.lang.Integer getInt()
Gets the storedIntegervalue.- Returns:
- a
Integerornullif empty
-
intVal
public int intVal()
Gets the stored integer.- Returns:
- the int values
- Throws:
java.lang.IllegalStateException- if object is empty
-
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
-
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
-
setInt
public void setInt(java.lang.Integer 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(int newInt)
Sets the value of this tonewInt. Fires aJSCDataEventof type:JSCDataEventTypes.VALUE_CHANGEDif the new value is not equal to the previousJSCDataEventTypes.EMPTY_STATEif this was empty before
- Parameters:
newInt- the newint
-
type
public JSCTypes type()
Gets the type of thisJSCDataobject.- Returns:
JSCTypes.INT- 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
-
isNonZero
public boolean isNonZero()
Gets whether the stored value is not zero.- Returns:
trueif not equal to zero,falseotherwise- Throws:
java.lang.IllegalStateException- if object is empty
-
-
DMelt 3.0 © DataMelt by jWork.ORG