/**
   * Build internal lists buttonDrag, keyDrags, etc from BehaviourMap(?) and InputMap(?). The
   * internal lists only contain entries for Behaviours that can be actually triggered with the
   * current InputMap, grouped by Behaviour type, such that hopefully lookup from the event handlers
   * is fast.
   */
  private void updateInternalMaps() {
    buttonDrags.clear();
    keyDrags.clear();
    buttonClicks.clear();
    keyClicks.clear();

    for (final Entry<InputTrigger, Set<String>> entry : inputMap.getAllBindings().entrySet()) {
      final InputTrigger buttons = entry.getKey();
      final Set<String> behaviourKeys = entry.getValue();
      if (behaviourKeys == null) continue;

      for (final String behaviourKey : behaviourKeys) {
        final Behaviour behaviour = behaviourMap.get(behaviourKey);
        if (behaviour == null) continue;

        if (behaviour instanceof DragBehaviour) {
          final BehaviourEntry<DragBehaviour> dragEntry =
              new BehaviourEntry<>(buttons, (DragBehaviour) behaviour);
          if (buttons.isKeyStroke()) keyDrags.add(dragEntry);
          else buttonDrags.add(dragEntry);
        } else if (behaviour instanceof ClickBehaviour) {
          final BehaviourEntry<ClickBehaviour> clickEntry =
              new BehaviourEntry<>(buttons, (ClickBehaviour) behaviour);
          if (buttons.isKeyStroke()) keyClicks.add(clickEntry);
          else buttonClicks.add(clickEntry);
        } else if (behaviour instanceof ScrollBehaviour) {
          final BehaviourEntry<ScrollBehaviour> scrollEntry =
              new BehaviourEntry<>(buttons, (ScrollBehaviour) behaviour);
          scrolls.add(scrollEntry);
        }
      }
    }
  }
 /**
  * Make sure that the internal behaviour lists are up to date. For this, we keep track the
  * modification count of {@link #inputMap} and {@link #behaviourMap}. If expected mod counts are
  * not matched, call {@link #updateInternalMaps()} to rebuild the internal behaviour lists.
  */
 private synchronized void update() {
   final int imc = inputMap.modCount();
   final int bmc = behaviourMap.modCount();
   if (imc != inputMapExpectedModCount || bmc != behaviourMapExpectedModCount) {
     inputMapExpectedModCount = imc;
     behaviourMapExpectedModCount = bmc;
     updateInternalMaps();
   }
 }
 public void setInputMap(final InputTriggerMap inputMap) {
   this.inputMap = inputMap;
   inputMapExpectedModCount = inputMap.modCount() - 1;
 }