Package ej.microui.event.generator

## Class States

- java.lang.Object
- - ej.microui.event.EventGenerator
  - - ej.microui.event.generator.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`

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `EVENT_TYPE` | The STATE event type returned by `getEventType()`.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `States​(int[] nbValues, int[] initialValues)` | Creates a states generator.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `buildEvent​(int stateId, int value)` | Builds a MicroUI event for the given state identifier on its value.
    `int` | `getCurrentValue​(int stateId)` | Gets the current value of the given state.
    `int` | `getEventType()` | Gets the event type associated with the event generator
    `int` | `getNumberOfStates()` | Gets the number of states managed by this instance.
    `int` | `getNumberOfValues​(int stateId)` | Gets the total number of values for the given state.
    `static int` | `getStateId​(int event)` | Gets the state's identifier held by the state event.
    `static int` | `getStateValue​(int event)` | Gets the state's value held by the state event.
    `void` | `send​(int stateId, int value)` | Stores the given state value and sends a MicroUI `EVENT_TYPE` to the States's listener.

    - ### Methods inherited from class ej.microui.event.EventGenerator

      `addToSystemPool, get, get, get, getEventHandler, getId, removeFromSystemPool, sendEvent, setEventHandler`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### EVENT_TYPE

          public static final int EVENT_TYPE

      The STATE event type returned by `getEventType()`.
      See Also:
        Constant Field Values

  - ### 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]`.

    - #### getCurrentValue

          public int getCurrentValue​(int stateId)

      Gets the current value of the given state.
      Parameters:
        `stateId` - the state identifier value.
      Returns:
        a number between `0` and ``getNumberOfValues(int)`-1`.
      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

    - #### send

          public void send​(int stateId,
                           int value)

      Stores the given state value and sends a MicroUI `EVENT_TYPE` to the States's listener.
      Parameters:
        `stateId` - the state identifier value.
        `value` - the new state value
      Throws:
        `IndexOutOfBoundsException` - when `stateId` is out of `[0,`getNumberOfStates()`-1]`.
        `IndexOutOfBoundsException` - when `value` is out of `[0,`getNumberOfValues(int)`-1]`.