Source:
<code>protected boolean approveMoveRequest(MoveRequest request) { if (!(request.getTargetContainer() instanceof Region)) { return true; } StateMachine targetSM = StateMachineUtils.getStateMachine(request.getTargetContainer()); for (Object o : request.getElementsToMove().keySet()) { if ((o instanceof Vertex) && (((Vertex) o).eContainer() != null && <START> StateMachineUtils.getStateMachine((Vertex) <END> o) != targetSM)) { return false; } } Region targetRegion = (Region) request.getTargetContainer(); @SuppressWarnings("unchecked") List<Pseudostate> pseudostatesToMove = (List<Pseudostate>) request.getElementsToMove().keySet().stream().filter(Pseudostate.class::isInstance).map(Pseudostate.class::cast).collect(Collectors.toList()); List<Pseudostate> pseudostatesInRegion = targetRegion.getSubvertices().stream().filter(Pseudostate.class::isInstance).map(Pseudostate.class::cast).collect(Collectors.toList()); long nuInitialStatesToMove = pseudostatesToMove.stream().filter(p -> PseudostateKind.INITIAL_LITERAL == p.getKind()).count(); if (nuInitialStatesToMove > 1 || nuInitialStatesToMove == 1 && pseudostatesInRegion.stream().anyMatch(p -> PseudostateKind.INITIAL_LITERAL == p.getKind())) { return false; } List<Pseudostate> deepHistoryToMove = pseudostatesToMove.stream().filter(p -> PseudostateKind.DEEP_HISTORY_LITERAL == p.getKind()).collect(Collectors.toList()); if (deepHistoryToMove.size() > 1) { return false; } else if (deepHistoryToMove.size() == 1) { if (targetRegion.getState() == null) { return false; } if (pseudostatesInRegion.stream().anyMatch(p -> p.getKind() == PseudostateKind.DEEP_HISTORY_LITERAL)) { return false; } } if (pseudostatesToMove.stream().anyMatch(p -> p.getKind() == PseudostateKind.ENTRY_POINT_LITERAL || p.getKind() == PseudostateKind.EXIT_POINT_LITERAL)) { return false; } return true; }</code><technical_language>Vertex API a containingStateMachine() operation already</technical_language>

Target:
protected boolean approveMoveRequest(MoveRequest request) { if (!(request.getTargetContainer() instanceof Region)) { return true; } StateMachine targetSM = ((Region) request.getTargetContainer()).containingStateMachine(); for (Object o : request.getElementsToMove().keySet()) { if ((o instanceof Vertex) && (((Vertex) o).eContainer() != null && ((Vertex) o).containingStateMachine() != targetSM)) { return false; } } Region targetRegion = (Region) request.getTargetContainer(); @SuppressWarnings("unchecked") List<Pseudostate> pseudostatesToMove = (List<Pseudostate>) request.getElementsToMove().keySet().stream().filter(Pseudostate.class::isInstance).map(Pseudostate.class::cast).collect(Collectors.toList()); List<Pseudostate> pseudostatesInRegion = targetRegion.getSubvertices().stream().filter(Pseudostate.class::isInstance).map(Pseudostate.class::cast).collect(Collectors.toList()); long nuInitialStatesToMove = pseudostatesToMove.stream().filter(p -> PseudostateKind.INITIAL_LITERAL == p.getKind()).count(); if (nuInitialStatesToMove > 1 || nuInitialStatesToMove == 1 && pseudostatesInRegion.stream().anyMatch(p -> PseudostateKind.INITIAL_LITERAL == p.getKind())) { return false; } List<Pseudostate> deepHistoryToMove = pseudostatesToMove.stream().filter(p -> PseudostateKind.DEEP_HISTORY_LITERAL == p.getKind()).collect(Collectors.toList()); if (deepHistoryToMove.size() > 1) { return false; } else if (deepHistoryToMove.size() == 1) { if (targetRegion.getState() == null) { return false; } if (pseudostatesInRegion.stream().anyMatch(p -> p.getKind() == PseudostateKind.DEEP_HISTORY_LITERAL)) { return false; } } if (pseudostatesToMove.stream().anyMatch(p -> p.getKind() == PseudostateKind.ENTRY_POINT_LITERAL || p.getKind() == PseudostateKind.EXIT_POINT_LITERAL)) { return false; } return true; }