com.jstatcom.model
Class JSCMap

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

public final class JSCMap
extends AbstractJSCData

An object wrapper that conforms to the JSCData interface. This class acts like an ordered map where the keys are string values and the values are one of String, String[], Integer, int[], int[][], Double, double[], double[][], Boolean, boolean[]. On read/write access all array values are copied to prevent external references to them. The JSCMap was inspired by the list datatype in the R statistics language. It can be used as an input and return parameter in calls the the RStatEngine.

A JSCMap is empty, if there are no keys stored.

Usage Note:

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

Author:
Markus Kraetzig

Field Summary
static javolution.xml.XmlFormat<JSCMap> JSCMap_XML
          XML format field for (de)serialization.
 
Constructor Summary
JSCMap()
          Creates an empty JSCMap with a default name.
JSCMap(java.lang.String name)
          Creates an empty JSCMap.
 
Method Summary
 void clear()
          Clears this data object.
 boolean containsKey(java.lang.String key)
          Checks whether key is contained.
 JSCMap copy()
          Gets a copy of the current object.
 java.lang.String display()
          Default implementation that gets a string representing the value stored in this JSCData object.
 java.lang.Object get(java.lang.String key)
          Gets the element belonging to key and returns the underying value or null otherwise.
 java.util.Map<java.lang.String,java.lang.Object> getAll()
          Gets a deep copy of the map holding all key value pairs.
 boolean isEmpty()
          Gets whether this is empty.
 boolean isEqual(JSCData o)
          Checks whether both objects contain the same keys only.
 java.lang.String name()
          Gets the name of the data object.
 void put(java.lang.String key, java.lang.Object val)
          Copy-on-write adds a new key value pair, where val must be of one .
 java.lang.Object remove(java.lang.String key)
          Removes the element belonging to key and returns the underying value.
 int size()
           
 JSCTypes type()
          Gets the type of this JSCData object.
 java.lang.Object value()
          Gets the underlying value, which is stored as a Map<String, Object>.
 
Methods inherited from class com.jstatcom.model.AbstractJSCData
addJSCDataListener, getJSCProperty, removeJSCDataListener, removeJSCProperty, setJSCProperty, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JSCMap_XML

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

Constructor Detail

JSCMap

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

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)

JSCMap

public JSCMap()
Creates an empty JSCMap with a default name.

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 JSCMap 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

isEmpty

public boolean isEmpty()
Gets whether this is empty. If this method returns true, then value returns an empty Map.

Returns:
true if empty

isEqual

public boolean isEqual(JSCData o)
Checks whether both objects contain the same keys only. Values are not compared.

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

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

put

public void put(java.lang.String key,
                java.lang.Object val)
Copy-on-write adds a new key value pair, where val must be of one . Fires a JSCDataEvent of type:

Parameters:
key - must be non null, otherwise arbitrary
val - value, must be one of String, String[], Integer, int[], int[][], Double, double[], double[][], Boolean, boolean[]
Throws:
java.lang.IllegalArgumentException - if (key == null) or if val has a class that is not supported

remove

public java.lang.Object remove(java.lang.String key)
Removes the element belonging to key and returns the underying value. The following events are fired:

Parameters:
key - must be non null, otherwise arbitrary
Returns:
object belonging to key, may be null if it was set to null or if key did not exist
Throws:
java.lang.IllegalArgumentException - if (key == null)

get

public java.lang.Object get(java.lang.String key)
Gets the element belonging to key and returns the underying value or null otherwise.

Parameters:
key - must be non null, otherwise arbitrary
Returns:
object belonging to key, may be null if it was set to null or if key does 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 whether key is contained.

Parameters:
key - to check for
Returns:
true if contained, false otherwise
Throws:
java.lang.IllegalArgumentException - if (key == null)

size

public int size()

type

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

Returns:
JSCTypes.MAP
See Also:
JSCTypes

value

public java.lang.Object value()
Gets the underlying value, which is stored as a Map<String, Object>.

Returns:
the value object or an empty Map if this is empty

display

public java.lang.String display()
Description copied from class: AbstractJSCData
Default implementation that gets a string representing the value stored in this JSCData object.

Specified by:
display in interface JSCData
Overrides:
display in class AbstractJSCData
Returns:
"{}" if isEmpty == true, otherwise value().toString()