Class JSCVoid
- java.lang.Object
-
- com.jstatcom.model.AbstractJSCData
-
- com.jstatcom.model.JSCVoid
-
- All Implemented Interfaces:
- JSCData
public final class JSCVoid extends AbstractJSCData
An object wrapper that conforms to theJSCDatainterface. Arbitrary objects can be stored. This class is meant to store special purpose objects that are not easily generalized. It can be used to easily pass references to those objects via the symbol table.Because nothing is known about the underlying value except that it is an
Object, no special purpose methods are provided.Example:
An example usage would be to store an object that represents the state of a certain model, sayModelState. This state object could be immutable and this wrapper notifies listeners whenever a newModelStatehas been set.JSCVoidmakes it also possible to assign aSymbolfor that state object and to store it in aSymbolTable.Usage Note:
Instances can only be (de)serialized, if the stored value is itself XML serializable, see javolution37.javolution.xml.XmlFormat.Comparisons between the stored values rely on the
equalsmethod ofObject. If a logical check for equality is preferred to a pure reference check, then the class of the value object should overwriteequal(andhashCodeto keep the contract).Whenever the value of this data object changes (by setting a new object), 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<JSCVoid>JSCVoid_XMLXML format field for (de)serialization.
-
Constructor Summary
Constructors Constructor and Description JSCVoid()Creates an emptyJSCVoidwith a default name.JSCVoid(java.lang.String name)Creates an emptyJSCVoid.JSCVoid(java.lang.String name, java.lang.Object value)Creates aJSCVoidfromvalue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Clearsthisdata object.JSCVoidcopy()Gets a copy of the current object.booleanisEmpty()Gets whetherthisis empty.booleanisEqual(JSCData o)Gets whether the values of this data object andotherare logically equal.java.lang.Stringname()Gets the name of the data object.voidsetVal(java.lang.Object newValue)Sets the value of this tonewValue.JSCTypestype()Gets the type of thisJSCDataobject.java.lang.Objectvalue()Gets the underlying value, which is stored as anObject.-
Methods inherited from class com.jstatcom.model.AbstractJSCData
addJSCDataListener, display, getJSCProperty, removeJSCDataListener, removeJSCProperty, setJSCProperty, toString
-
-
-
-
Constructor Detail
-
JSCVoid
public JSCVoid(java.lang.String name)
Creates an emptyJSCVoid.- Parameters:
name- the identifier of that object- Throws:
java.lang.IllegalArgumentException- ifnameis not valid orif (name == null)- See Also:
JSCConstants.isValidName(java.lang.String)
-
JSCVoid
public JSCVoid()
Creates an emptyJSCVoidwith a default name.
-
JSCVoid
public JSCVoid(java.lang.String name, java.lang.Object value)Creates aJSCVoidfromvalue.- Parameters:
name- the identifier of that objectvalue- theObjectto 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 JSCVoid 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
-
isEmpty
public boolean isEmpty()
Gets whetherthisis empty. If this method returnstrue, thenvaluereturnsnull.- 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
-
setVal
public void setVal(java.lang.Object newValue)
Sets the value of this tonewValue. Fires aJSCDataEventof type:JSCDataEventTypes.VALUE_CHANGEDif!newValue.equals(value())JSCDataEventTypes.EMPTY_STATEifnewValue != nulland this was empty beforeJSCDataEventTypes.EMPTY_STATEifnewValue == nulland this was not empty before
- Parameters:
newValue- the new value
-
type
public JSCTypes type()
Gets the type of thisJSCDataobject.- Returns:
JSCTypes.VOID- See Also:
JSCTypes
-
value
public java.lang.Object value()
Gets the underlying value, which is stored as anObject.- Returns:
- the value object or
nullifthisis empty
-
-
DMelt 3.0 © DataMelt by jWork.ORG