Class Context
- java.lang.Object
-
- eu.h2020.helios_social.core.context.Context
-
- Direct Known Subclasses:
ActivityContext
,ContextAnd
,ContextNot
,ContextOr
,LocationContext
,TimeContext
,WifiContext
public class Context extends java.lang.Object
This is the base class for HELIOS contexts. This class provides base methods for context implementations. A context includes a type, a state (active or inactive) and possible several attributes that are used to define and detect the context. Values of context attributes may be determined explicitly (e.g. a given static value) or implicitly (e.g. by an external context source, sensor value). To listen the changes in the active value of a context, context listeners (see theContextListener
interface) can be registered for the context. New context types can be created by extending this class.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSensor(Sensor sensor)
Relates a sensor input to the context.void
addSensors(java.util.List<Sensor> sensors)
Relates a list of sensors to the context.java.util.Iterator<ContextListener>
getContextListeners()
Gets all the listeners related to this contextjava.lang.String
getId()
Gets identifier of this contextjava.lang.String
getName()
Gets name of this contextjava.util.Iterator<Sensor>
getSensors()
Gets sensorsboolean
isActive()
Is context active?void
registerContextListener(ContextListener listener)
Registers a listener (ContextListener) for this context.void
removeSensor(Sensor sensor)
Removes a sensor from the contextvoid
setActive(boolean active)
Sets context active valuevoid
setName(java.lang.String name)
Sets context namevoid
unregisterContextListener(ContextListener listener)
Unregisters a ContextListener.
-
-
-
Constructor Detail
-
Context
public Context(java.lang.String id, java.lang.String name, boolean active)
Creates a context- Parameters:
id
- the identifier of this context.name
- the name of this contextactive
- is this context active
-
Context
public Context(java.lang.String name, boolean active)
Creates a context- Parameters:
name
- the name of this contextactive
- is this context active
-
-
Method Detail
-
getId
public final java.lang.String getId()
Gets identifier of this context- Returns:
- the identifier of this context
-
isActive
public boolean isActive()
Is context active?- Returns:
- active the active value(boolean)
-
getName
public java.lang.String getName()
Gets name of this context- Returns:
- name the name of this context
-
setName
public void setName(java.lang.String name)
Sets context name- Parameters:
name
- the name of this context
-
setActive
public void setActive(boolean active)
Sets context active value- Parameters:
active
- the active value
-
addSensor
public void addSensor(@NonNull Sensor sensor)
Relates a sensor input to the context.- Parameters:
sensor
- the sensor
-
addSensors
public void addSensors(java.util.List<Sensor> sensors)
Relates a list of sensors to the context.- Parameters:
sensors
- the sensor list
-
removeSensor
public void removeSensor(@NonNull Sensor sensor)
Removes a sensor from the context- Parameters:
sensor
- the sensor
-
getSensors
public java.util.Iterator<Sensor> getSensors()
Gets sensors- Returns:
- the sensors
-
registerContextListener
public void registerContextListener(ContextListener listener)
Registers a listener (ContextListener) for this context. The ContextListener will then receive changes in the context active value.- Parameters:
listener
- the ContextListener
-
unregisterContextListener
public void unregisterContextListener(ContextListener listener)
Unregisters a ContextListener.- Parameters:
listener
- the ContextListener
-
getContextListeners
public java.util.Iterator<ContextListener> getContextListeners()
Gets all the listeners related to this context- Returns:
- the listeners
-
-