Sets current state to the given state. Returns true if the current state is changed, false
otherwise.

@param state the state to be set.
@return true if the current state is changed, false otherwise.
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;
      }
    }
  }
250798
public boolean isState(Class<? extends State> state)
    {
        if (current != null)
        {
            return current.getClass().equals(state);
        }
        return false;
    }
437207
private void setState(State newState) {
        m_logger.debug("Entering state: {}", newState.toString());
        synchronized (m_stateChangeLock) {
            m_state = newState;
            m_stateChangeLock.notifyAll();
        }
    }
121450
protected function isState($state)
    {
        $current = $this->getState();

        return (is_array($state))
            ? in_array($current, $state)
            : $current == $state;
    }
864993
public void setState(String state)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "setState", state);

    this.state = state;

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "setState");
  }
849204
public static StateObj state(StateObj... states) {
        MutableStateObj mutable = mutable();
        for (StateObj state : states) {
            mutable.updateState(state);
        }
        return state(mutable.getState());
    }
1259704
public function changeState($state)
    {
        $availableStates = $this->dbObject('Status')->enumValues();
        if (in_array($state, $availableStates)) {
            $this->Status = $state;
            return true;
        } else {
            user_error(_t('Reservation.STATE_CHANGE_ERROR', 'Selected state is not available'));
            return false;
        }
    }
294194
private boolean toNextState(LifecycleState newState)
  {
    LifecycleState state;
    
    synchronized (this) {
      state = _state;
      
      if (newState.ordinal() <= state.ordinal()) {
        return false;
      }
      
      _state = newState;

      _lastChangeTime = CurrentTime.currentTime();
    }

    if (_log != null && _log.isLoggable(_lowLevel)) {
      _log.log(_lowLevel, newState + " " + _name);
    }

    notifyListeners(state, newState);

    return true;
  }
230530
public int setState(boolean state, boolean bDisplayOption, int moveMode)
    {
        double value = 0;
        if (state)
            value = 1;
        return this.setValue(value, bDisplayOption, moveMode);  // Move value to this field
    }
495672
@Override
	public void setCurrent(T stateful, State<T> current, State<T> next) throws StaleStateException {
		synchronized(stateful) {
			if (this.getCurrent(stateful).equals(current)) {
				this.setCurrent(stateful, next);
			} else {
				throw new StaleStateException();
			}
		}
	}
913815
protected void setState(FieldState state) {
        if (DEBUG)
            LOG.debug("{}:{} --> {}", _state, _field != null ? _field : _headerString != null ? _headerString : _string, state);
        _fieldState = state;
    }
758610
public void setState(PrimitiveState state) {
    if (this.state != state) {
      if (this.state != PrimitiveState.EXPIRED && this.state != PrimitiveState.CLOSED) {
        this.state = state;
        if (state == PrimitiveState.SUSPENDED) {
          if (suspendedTime == null) {
            suspendedTime = System.currentTimeMillis();
          }
        } else {
          suspendedTime = null;
        }
        changeListeners.forEach(l -> l.accept(state));
      }
    } else if (this.state == PrimitiveState.SUSPENDED) {
      if (System.currentTimeMillis() - suspendedTime > timeout) {
        setState(PrimitiveState.EXPIRED);
      }
    }
  }
50302
@Override
    public void setState(TransferState state) {
        super.setState(state);

        switch (state) {
        case Waiting:
            fireProgressEvent(ProgressEventType.TRANSFER_PREPARING_EVENT);
            break;
        case InProgress:
            if ( subTransferStarted.compareAndSet(false, true) ) {
                /* The first InProgress signal */
                fireProgressEvent(ProgressEventType.TRANSFER_STARTED_EVENT);
            }
            /* Don't need any event code update for subsequent InProgress signals */
            break;
        case Completed:
            fireProgressEvent(ProgressEventType.TRANSFER_COMPLETED_EVENT);
            break;
        case Canceled:
            fireProgressEvent(ProgressEventType.TRANSFER_CANCELED_EVENT);
            break;
        case Failed:
            fireProgressEvent(ProgressEventType.TRANSFER_FAILED_EVENT);
            break;
        default:
            break;
        }
    }
1227658
public int setState(boolean bState, boolean bDisplayOption, int iMoveMode)
    {
        int iFieldValue = (int)this.getValue();
        if (!m_bTrueIfMatch)
            bState = !bState; // Do opposite operation
        if (bState)
            iFieldValue |= (1 << m_iBitNumber);     // Set the bit
        else
            iFieldValue &= ~(1 << m_iBitNumber);    // Clear the bit
        return this.setValue(iFieldValue, bDisplayOption, iMoveMode);
    }
1077995
private boolean setState(State newState) {
        switch (newState) {
            case DEPLOYED:
                return changeState(State.DEPLOYING, State.DEPLOYED);
            case DEPLOYING:
                //can move from either UNDEPLOYED or FAILED into DEPLOYING state
                return (changeState(State.UNDEPLOYED, State.DEPLOYING) || changeState(State.FAILED, State.DEPLOYING));
            case UNDEPLOYING:
                return changeState(State.DEPLOYED, State.UNDEPLOYING);
            case UNDEPLOYED:
                return changeState(State.UNDEPLOYING, State.UNDEPLOYED);
            case FAILED:
                return changeState(State.DEPLOYING, State.FAILED);
            default:
                return false;
        }
    }
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;
                }
            }
        }
    }
1087120
public function setState($state)
    {
        if (!empty($state) && is_string($state) && ctype_print($state)) {
            $this->state = trim($state);
        }

        return $this;
    }