org.instantreality.InstantIO
Class Data

java.lang.Object
  extended by org.instantreality.InstantIO.Data

public final class Data
extends java.lang.Object

Helper class that combines a data value with a timestamp.

This class is used when writing values into InSlots or when reading values from OutSlots to transfer timestamps between different software components. The timestamp is a long value that specifies the number of milliseconds since midnight January 1., 1970 UTC.

The following code snippet demonstrates how to use the Data class when pushing boolean values with the current system time into OutSlots:

 OutSlot outSlot = ...;
 Boolean value = new Boolean(true);
 long timeStamp = System.currentTimeMillis();
 Data data = new Data(value, timeStamp);
 outSlot.push(data);
 

The following code snippet demonstrates how to use the Data class when receiving boolean values from InSlots:

 InSlot inSlot = ...;
 Data data = inSlot.popData();
 Boolean value = (Boolean) data.getValue();
 long timeStamp = data.getTimeStamp();
 

Author:
Patrick Dähne
See Also:
OutSlot, InSlot

Constructor Summary
Data(java.lang.Object value)
          Creates a new Data object that contains a given value and whose timestamp is set to the current system time.
Data(java.lang.Object value, long timeStamp)
          Creates a new Data object that contains a given value and whose timestamp is set to a given timestamp.
 
Method Summary
 long getTimeStamp()
          Returns the timestamp.
 java.lang.Object getValue()
          Returns the data value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Data

public Data(java.lang.Object value)
Creates a new Data object that contains a given value and whose timestamp is set to the current system time.

The following example demonstrates how to create a new Data object with a boolean value and the current system time, and push it into an OutSlot:

 OutSlot outSlot = ...;
 Data data = new Data(new Boolean(true));
 outSlot.push(data);
 

Parameters:
value - The value that is put into the Data object.

Data

public Data(java.lang.Object value,
            long timeStamp)
Creates a new Data object that contains a given value and whose timestamp is set to a given timestamp.

The following example demonstrates how to create a new Data object with a boolean value and the current system time, and push it into an OutSlot:

 OutSlot outSlot = ...;
 Data data = new Data(new Boolean(true), System.currentTimeMillis());
 outSlot.push(data);
 

Parameters:
value - The value that is put into the Data object.
timeStamp - The timestamp of the data value. This is a long value that specifies the number of milliseconds since midnight January 1., 1970 UTC.
Method Detail

getValue

public java.lang.Object getValue()
Returns the data value.

The following example demonstrates how to receive a boolean value from an OutSlot and print the value and its timestamp to the console:

 InSlot inSlot = ...;
 Data data = inSlot.popData();
 Boolean value = (Boolean) data.getValue();
 long timeStamp = data.getTimeStamp();
 System.out.println("Value = " + value + ", Timestamp = " + timeStamp);
 

Returns:
The data value contained in the Data object.

getTimeStamp

public long getTimeStamp()
Returns the timestamp.
 InSlot inSlot = ...;
 Data data = inSlot.popData();
 Boolean value = (Boolean) data.getValue();
 long timeStamp = data.getTimeStamp();
 System.out.println("Value = " + value + ", Timestamp = " + timeStamp);
 

Returns:
Returns the timestamp of the value contained in the data object. This is a long value that specifies the number of milliseconds since midnight January 1., 1970 UTC.