Sets the state if the current state satisfies the specified predicate.
If the new state does not {@code .equals()} the current state, listeners and waiters will be notified.

@return true if the state is set
504226
public boolean setIf(T newState, Predicate<T> predicate)
    {
        checkState(!Thread.holdsLock(lock), "Can not set state while holding the lock");
        requireNonNull(newState, "newState is null");

        while (true) {
            // check if the current state passes the predicate
            T currentState = get();

            // change to same state is not a change, and does not notify the notify listeners
            if (currentState.equals(newState)) {
                return false;
            }

            // do not call predicate while holding the lock
            if (!predicate.test(currentState)) {
                return false;
            }

            // if state did not change while, checking the predicate, apply the new state
            if (compareAndSet(currentState, newState)) {
                return true;
            }
        }
    }
979789
public function setStateToVote () : bool
    {
        if ( $this->_State === 1 ) :
                if (empty($this->_Candidates)) :
                    throw new CondorcetException(20);
                endif;

                $this->_State = 2;

        // If voting continues after a first set of results
        elseif ( $this->_State > 2 ) :
                $this->cleanupResult();
        endif;

        return true;
    }
337898
public boolean set(State state) {
    while (true) {
      InternalState internalState = currentInternalState.get();
      checkState(!internalState.isRead, "State was already read, cannot set state.");
      if (state == internalState.state) {
        return false;
      } else {
        if (!currentInternalState.compareAndSet(
            internalState,
            state == State.ENABLED
                ? InternalState.ENABLED_NOT_READ
                : InternalState.DISABLED_NOT_READ)) {
          // The state was changed between the moment the internalState was read and this point.
          // Some conditions may be not correct, reset at the beginning and recheck all conditions.
          continue;
        }
        return true;
      }
    }
  }
744444
private void setState(final RunnableProcessState newState) {
    if (!this.state.isLegal(newState)) {
      throw new IllegalStateException("Transition from " + this.state + " to " + newState + " is illegal");
    }
    this.state = newState;
  }
1022922
public boolean hasChanged() {
        Object currentValue = getValue();
        return value == null || currentValue == null ? value != currentValue : !value.equals(currentValue);
    }
977236
public boolean isSet() {
        if (isUsageMode()) {
            return true;
        }
        if (getJobFile() != null) {
            return true;
        }
        if (getListType() != null) {
            return true;
        }
        return false;
    }
179009
public synchronized boolean addStateChange(ConnectionState newConnectionState)
    {
        if ( state.get() != State.STARTED )
        {
            return false;
        }

        ConnectionState previousState = currentConnectionState;
        if ( previousState == newConnectionState )
        {
            return false;
        }
        currentConnectionState = newConnectionState;

        ConnectionState localState = newConnectionState;
        boolean isNegativeMessage = ((newConnectionState == ConnectionState.LOST) || (newConnectionState == ConnectionState.SUSPENDED) || (newConnectionState == ConnectionState.READ_ONLY));
        if ( !isNegativeMessage && initialConnectMessageSent.compareAndSet(false, true) )
        {
            localState = ConnectionState.CONNECTED;
        }

        postState(localState);

        return true;
    }
999950
private void setState(State state) {
    if (this.state != state) {
      this.state = state;
      log.debug("State changed: {}", state);
    }
  }
773629
public static <T> Predicate<T> always() {
        return new Predicate<T>() {
            @Override
            public boolean test( T input ) {
                return true;
            }
        };
    }
395528
private static ThreadState state()
    {
        ThreadState state=(ThreadState)__states.get();
        if (state==null)
        {
            state=new ThreadState();
            __states.set(state);
        }
        return state;
    }
1208107
public boolean inContentState() {
        return _state.ordinal() >= State.CONTENT.ordinal() && _state.ordinal() < State.END.ordinal();
    }
1156629
public synchronized int setStatus(int iStatus)
    {
        m_cachedInfo.setStatus(iStatus);
        int iThisIndex = m_model.indexOf(this);
        if (iThisIndex != -1)
            m_model.fireTableRowsUpdated(iThisIndex, iThisIndex);
        return this.getStatus();
    }
461477
public boolean isForUpdate() {
        mLock.lock();
        try {
            return (mClosed || mActive == null) ? false : mActive.isForUpdate();
        } finally {
            mLock.unlock();
        }
    }
1265482
private boolean checkIngestState() throws IOException {
    if (currentIngestState == StandbyIngestState.INGESTING_EDITS) {
      String msg = "";
      if (ingest == null) {
        msg = "Standby: Ingest instantiation failed, the state is "
            + currentIngestState + ", but the ingest is null";
      }
      if (currentSegmentTxId != ingest.getStartTxId()) {
        msg = "Standby: Ingest instantiation failed, trying to instantiate ingest for txid: "
            + currentSegmentTxId
            + ", but there is ingest for txid: "
            + ingest.getStartTxId();
      }
      if (currentIngestState == StandbyIngestState.NOT_INGESTING
          && ingest.isRunning()) {
        msg = "Standby: Ingest instantiation failed, the state is "
            + currentIngestState + " but the ingest is running";
      }
      if (!msg.isEmpty()) {
        LOG.warn(msg);
        throw new IOException(msg);
      }
      return true;
    }
    return false;
  }
142629
public boolean getState()
    {
        if (this.getData() == null)
            return m_bTrueIfNull;
        int fieldValue = (int)this.getValue();
        boolean returnValue = false;
        if ((fieldValue & (1 << m_iBitNumber)) != 0)
            returnValue = true;
        if (m_bTrueIfMatch)
            return returnValue;
        else
            return !returnValue;
    }
1144209
boolean awaitState(final InternalState expected) {
        synchronized (this) {
            final InternalState initialRequired = this.requiredState;
            for(;;) {
                final InternalState required = this.requiredState;
                // Stop in case the server failed to reach the state
                if(required == InternalState.FAILED) {
                    return false;
                // Stop in case the required state changed
                } else if (initialRequired != required) {
                    return false;
                }
                final InternalState current = this.internalState;
                if(expected == current) {
                    return true;
                }
                try {
                    wait();
                } catch(InterruptedException e) {
                    Thread.currentThread().interrupt();
                    return false;
                }
            }
        }
    }
449020
public final Collection<State> acceptStates() {
	if(acceptStates == null) {
	    final Collection<State> states = this.states();
	    acceptStates = 
		DSUtil.filterColl(_acceptStates(),
				  new Predicate<State>() {
				      public boolean check(State state) {
					  return states.contains(state);
				      }
				  },
				  new LinkedHashSet<State>());
	}
	return acceptStates;
    }