private synchronized boolean compareAndSetState(State[] expectedStates, State update) {
    for (State expected : expectedStates) {
      if (state == expected) {
        setState(update);
        return true;
      }
    }
    return false;
  }
Atomically sets the state to <code>update</code> if and only if the state is currently one of
<code>expectedStates</code>.
@param expectedStates the expected states.
@param update         the new state.
@return true if the update succeeds, or false if the current state does not equal any of the
        <code>expectedStates</code>.
hbase-common/src/main/java/org/apache/hadoop/hbase/io/FileChangeWatcher.java