de.cau.cs.kieler.sim.kiem
Class JSONSignalValues

java.lang.Object
  extended by de.cau.cs.kieler.sim.kiem.JSONSignalValues

public final class JSONSignalValues
extends Object

The Class JSONSignalValues. This is an implementation of a CONVENTION for representing signal values in JSON format. This convention is used to explicitly denote the presents/absents of pure and valued signals.

Signals in JSON format should contain not just a value but a JSONSignalValue. That is they contain a JSONObject as their value, where at least one parameter is called present and this parameter is of type boolean, indicating the presents or absents of a signal.

Examples:
Valued signal a, present, with an integer value of 10:
a:{present:true, value:10}
Valued signal a, absent, with a string value of "hello signal":
a:{present:false, value:"hello signal"}
Pure signal b, present
b:{present:true}
Pure signal b, absent
b:{present:absent}

Rating proposed yellow
(2009-01-15)

Field Summary
static String PRESENT_KEY
          The present key of this *CONVENTION*.
static String VALUE_KEY
          The value key of this *CONVENTION*.
 
Method Summary
static Object getSignalValue(Object signalValue)
          Gets the value of a SignalValue.
static boolean isPresent(Object signalValue)
          Checks whether the signal of this SignalValue is present.
static boolean isSignalValue(Object signalValue)
          Checks if this Object is a SignalValue.
static JSONObject newValue(boolean present)
          Create a new SignalValue for a pure signal, containing a presentKey only.
static JSONObject newValue(Object value, boolean present)
          Create a new SignalValue for a valued signal, containing a presentKey and a valueKey.
static void setPresent(JSONObject signalValue, boolean isPresent)
          Sets the presents of a signaled value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRESENT_KEY

public static final String PRESENT_KEY
The present key of this *CONVENTION*.

See Also:
Constant Field Values

VALUE_KEY

public static final String VALUE_KEY
The value key of this *CONVENTION*.

See Also:
Constant Field Values
Method Detail

setPresent

public static void setPresent(JSONObject signalValue,
                              boolean isPresent)
                       throws JSONException
Sets the presents of a signaled value. If this is not a SignalValue or at least a JSONObject where the presentKey can be inserted, then an exception is thrown.

Parameters:
signalValue - the JSONObject representing the signal value
isPresent - a boolean indicating whether the signal is present
Throws:
JSONException - a JSONException

isSignalValue

public static boolean isSignalValue(Object signalValue)
                             throws JSONException
Checks if this Object is a SignalValue. It is a SignalValue iff it is a JSONObject and has a presentKey.

Parameters:
signalValue - the Object to be checked
Returns:
true, if it is a SignalValue
Throws:
JSONException - a JSONException

getSignalValue

public static Object getSignalValue(Object signalValue)
                             throws JSONException
Gets the value of a SignalValue. This method returns null if it is a SignalValue of a pure signal or it is no SignalValue at all.

Parameters:
signalValue - the SignalValue (or Object if that is unclear)
Returns:
the value of the SignalValue or null
Throws:
JSONException - a JSONException

isPresent

public static boolean isPresent(Object signalValue)
                         throws JSONException
Checks whether the signal of this SignalValue is present. If it is no SignalValue at all, then the default value is absent.

Parameters:
signalValue - the SignalValue
Returns:
true, if signal is present
Throws:
JSONException - a JSONException

newValue

public static JSONObject newValue(Object value,
                                  boolean present)
                           throws JSONException
Create a new SignalValue for a valued signal, containing a presentKey and a valueKey.

Parameters:
value - the value of the signal
present - true if the signal is present
Returns:
the SignalValue as a JSONObject
Throws:
JSONException - a JSONException

newValue

public static JSONObject newValue(boolean present)
                           throws JSONException
Create a new SignalValue for a pure signal, containing a presentKey only.

Parameters:
present - true if the signal is present
Returns:
the SignalValue as a JSONObject
Throws:
JSONException - a JSONException