Class States


  • public class States
    extends EventGenerator
    A states event generator is usually associated to a group of physical devices holding a position (switch, rotary wheel encoder, ...) and allows to generate events relating to them. This class generates EVENT_TYPE events and allows to retrieve for each state its current value. Each instance can manage at most 256 states and each state can have a value between 0 and 255.
    A state has a unique identifier between 0 and getNumberOfStates()-1
    • Constructor Detail

      • States

        public States​(int[] nbValues,
                      int[] initialValues)
        Creates a states generator.
        Parameters:
        nbValues - number of values for each state.
        initialValues - initial value for each state.
        Throws:
        IllegalArgumentException - if both arrays don't have the same length.
        IndexOutOfBoundsException - if arrays length is greater than 255.
        IndexOutOfBoundsException - if nbValues[i] < 0 or nbValues[i] > 255.
        IndexOutOfBoundsException - if initialValues[i] < 0 or initialValues[i] >= nbValues[i].
    • Method Detail

      • getStateId

        public static int getStateId​(int event)
        Gets the state's identifier held by the state event.
        Parameters:
        event - the state event to decode.
        Returns:
        id between 0 and 255.
      • getStateValue

        public static int getStateValue​(int event)
        Gets the state's value held by the state event.
        Parameters:
        event - the state event to decode.
        Returns:
        value between 0 and 255.
      • getEventType

        public int getEventType()
        Description copied from class: EventGenerator
        Gets the event type associated with the event generator
        Specified by:
        getEventType in class EventGenerator
        Returns:
        the event type
      • getNumberOfValues

        public int getNumberOfValues​(int stateId)
        Gets the total number of values for the given state.
        Parameters:
        stateId - the state identifier value.
        Returns:
        the total number of values for the given state.
        Throws:
        IndexOutOfBoundsException - when stateId is out of [0,getNumberOfStates()-1].
      • getNumberOfStates

        public int getNumberOfStates()
        Gets the number of states managed by this instance.
        Returns:
        the number of states managed by this instance.
      • buildEvent

        public int buildEvent​(int stateId,
                              int value)
        Builds a MicroUI event for the given state identifier on its value.
        Parameters:
        stateId - the state identifier value.
        value - the new state value
        Returns:
        the MicroUI event