@SuppressWarnings("unchecked") private boolean isStartingNode(final Node node) { return null == node.getInEdges() || startNodePredicate.test(node); } }
@Override public boolean startNodeTraversal(final Node node) { // Process incoming edges into the node as well. final List<? extends Edge> inEdges = node.getInEdges(); if (null != inEdges) { inEdges.stream().forEach(this::process); } return true; }
public static boolean isDockedNode(final Node<?, ? extends Edge> element) { return Objects.nonNull(element.getInEdges()) ? element.getInEdges() .stream() .anyMatch(edge -> edge.getContent() instanceof Dock) : false; }
@SuppressWarnings("unchecked") private Node<View, Edge> getDockSourceNode(final Node<View, Edge> node) { return (Node<View, Edge>) node .getInEdges() .stream() .filter(this::isDockEdge) .map(Edge::getSourceNode) .findFirst() .orElse(null); }
protected Predicate<Node<?, Edge>> newStartNodePredicate() { return node -> !node.getInEdges().stream() .filter(ViewTraverseProcessorImpl::isViewEdge) .filter(ViewTraverseProcessorImpl::isNotCyclicEdge) .findAny() .isPresent(); }
private boolean isStartNode(final Node<?, Edge> node) { final boolean hasConnectors = node.getInEdges().stream() .filter(e -> e.getContent() instanceof View) .findAny() .isPresent(); final boolean hasDocks = node.getInEdges().stream() .filter(e -> e.getContent() instanceof Dock) .findAny() .isPresent(); return !hasConnectors && !hasDocks; }
private static void appendViewConnectorIds(final Set<String> result, final Node<?, Edge> node) { Stream.concat(node.getInEdges().stream(), node.getOutEdges().stream()) .filter(e -> e.getContent() instanceof ViewConnector) .forEach(e -> result.add(e.getUUID())); }
public Stream<EdgeT> edges() { return nodes() .flatMap(e -> Stream.concat( e.getInEdges().stream(), e.getOutEdges().stream())) .distinct() .filter(e -> (isViewConnector(e))); }
private void updateConnectionEdges(AbstractCanvasHandler context, Node<? extends Definition<?>, Edge> candidate) { // Update incoming edges for the new shape Optional.ofNullable(candidate.getInEdges()) .ifPresent(edges -> edges.stream() .filter(this::isViewEdge) .forEach(edge -> updateConnections(context, edge, edge.getSourceNode(), candidate))); // Update outgoing edges for the new shape. Optional.ofNullable(candidate.getOutEdges()) .ifPresent(edges -> edges.stream() .filter(this::isViewEdge) .forEach(edge -> updateConnections(context, edge, candidate, edge.getTargetNode()))); }
private Optional<Node> getParent() { List<Edge> inEdges = candidate.getInEdges(); if (null != inEdges && !inEdges.isEmpty()) { for (final Edge edge : inEdges) { if (isChildEdge(edge) || isDockEdge(edge)) { return Optional.ofNullable(edge.getSourceNode()); } } } return Optional.empty(); }
@SuppressWarnings("unchecked") private Set<Edge> asEdgeSet(Iterable nodes) { Set<Edge> oldEdges = new HashSet<>(); nodes.forEach(n -> { oldEdges.addAll(((Node<?, Edge>) n).getOutEdges()); oldEdges.addAll(((Node<?, Edge>) n).getInEdges()); }); return oldEdges; }
private Set<Edge> asEdgeSet(Iterable nodes) { Set<Edge> oldEdges = new HashSet<>(); nodes.forEach(n -> { oldEdges.addAll(((Node<?, Edge>) n).getOutEdges()); oldEdges.addAll(((Node<?, Edge>) n).getInEdges()); }); return oldEdges; }
public static Node mockNode(String uuid) { Node node = mock(Node.class); when(node.getUUID()).thenReturn(uuid); when(node.asNode()).thenReturn(node); when(node.getInEdges()).thenReturn(new LinkedList()); when(node.getOutEdges()).thenReturn(new LinkedList()); return node; }
private ViewConnector getInEdgeViewConnector(Node node) { List<Edge> edges = node.getInEdges(); if (edges != null) { for (Edge edge : edges) { if (edge.getContent() instanceof ViewConnector) { return (ViewConnector) edge.getContent(); } } } return null; }
@SuppressWarnings("unchecked") private void connectNodes(final Node source, final Node target, final Edge connector) { source.getOutEdges().add(connector); target.getInEdges().add(connector); connector.setSourceNode(source); connector.setTargetNode(target); } }
@SuppressWarnings("unchecked") private void createEdge(String uuid, Node sourceNode, Node targetNode) { final Edge<View<SequenceFlow>, Node> edge = typedFactoryManager.newEdge(uuid, SequenceFlow.class); edge.setSourceNode(sourceNode); edge.setTargetNode(targetNode); sourceNode.getOutEdges().add(edge); targetNode.getInEdges().add(edge); ViewConnector<SequenceFlow> content = (ViewConnector<SequenceFlow>) edge.getContent(); content.setSourceConnection(MagnetConnection.Builder.forElement(sourceNode)); content.setTargetConnection(MagnetConnection.Builder.forElement(targetNode)); }
@Test @SuppressWarnings("unchecked") public void testAccepts() { when(ruleExtension.getTypeArguments()).thenReturn(new Class[]{ParentDefinition.class}); when(containmentContext.getCandidate()).thenReturn(nodeA); when(containmentContext.getParent()).thenReturn(parentNode); nodeA.getInEdges().add(edge); when(edge.getContent()).thenReturn(viewConnector); assertTrue(tested.accepts(ruleExtension, containmentContext)); }
@SuppressWarnings("unchecked") T getEndNodeById(Diagram<Graph, Metadata> diagram, String id, boolean hasIncomeEdge) { Node<? extends Definition, ?> node = diagram.getGraph().getNode(id); assertNotNull(node); int incomeEdges = hasIncomeEdge ? 2 : 1; assertEquals(incomeEdges, node.getInEdges().size()); assertEquals(0, node.getOutEdges().size()); return getEndEventType().cast(node.getContent().getDefinition()); }
@SuppressWarnings("unchecked") T getThrowingIntermediateNodeById(Diagram<Graph, Metadata> diagram, String id, boolean hasIncomeEdge) { Node<? extends Definition, ?> node = diagram.getGraph().getNode(id); assertNotNull(node); int incomeEdges = hasIncomeEdge ? 2 : 1; assertEquals(incomeEdges, node.getInEdges().size()); assertEquals(1, node.getOutEdges().size()); return getThrowingIntermediateEventType().cast(node.getContent().getDefinition()); }
@SuppressWarnings("unchecked") T getCatchingIntermediateNodeById(Diagram<Graph, Metadata> diagram, String id, boolean hasIncomeEdge, boolean hasOutgoingEdge) { Node<? extends Definition, ?> node = diagram.getGraph().getNode(id); assertNotNull(node); int incomeEdges = hasIncomeEdge ? getDefaultAmountOfIncomdeEdges() + 1 : getDefaultAmountOfIncomdeEdges(); assertEquals(incomeEdges, node.getInEdges().size()); int outgoingEdges = hasOutgoingEdge ? 1 : 0; assertEquals(outgoingEdges, node.getOutEdges().size()); return getCatchingIntermediateEventType().cast(node.getContent().getDefinition()); }