Class TimeContext
- java.lang.Object
-
- eu.h2020.helios_social.core.context.Context
-
- eu.h2020.helios_social.core.context.ext.TimeContext
-
- All Implemented Interfaces:
SensorValueListener
public class TimeContext extends Context implements SensorValueListener
This class is a time-based context defined by given start and end times of the time scale when the context is active. The class extends the base class Context.
In order to receive the time updates, this context should be registered as a SensorValueListener for the sensor providing the time updates. For example, time updates from the TimeSensor {@see eu.h2020.helios_social.core.sensor.ext.TimeSensor}:TimeContext timecontext1 = new TimeContext("timecontext1", startTime, endTime); TimeSensor timeSensor = new TimeSensor(1000); // update interval = 1000 milliseconds timeSensor.registerValueListener(timecontext1); timeSensor.startUpdates();
The context active value is updated using the setActive method. The current value of the context can always be checked using the isActive method of the context. If the application needs to track the changes in the active value of the context then the application should implement also the ContextListener interface {@see eu.h2020.helios_social.core.context.ContextListener} and register the context for the listener.
-
-
Field Summary
Fields Modifier and Type Field Description static int
REPEAT_DAILY
static int
REPEAT_NONE
static int
REPEAT_WEEKDAYS
static int
REPEAT_WEEKENDS
static int
REPEAT_WEEKLY
-
Constructor Summary
Constructors Constructor Description TimeContext(java.lang.String name, long startTime, long endTime)
Creates a TimeContextTimeContext(java.lang.String id, java.lang.String name, long startTime, long endTime)
Creates a TimeContextTimeContext(java.lang.String id, java.lang.String name, long startTime, long endTime, int repeat)
Creates a TimeContext
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getEndTime()
Returns end timeint
getRepeat()
Returns repeat interval value (REPEAT_NONE, REPEAT_DAILY, REPEAT_WEEKLYlong
getStartTime()
Returns start timevoid
receiveValue(java.lang.Object value)
Receive updated time values from the time sensor.-
Methods inherited from class eu.h2020.helios_social.core.context.Context
addSensor, addSensors, getContextListeners, getId, getName, getSensors, isActive, registerContextListener, removeSensor, setActive, setName, unregisterContextListener
-
-
-
-
Field Detail
-
REPEAT_NONE
public static final int REPEAT_NONE
- See Also:
- Constant Field Values
-
REPEAT_DAILY
public static final int REPEAT_DAILY
- See Also:
- Constant Field Values
-
REPEAT_WEEKLY
public static final int REPEAT_WEEKLY
- See Also:
- Constant Field Values
-
REPEAT_WEEKDAYS
public static final int REPEAT_WEEKDAYS
- See Also:
- Constant Field Values
-
REPEAT_WEEKENDS
public static final int REPEAT_WEEKENDS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TimeContext
public TimeContext(java.lang.String name, long startTime, long endTime)
Creates a TimeContext- Parameters:
name
- the name of the contextstartTime
- the start moment of the time interval (milliseconds since epoch)endTime
- the end moment of the time interval (milliseconds since epoch)
-
TimeContext
public TimeContext(java.lang.String id, java.lang.String name, long startTime, long endTime)
Creates a TimeContext- Parameters:
id
- the identifier of the contextname
- the name of the contextstartTime
- the start moment of the time interval (milliseconds since epoch)endTime
- the end moment of the time interval (milliseconds since epoch)
-
TimeContext
public TimeContext(java.lang.String id, java.lang.String name, long startTime, long endTime, int repeat)
Creates a TimeContext- Parameters:
id
- the identifier of the contextname
- the name of the contextstartTime
- the start moment of the time interval (milliseconds since epoch)endTime
- the end moment of the time interval (milliseconds since epoch)repeat
- the repeat interval (REPEAT_NONE,REPEAT_DAILY or REPEAT_WEEKLY)
-
-
Method Detail
-
getStartTime
public long getStartTime()
Returns start time- Returns:
- the start time (milliseconds since epoch)
-
getEndTime
public long getEndTime()
Returns end time- Returns:
- the end time (milliseconds since epoch)
-
getRepeat
public int getRepeat()
Returns repeat interval value (REPEAT_NONE, REPEAT_DAILY, REPEAT_WEEKLY- Returns:
- the repeat interval
-
receiveValue
public void receiveValue(java.lang.Object value)
Receive updated time values from the time sensor. For example, from the TimeSensor {@see eu.h2020.helios_social.core.sensor.ext.TimeSensor}. In order to receive the time updates, this context should be registered as a SensorValueListener for the sensor.- Specified by:
receiveValue
in interfaceSensorValueListener
- Parameters:
value
- the received value
-
-