Class 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 the ContextListener interface) can be registered for the context. New context types can be created by extending this class.
    • Constructor Summary

      Constructors 
      Constructor Description
      Context​(java.lang.String name, boolean active)
      Creates a context
      Context​(java.lang.String id, java.lang.String name, boolean active)
      Creates a context
    • 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 context
        active - is this context active
      • Context

        public Context​(java.lang.String name,
                       boolean active)
        Creates a context
        Parameters:
        name - the name of this context
        active - 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