protected void setState(int state) {
   if (!Util.arrayContainsi(availableStates, state))
     throw new IllegalArgumentException("state " + state + " is not enabled");
   this.state = state;
 }