Class Symbol
- java.lang.Object
-
- com.jstatcom.model.Symbol
-
- All Implemented Interfaces:
- JSCDataListener, java.lang.Comparable
public class Symbol extends java.lang.Object implements JSCDataListener, java.lang.Comparable
TheSymbolclass represents a variable with a certain type and name. After initialization it is only possible to store references toJSCDataobjects oftype. Two symbols are considered equal if their names are equal, independent of the case.SymbolListenercan savely useSymbolobjects to obtain notification about changes in the underlyingJSCDatawithin the SwingEventDispatchingThread. This is not ensured if they register themselves as listeners directly toJSCDataobjects.This class is thread-save. All access to mutable data is synchronized.
Subclasses might add new accessor methods for newly declared
JSCDatatypes. The main functionality of a symbol should not be changed, therefore all methods are declaredfinal.
-
-
Field Summary
Fields Modifier and Type Field and Description java.lang.StringnameIdentifier of this symbol.java.lang.StringNAMEUpper case identifier of this symbol.static XmlFormat<Symbol>Symbol_XMLXML format field for (de)serialization.JSCTypestypeType of this symbol.
-
Constructor Summary
Constructors Constructor and Description Symbol(JSCData data)Creates aSymbolwithdata.getNamea reference todata.Symbol(JSCTypeDef def)Creates aSymbolwith an empty object of the given type.Symbol(java.lang.String name, JSCData data)Creates aSymbolwithnameand a reference todata.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddSymbolListener(SymbolListener evtListener)Convenience method that adds a listener that is notified when changes of typeVALUE_CHANGEDoccur in this object.voidaddSymbolListener(SymbolListener evtListener, SymbolEventTypes evtType)Adds a listener that is notified when changes of typeevtTypeoccur in this object.voidclear()Clears the underlyingJSCDataobject.intcompareTo(java.lang.Object obj)Compares twoSymbolobjects by their uppercase names.static voidcopySymbol(Symbol source, Symbol target)Moves data and listeners from one symbol to the other.java.lang.Stringdisplay()Displays the underlyingJSCDataobject.booleanequals(java.lang.Object obj)Returnstrueifobjis aSymboland has the same name as this, without regarding the case.java.lang.StringgetDescription()Gets the description of this symbol.JSCDatagetJSCData()Gets a reference to the underlying data object.JSCDategetJSCDate()Gets the data as an instance ofJSCDate.JSCDRangegetJSCDRange()Gets the data as an instance ofJSCDRange.JSCIntgetJSCInt()Gets the data as an instance ofJSCInt.JSCNArraygetJSCNArray()Gets the data as an instance ofJSCNArray.JSCNumbergetJSCNumber()Gets the data as an instance ofJSCNumber.JSCSArraygetJSCSArray()Gets the data as an instance ofJSCSArray.JSCStringgetJSCString()Gets the data as an instance ofJSCString.JSCVoidgetJSCVoid()Gets the data as an instance ofJSCVoid.java.util.ListgetListenersForType(SymbolEventTypes evtType)Gets a list with all registered listeners forevtType.inthashCode()Generates a hash code for the receiver.booleanisEmpty()Gets whether the underlyingJSCDataobject is empty.voidremoveAllSymbolListeners()Removes allSymbolListenerobjects from this symbol.voidremoveSymbolListener(SymbolListener evtListener)RemovesevtListenerfrom all listener lists.voidsetDescription(java.lang.String newDescription)Sets the description for this symbol.voidsetJSCData(JSCData newData)Sets the reference of this symbol to a new data object.java.lang.StringtoString()Returns a string that represents the value of this object.voidvalueChanged(JSCDataEvent evt)Transformsevtto the respectiveSymbolEventand dispatches it to theSymbolListeners.
-
-
-
Field Detail
-
name
public final java.lang.String name
Identifier of this symbol.
-
NAME
public final java.lang.String NAME
Upper case identifier of this symbol.
-
type
public final JSCTypes type
Type of this symbol.
-
-
Constructor Detail
-
Symbol
public Symbol(JSCData data)
Creates aSymbolwithdata.getNamea reference todata. The type of thisSymbolis set todata.type.- Parameters:
data- theJSCDataobject for thisSymbol- Throws:
java.lang.IllegalArgumentException-if (data == null)
-
Symbol
public Symbol(java.lang.String name, JSCData data)Creates aSymbolwithnameand a reference todata. The type of thisSymbolis set todata.type.- Parameters:
name- the identifier of the symbol, must satisfy conventions for variable names defined inJSCConstantsdata- theJSCDataobject for thisSymbol- Throws:
java.lang.IllegalArgumentException-if (name == null || data == null)or ifnameis not valid- See Also:
JSCConstants.isValidName(java.lang.String)
-
Symbol
public Symbol(JSCTypeDef def)
Creates aSymbolwith an empty object of the given type.- Parameters:
def- the type definition- Throws:
java.lang.NullPointerException-if (def == null)- See Also:
JSCConstants.isValidName(java.lang.String)
-
-
Method Detail
-
addSymbolListener
public final void addSymbolListener(SymbolListener evtListener)
Convenience method that adds a listener that is notified when changes of typeVALUE_CHANGEDoccur in this object. All other events that are fired by this object are not dispatched toevtListener. This is most common forSymbolListeners.- Parameters:
evtListener- the listener object that gets notified when an event of typeevtTypegets fired- Throws:
java.lang.IllegalArgumentException-if (evtListener == null)
-
addSymbolListener
public final void addSymbolListener(SymbolListener evtListener, SymbolEventTypes evtType)
Adds a listener that is notified when changes of typeevtTypeoccur in this object. All other events that are fired by this object are not dispatched toevtListener.- Parameters:
evtListener- the listener object that gets notified when an event of typeevtTypegets firedevtType- the type of event thatevtListenerwants to listen to- Throws:
java.lang.IllegalArgumentException-if (evtListener == null || evtType == null)
-
clear
public final void clear()
Clears the underlyingJSCDataobject. This fires aEMPTY_STATEandVAL_CHANGEDevent, if the data was not empty before.
-
display
public final java.lang.String display()
Displays the underlyingJSCDataobject.
-
compareTo
public final int compareTo(java.lang.Object obj)
Compares twoSymbolobjects by their uppercase names.- Specified by:
compareToin interfacejava.lang.Comparable- Parameters:
obj- the symbol to be compared, must anotherSymbol- Returns:
- 0 if equal, < 0 if this smaller, > 0 if this is greater
- Throws:
java.lang.IllegalArgumentException-if (!(obj instanceof Symbol))
-
equals
public final boolean equals(java.lang.Object obj)
Returnstrueifobjis aSymboland has the same name as this, without regarding the case. This is to ensure that there is only oneSymbolof a given name in aSymbolTable.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare with- Returns:
trueif these object are equal,falseotherwise.
-
getDescription
public final java.lang.String getDescription()
Gets the description of this symbol.- Returns:
- the descriptive string or
""if no description has been set
-
getJSCData
public final JSCData getJSCData()
Gets a reference to the underlying data object.Usage note:
The returned data is a reference to the underlyingJSCDataobject only until a new data object has been set to this symbol. It should be used read only. Changes that should not affect this symbol must be made on a copy of the returned object.- Returns:
JSCDataobject of typetype
-
getJSCDate
public final JSCDate getJSCDate()
Gets the data as an instance ofJSCDate.Usage note:
The returned data is a reference to the underlyingJSCDataobject only until a new data object has been set to this symbol. It should be used read only. Changes that should not affect this symbol must be made on a copy of the returned object.- Returns:
- a
JSCDate - Throws:
java.lang.RuntimeException-if (type != JSCTypes.DATE)
-
getJSCDRange
public final JSCDRange getJSCDRange()
Gets the data as an instance ofJSCDRange.Usage note:
The returned data is a reference to the underlyingJSCDataobject only until a new data object has been set to this symbol. It should be used read only. Changes that should not affect this symbol must be made on a copy of the returned object.- Returns:
- a
JSCDRange - Throws:
java.lang.RuntimeException-if (type != JSCTypes.DRANGE)
-
getJSCNArray
public final JSCNArray getJSCNArray()
Gets the data as an instance ofJSCNArray. If the data is an instance ofJSCNumberorJSCInta new 1x1JSCNArraywith the single element is returned or an emptyJSCNArray.Usage note:
The returned data is a reference to the underlyingJSCDataobject only until a new data object has been set to this symbol. It should be used read only. Changes that should not affect this symbol must be made on a copy of the returned object.- Returns:
- a
JSCNArray - Throws:
java.lang.RuntimeException-if (type != JSCTypes.NARRAY && type != JSCTypes.INT && type != JSCTypes.NUMBER)
-
getJSCNumber
public final JSCNumber getJSCNumber()
Gets the data as an instance ofJSCNumber. If the data is of typeINTa newJSCNumberwith the element is returned.Usage note:
The returned data is a reference to the underlyingJSCDataobject only until a new data object has been set to this symbol. It should be used read only. Changes that should not affect this symbol must be made on a copy of the returned object.- Returns:
- a
JSCNumber - Throws:
java.lang.RuntimeException-if (type != JSCTypes.NUMBER && type != JSCTypes.INT)
-
getJSCInt
public final JSCInt getJSCInt()
Gets the data as an instance ofJSCInt.Usage note:
The returned data is a reference to the underlyingJSCDataobject only until a new data object has been set to this symbol. It should be used read only. Changes that should not affect this symbol must be made on a copy of the returned object.- Returns:
- a
JSCInt - Throws:
java.lang.RuntimeException-if (type != JSCTypes.INT)
-
getJSCSArray
public final JSCSArray getJSCSArray()
Gets the data as an instance ofJSCSArray. If the data is an instance ofJSCString, a new 1x1JSCSArraywith the single element is returned or an emptyJSCSArray.Usage note:
The returned data is a reference to the underlyingJSCDataobject only until a new data object has been set to this symbol. It should be used read only. Changes that should not affect this symbol must be made on a copy of the returned object.- Returns:
- a
JSCSArray - Throws:
java.lang.RuntimeException-if (type != JSCTypes.SARRAY && type != JSCTypes.STRING)
-
getJSCString
public final JSCString getJSCString()
Gets the data as an instance ofJSCString. If the data is an instance ofJSCSArray, aJSCStringwith the 0:0 element is returned or an emptyJSCString.Usage note:
The returned data is a reference to the underlyingJSCDataobject only until a new data object has been set to this symbol. It should be used read only. Changes that should not affect this symbol must be made on a copy of the returned object.- Returns:
- a
JSCString - Throws:
java.lang.RuntimeException-if (type != JSCTypes.STRING && type != JSCTypes.SARRAY)
-
getJSCVoid
public final JSCVoid getJSCVoid()
Gets the data as an instance ofJSCVoid.Usage note:
The returned data is a reference to the underlyingJSCDataobject only until a new data object has been set to this symbol. It should be used read only. Changes that should not affect this symbol must be made on a copy of the returned object.- Returns:
- a
JSCVoid - Throws:
java.lang.RuntimeException-if (type != JSCTypes.VOID)
-
hashCode
public final int hashCode()
Generates a hash code for the receiver. This method is supported primarily for hash tables, such as those provided in java.util.- Overrides:
hashCodein classjava.lang.Object- Returns:
- an integer hash code for the receiver
-
isEmpty
public final boolean isEmpty()
Gets whether the underlyingJSCDataobject is empty.- Returns:
trueif empty,falseotherwise
-
removeAllSymbolListeners
public void removeAllSymbolListeners()
Removes allSymbolListenerobjects from this symbol.
-
removeSymbolListener
public final void removeSymbolListener(SymbolListener evtListener)
RemovesevtListenerfrom all listener lists.- Parameters:
evtListener- the listener to remove
-
getListenersForType
public java.util.List getListenersForType(SymbolEventTypes evtType)
Gets a list with all registered listeners forevtType.- Parameters:
evtType- the event type- Returns:
- a copy of the respective list or an initialized list instance
with size == 0 if no listeners are registered for
evtType
-
setDescription
public final void setDescription(java.lang.String newDescription)
Sets the description for this symbol.- Parameters:
newDescription- a descriptive string- Throws:
java.lang.IllegalArgumentException- if description contains / * or * /
-
setJSCData
public final void setJSCData(JSCData newData)
Sets the reference of this symbol to a new data object.SymbolListenerobjects are notified via the events:SymbolEventTypes.REF_CHANGEDSymbolEventTypes.VAL_CHANGEDonlyif (!newData.isEqual(oldData))
REF_CHANGEDevent is necessary for tables that listen to changes in a certainSymbol. They need to change their model data tonewData, otherwise they would continue to listen to changes in the old data object.This symbol is removed from the listener list of the previous data object.
- Parameters:
newData- reference to the new data object, which must be of typetype- Throws:
java.lang.IllegalArgumentException-if (newData == null)orif (newData.type() != type)
-
toString
public final java.lang.String toString()
Returns a string that represents the value of this object.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the receiver
-
valueChanged
public final void valueChanged(JSCDataEvent evt)
Transformsevtto the respectiveSymbolEventand dispatches it to theSymbolListeners.- Specified by:
valueChangedin interfaceJSCDataListener- Parameters:
evt- the data event
-
copySymbol
public static void copySymbol(Symbol source, Symbol target)
Moves data and listeners from one symbol to the other. The data is ONLY copied, if the source is not empty. The source will be cleared and all listeners will be removed. Nothing happensif (source == target).- Parameters:
source- to copy fromtarget- to copy to- Throws:
java.lang.IllegalArgumentException- if an argument isnull
-
-
DMelt 3.0 © DataMelt by jWork.ORG