com.jstatcom.model
Class JSCMap
- java.lang.Object
-
- com.jstatcom.model.AbstractJSCData
-
- com.jstatcom.model.JSCMap
-
- All Implemented Interfaces:
- JSCData
public final class JSCMap extends AbstractJSCData
An object wrapper that conforms to theJSCDatainterface. This class acts like an ordered map where the keys are string values and the values are one ofString, String[], Integer, int[], int[][], Double, double[], double[][], Boolean, boolean[]. On read/write access all array values are copied to prevent external references to them. TheJSCMapwas inspired by the list datatype in the R statistics language. It can be used as an input and return parameter in calls the theRStatEngine.A
JSCMapis empty, if there are no keys stored.Usage Note:
Whenever the value of this data object changes (by adding, removing elements), registered
JSCDataListenersare notified via aJSCDataEvent. In case of value changes, the event objects contain an array with the keys before and after the change, but not the values itself.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<JSCMap>JSCMap_XMLXML format field for (de)serialization.
-
Constructor Summary
Constructors Constructor and Description JSCMap()Creates an emptyJSCMapwith a default name.JSCMap(java.lang.String name)Creates an emptyJSCMap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Clearsthisdata object.booleancontainsKey(java.lang.String key)Checks whetherkeyis contained.JSCMapcopy()Gets a copy of the current object.java.lang.Stringdisplay()Default implementation that gets a string representing the value stored in thisJSCDataobject.java.lang.Objectget(java.lang.String key)Gets the element belonging tokeyand returns the underying value ornullotherwise.java.util.Map<java.lang.String,java.lang.Object>getAll()Gets a deep copy of the map holding all key value pairs.booleanisEmpty()Gets whetherthisis empty.booleanisEqual(JSCData o)Checks whether both objects contain the same keys only.java.lang.Stringname()Gets the name of the data object.voidput(java.lang.String key, java.lang.Object val)Copy-on-write adds a new key value pair, wherevalmust be of one .java.lang.Objectremove(java.lang.String key)Removes the element belonging tokeyand returns the underying value.intsize()JSCTypestype()Gets the type of thisJSCDataobject.java.lang.Objectvalue()Gets the underlying value, which is stored as aMap<String, Object>.-
Methods inherited from class com.jstatcom.model.AbstractJSCData
addJSCDataListener, getJSCProperty, removeJSCDataListener, removeJSCProperty, setJSCProperty, toString
-
-
-
-
Constructor Detail
-
JSCMap
public JSCMap(java.lang.String name)
Creates an emptyJSCMap.- Parameters:
name- the identifier of that object- Throws:
java.lang.IllegalArgumentException- ifnameis not valid orif (name == null)- See Also:
JSCConstants.isValidName(java.lang.String)
-
JSCMap
public JSCMap()
Creates an emptyJSCMapwith a default name.
-
-
Method Detail
-
clear
public void clear()
Clearsthisdata object. Fires:JSCDataEventTypes.EMPTY_STATEeventJSCDataEventTypes.VALUE_CHANGEDevent
isEmptyreturnstrue.
-
copy
public JSCMap 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, thenvaluereturns an emptyMap.- Returns:
trueif empty
-
isEqual
public boolean isEqual(JSCData o)
Checks whether both objects contain the same keys only. Values are not compared.- 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
-
put
public void put(java.lang.String key, java.lang.Object val)Copy-on-write adds a new key value pair, wherevalmust be of one . Fires aJSCDataEventof type:JSCDataEventTypes.VALUE_CHANGEDif a new key is added that was not there before or if an existing key ist overwritten, no matter whether the new object is logically equivalent or notJSCDataEventTypes.EMPTY_STATEif this was empty before
- Parameters:
key- must be nonnull, otherwise arbitraryval- value, must be one ofString, String[], Integer, int[], int[][], Double, double[], double[][], Boolean, boolean[]- Throws:
java.lang.IllegalArgumentException-if (key == null)or ifvalhas a class that is not supported
-
remove
public java.lang.Object remove(java.lang.String key)
Removes the element belonging tokeyand returns the underying value. The following events are fired:JSCDataEventTypes.VALUE_CHANGEDifkeyexistsJSCDataEventTypes.EMPTY_STATEif this is empty afterwards but nonempty before calling this method
- Parameters:
key- must be nonnull, otherwise arbitrary- Returns:
- object belonging to
key, may benullif it was set tonullor ifkeydid not exist - Throws:
java.lang.IllegalArgumentException-if (key == null)
-
get
public java.lang.Object get(java.lang.String key)
Gets the element belonging tokeyand returns the underying value ornullotherwise.- Parameters:
key- must be nonnull, otherwise arbitrary- Returns:
- object belonging to
key, may benullif it was set tonullor ifkeydoes not exist - Throws:
java.lang.IllegalArgumentException-if (key == null)
-
getAll
public java.util.Map<java.lang.String,java.lang.Object> getAll()
Gets a deep copy of the map holding all key value pairs.- Returns:
- copied map with copied values
-
containsKey
public boolean containsKey(java.lang.String key)
Checks whetherkeyis contained.- Parameters:
key- to check for- Returns:
trueif contained,falseotherwise- Throws:
java.lang.IllegalArgumentException-if (key == null)
-
size
public int size()
-
type
public JSCTypes type()
Gets the type of thisJSCDataobject.- Returns:
JSCTypes.MAP- See Also:
JSCTypes
-
value
public java.lang.Object value()
Gets the underlying value, which is stored as aMap<String, Object>.- Returns:
- the value object or an empty Map if
thisis empty
-
display
public java.lang.String display()
Description copied from class:AbstractJSCDataDefault implementation that gets a string representing the value stored in thisJSCDataobject.- Specified by:
displayin interfaceJSCData- Overrides:
displayin classAbstractJSCData- Returns:
- "{}" if
isEmpty == true, otherwisevalue().toString()
-
-
DMelt 3.0 © DataMelt by jWork.ORG