Check transitions duplicates.

An transition from a state should exist once

@param TransitionChain $transitionChain Transition chain

@return $this Self object

@throws InconsistentTransitionConfigurationException Duplicated pair of
state-transition
761483
private function checkTransitionDuplicates(TransitionChain $transitionChain)
    {
        $states = [];

        /**
         * @var Transition $transition
         */
        foreach ($transitionChain->getTransitions() as $transition) {
            $startingStateName = $transition->getStart()->getName();
            $transitionName = $transition->getName();

            if (isset($states[$startingStateName])) {
                if (isset($states[$startingStateName][$transitionName])) {
                    throw new InconsistentTransitionConfigurationException(
                        $startingStateName,
                        $transitionName
                    );
                }
            } else {
                $states[$startingStateName] = [];
            }

            $states[$startingStateName][$transitionName] = true;
        }

        return $this;
    }
478414
public function duplicate()
    {
        if (false === $this->is_duplicated) {
            $this->_duplicate();
            $this->is_duplicated = true;
            $this->node = parent::getNode();
        }
        return $this;
    }
145856
public function canTransition($subject, $transitionName, $name = null)
    {
        return $this->workflowRegistry->get($subject, $name)->can($subject, $transitionName);
    }
815207
protected function findTransition(StateInterface $sourceState, StateInterface $targetState, $eventName = null, ConditionInterface $condition = null)
    {
        $conditionName = $condition ? $condition->getName() : null;
        /* @var $transition TransitionInterface */
        foreach ($sourceState->getTransitions() as $transition) {
            $hasSameTargetState = ($transition->getTargetState() === $targetState);
            $hasSameCondition = ($transition->getConditionName() == $conditionName);
            $hasSameEvent = ($transition->getEventName() == $eventName);
            if ($hasSameTargetState && $hasSameCondition && $hasSameEvent) {
                return $transition;
            }
        }
    }
621054
def _check_transition_validity(self, check_transition):
        
        valid, message = super(BarrierConcurrencyState, self)._check_transition_validity(check_transition)
        if not valid:
            return False, message

        # Only the following transitions are allowed in barrier concurrency states:
        # - Transitions from the decider state to the parent state\n"
        # - Transitions from not-decider states to the decider state\n"
        # - Transitions from not_decider states from aborted/preempted outcomes to the
        #   aborted/preempted outcome of the parent

        from_state_id = check_transition.from_state
        to_state_id = check_transition.to_state
        from_outcome_id = check_transition.from_outcome
        to_outcome_id = check_transition.to_outcome

        if from_state_id == UNIQUE_DECIDER_STATE_ID:
            if to_state_id != self.state_id:
                return False, "Transition from the decider state must go to the parent state"
        else:
            if to_state_id != UNIQUE_DECIDER_STATE_ID:
                if from_outcome_id not in [-2, -1] or to_outcome_id not in [-2, -1]:
                    return False, "Transition from this state must go to the decider state. The only exception are " \
                                  "transition from aborted/preempted to the parent aborted/preempted outcomes"

        return True, message
803113
def initialize_copy(orig)
      super
      @transitions = @transitions.collect { |transition| transition.clone }
      @guards      = @guards.dup
      @unless      = @unless.dup
      @options     = {}
      orig.options.each_pair { |name, setting| @options[name] = setting.is_a?(Hash) || setting.is_a?(Array) ? setting.dup : setting }
    end
1250765
protected function createTransition(TransitionInterface $sourceTransition)
    {
        $targetStateName = $sourceTransition->getTargetState()->getName();
        $targetState = $this->findOrCreateState($targetStateName);
        $this->mergeMetadata($sourceTransition->getTargetState(), $targetState);
        $eventName = $sourceTransition->getEventName();

        $condition = $this->createCondition($sourceTransition);
        
        $transition = new Transition($targetState, $eventName, $condition);
        if ($sourceTransition instanceof WeightedInterface) {
            $transition->setWeight($sourceTransition->getWeight());
        }

        return $transition;
    }
749039
private function transition(TransitionalStateInterface $fromState, EventInterface $event)
    {
        if ($fromState instanceof StateActionInterface) {
            $exitEvent = $fromState->getExitEvent();
            if ($exitEvent !== null) {
                if ($this->eventDispatcher !== null) {
                    $this->eventDispatcher->dispatch(StateMachineEvents::EVENT_EXIT, new StateMachineEvent($this, $fromState, $exitEvent));
                }

                $this->runAction($exitEvent);
            }
        }

        $transition = $this->getTransition($fromState, $event);
        $transition->setToken($fromState->getToken());
        $this->previousState = $fromState;
        $this->currentState = null;
        if ($this->eventDispatcher !== null) {
            $this->eventDispatcher->dispatch(StateMachineEvents::EVENT_TRANSITION, new StateMachineEvent($this, null, $event, $transition));
        }
        $this->runAction($event, $transition);
        $transition->getToState()->setToken($transition->getToken());
        $toState = $this->stateCollection->getCurrentState();
        $this->currentState = $toState;
        $this->transitionLog[] = $this->createTransitionLogEntry($transition);

        if ($toState instanceof StateActionInterface) {
            $entryEvent = $toState->getEntryEvent();
            if ($entryEvent !== null) {
                if ($this->eventDispatcher !== null) {
                    $this->eventDispatcher->dispatch(StateMachineEvents::EVENT_ENTRY, new StateMachineEvent($this, $toState, $entryEvent));
                }

                $this->runAction($entryEvent);
            }
        }
    }
200469
def check_transition_id(self, transition_id):
        
        if transition_id is not None:
            if transition_id in self._transitions.keys():
                raise AttributeError("The transition id %s already exists. Cannot add transition!", transition_id)
        else:
            transition_id = generate_transition_id()
            while transition_id in self._transitions.keys():
                transition_id = generate_transition_id()
        return transition_id
1210404
public function duplicates($callback = null, $strict = false)
    {
        $items = $this->map($this->valueRetriever($callback));

        $uniqueItems = $items->unique(null, $strict);

        $compare = $this->duplicateComparator($strict);

        $duplicates = new static;

        foreach ($items as $key => $value) {
            if ($uniqueItems->isNotEmpty() && $compare($value, $uniqueItems->first())) {
                $uniqueItems->shift();
            } else {
                $duplicates[$key] = $value;
            }
        }

        return $duplicates;
    }
1369735
public function removeTransition(Transition $transition)
    {
        if ($this->transitions->contains($transition)) {
            $this->transitions->removeElement($transition);
            $transition->setTask(null);
        }

        return $this;
    }
423725
public function getNextTransitions()
    {
        /* @var $transition \Sokil\State\Transition */

        $nextTransitions = [];

        // get all transitions
        $currentStateName = $this->getCurrentState()->getName();
        if (empty($this->transitions[$currentStateName])) {
            throw new \Exception('No transitions found for passed state');
        }

        // get accepted transitions
        foreach ($this->transitions[$currentStateName] as $transitionName => $transition) {
            if (!$transition->isAcceptable()) {
                continue;
            }

            $nextTransitions[$transitionName] = $transition;
        }

        return $nextTransitions;
    }
429935
protected function getTransitionLabel(StateInterface $state, TransitionInterface $transition)
    {
        $labelParts = array();
        $eventName = $transition->getEventName();
        if ($eventName) {
            $labelParts[] = 'E: ' . $eventName;
            $event = $state->getEvent($eventName);
            $observerName = $this->convertObserverToString($event);
            if ($observerName) {
                $labelParts[] = 'C: ' . $observerName;
            }
        }
        $conditionName = $transition->getConditionName();
        if ($conditionName) {
            $labelParts[] = 'IF: ' . $conditionName;
        }
        if ($transition instanceof WeightedInterface) {
            $labelParts[] = 'W: ' . $transition->getWeight();
        }

        $label = implode(PHP_EOL, $labelParts);

        return $label;
    }
1243534
public static function pushTransitionsOnStack($stack, $transitions)
    {
        $returnValue = array();

        
    	foreach ($transitions as $t){
    		array_push($stack, $t);
    	}
    	
    	$returnValue = $stack;
        

        return (array) $returnValue;
    }
978414
protected boolean isAsyncTransitionInstance(TransitionInstance transitionInstance) {
    String executionId = transitionInstance.getExecutionId();
    ExecutionEntity execution = Context.getCommandContext().getExecutionManager().findExecutionById(executionId);
    for (JobEntity job : execution.getJobs()) {
      if (AsyncContinuationJobHandler.TYPE.equals(job.getJobHandlerType())) {
        return true;
      }
    }

    return false;
  }
1128915
public void transition(CopycatServer.State state) {
    checkThread();

    if (this.state != null && state == this.state.type()) {
      return;
    }

    LOGGER.info("{} - Transitioning to {}", cluster.member().address(), state);

    // Close the old state.
    try {
      this.state.close().get();
    } catch (InterruptedException | ExecutionException e) {
      throw new IllegalStateException("failed to close Raft state", e);
    }

    // Force state transitions to occur synchronously in order to prevent race conditions.
    try {
      this.state = createState(state);
      this.state.open().get();
    } catch (InterruptedException | ExecutionException e) {
      throw new IllegalStateException("failed to initialize Raft state", e);
    }

    stateChangeListeners.forEach(l -> l.accept(this.state.type()));
  }
25635
public function addTransition(Transition $transition)
    {
        if (!$this->transitions->contains($transition)) {
            $this->transitions->add($transition);
            $transition->setTask($this);
        }

        return $this;
    }