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.ObjectThis 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 theContextListenerinterface) 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 voidaddSensor(Sensor sensor)Relates a sensor input to the context.voidaddSensors(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.StringgetId()Gets identifier of this contextjava.lang.StringgetName()Gets name of this contextjava.util.Iterator<Sensor>getSensors()Gets sensorsbooleanisActive()Is context active?voidregisterContextListener(ContextListener listener)Registers a listener (ContextListener) for this context.voidremoveSensor(Sensor sensor)Removes a sensor from the contextvoidsetActive(boolean active)Sets context active valuevoidsetName(java.lang.String name)Sets context namevoidunregisterContextListener(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
-
-