@SuppressWarnings("unchecked") @Test public void testComputeCardinalityState() { String canvasRootUUID = "rootUUID"; Node rootNode = new NodeImpl<>(canvasRootUUID); Node node1 = new NodeImpl<>("node1"); Node node2 = new NodeImpl<>("node2"); Node node3 = new NodeImpl<>("node3"); Metadata metadata = new MetadataImpl(); metadata.setCanvasRootUUID(canvasRootUUID); Graph graph = new GraphImpl<>("graph1", new GraphNodeStoreImpl()); Diagram diagram = new DiagramImpl("diagram1", graph, metadata); assertEquals(GraphUtils.CardinalityCountState.EMPTY, computeCardinalityState(diagram)); graph.addNode(rootNode); assertEquals(GraphUtils.CardinalityCountState.EMPTY, computeCardinalityState(diagram)); graph.addNode(node1); assertEquals(GraphUtils.CardinalityCountState.SINGLE_NODE, computeCardinalityState(diagram)); graph.addNode(node2); assertEquals(GraphUtils.CardinalityCountState.MULTIPLE_NODES, computeCardinalityState(diagram)); graph.clear(); assertEquals(GraphUtils.CardinalityCountState.EMPTY, computeCardinalityState(diagram)); graph.addNode(node1); assertEquals(GraphUtils.CardinalityCountState.SINGLE_NODE, computeCardinalityState(diagram)); graph.addNode(rootNode); assertEquals(GraphUtils.CardinalityCountState.SINGLE_NODE, computeCardinalityState(diagram)); graph.addNode(node2); assertEquals(GraphUtils.CardinalityCountState.MULTIPLE_NODES, computeCardinalityState(diagram)); graph.clear(); assertEquals(GraphUtils.CardinalityCountState.EMPTY, computeCardinalityState(diagram)); graph.addNode(node1); assertEquals(GraphUtils.CardinalityCountState.SINGLE_NODE, computeCardinalityState(diagram)); graph.addNode(node2); assertEquals(GraphUtils.CardinalityCountState.MULTIPLE_NODES, computeCardinalityState(diagram)); graph.addNode(node3); assertEquals(GraphUtils.CardinalityCountState.MULTIPLE_NODES, computeCardinalityState(diagram)); }
public static CardinalityCountState computeCardinalityState(final Diagram diagram) { final String rootUUID = diagram.getMetadata().getCanvasRootUUID(); final Graph graph = diagram.getGraph(); final Iterator nodes = graph.nodes().iterator(); final Node firstElement = nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; final Node secondElement = null != firstElement && nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; final Node thirdElement = null != secondElement && nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; if (null != thirdElement) { return CardinalityCountState.MULTIPLE_NODES; } if (null != secondElement && secondElement.getUUID().equals(rootUUID)) { return CardinalityCountState.SINGLE_NODE; } if (null != firstElement && firstElement.getUUID().equals(rootUUID)) { return null != secondElement ? CardinalityCountState.SINGLE_NODE : CardinalityCountState.EMPTY; } if (null != firstElement && null != secondElement) { return CardinalityCountState.MULTIPLE_NODES; } return null != firstElement ? CardinalityCountState.SINGLE_NODE : CardinalityCountState.EMPTY; }
GraphUtils { public static CardinalityCountState computeCardinalityState(final Diagram diagram) { final String rootUUID = diagram.getMetadata().getCanvasRootUUID(); final Graph graph = diagram.getGraph(); final Iterator nodes = graph.nodes().iterator(); final Node firstElement = nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; final Node secondElement = null != firstElement && nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; final Node thirdElement = null != secondElement && nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; if (null != thirdElement) { return CardinalityCountState.MULTIPLE_NODES; } if (null != secondElement && secondElement.getUUID().equals(rootUUID)) { return CardinalityCountState.SINGLE_NODE; } if (null != firstElement && firstElement.getUUID().equals(rootUUID)) { return null != secondElement ? CardinalityCountState.SINGLE_NODE : CardinalityCountState.EMPTY; } if (null != firstElement && null != secondElement) { return CardinalityCountState.MULTIPLE_NODES; } return null != firstElement ? CardinalityCountState.SINGLE_NODE : CardinalityCountState.EMPTY; } }
GraphUtils { public static CardinalityCountState computeCardinalityState(final Diagram diagram) { final String rootUUID = diagram.getMetadata().getCanvasRootUUID(); final Graph graph = diagram.getGraph(); final Iterator nodes = graph.nodes().iterator(); final Node firstElement = nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; final Node secondElement = null != firstElement && nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; final Node thirdElement = null != secondElement && nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; if (null != thirdElement) { return CardinalityCountState.MULTIPLE_NODES; } if (null != secondElement && secondElement.getUUID().equals(rootUUID)) { return CardinalityCountState.SINGLE_NODE; } if (null != firstElement && firstElement.getUUID().equals(rootUUID)) { return null != secondElement ? CardinalityCountState.SINGLE_NODE : CardinalityCountState.EMPTY; } if (null != firstElement && null != secondElement) { return CardinalityCountState.MULTIPLE_NODES; } return null != firstElement ? CardinalityCountState.SINGLE_NODE : CardinalityCountState.EMPTY; }  }
GraphUtils { public static CardinalityCountState computeCardinalityState(final Diagram diagram) { final String rootUUID = diagram.getMetadata().getCanvasRootUUID(); final Graph graph = diagram.getGraph(); final Iterator nodes = graph.nodes().iterator(); final Node firstElement = nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; final Node secondElement = null != firstElement && nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; final Node thirdElement = null != secondElement && nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; if (null != thirdElement) { return CardinalityCountState.MULTIPLE_NODES; } if (null != secondElement && secondElement.getUUID().equals(rootUUID)) { return CardinalityCountState.SINGLE_NODE; } if (null != firstElement && firstElement.getUUID().equals(rootUUID)) { return null != secondElement ? CardinalityCountState.SINGLE_NODE : CardinalityCountState.EMPTY; } if (null != firstElement && null != secondElement) { return CardinalityCountState.MULTIPLE_NODES; } return null != firstElement ? CardinalityCountState.SINGLE_NODE : CardinalityCountState.EMPTY; }  static int countEdges(final DefinitionManager definitionManager,
                                 final String edgeId,
                                 final Collection<? extends Edge> edges); static Map<String, Integer> getLabelsCount(final Graph<?, ? extends Node> target,
                                                      final Set<String> roleFilter); @SuppressWarnings("unchecked") static Map<String, Integer> getLabelsCount(final Graph<?, ? extends Node> target,
                                                      final Predicate<Element<?>> elementFilter,
                                                      final Set<String> roleFilter); @SuppressWarnings("unchecked") static void computeLabelsCount(final Node node,
                                          final Map<String, Integer> labelsCount,
                                          final Set<String> roleFilter); static CardinalityCountState computeCardinalityState(final Diagram diagram); static Set<String> getLabels(final Element<? extends Definition<?>> element); @SuppressWarnings("unchecked") static Element<?> getParent(final Node<?, ? extends Edge> element); @SuppressWarnings("unchecked") static Optional<Element<? extends Definition>> getParentByDefinitionId(final DefinitionManager definitionManager,
                                                                                  final Function<Node, Element> parentSupplier,
                                                                                  final Node<?, ? extends Edge> candidate,
                                                                                  final Predicate<String> parentDefIdFilter); @SuppressWarnings("unchecked") static Optional<Element<? extends Definition>> getParentByDefinitionId(final DefinitionManager definitionManager,
                                                                                  final Function<Node, Element> parentSupplier,
                                                                                  final Node<?, ? extends Edge> candidate,
                                                                                  final String parentDefId); static Point2D getPosition(final View element); static Point2D getComputedPosition(final Node<?, ? extends Edge> element); static double[] getNodeSize(final View element); static boolean isRootNode(Element<? extends View<?>> element, final Graph<DefinitionSet, Node> graph); static boolean checkBoundsExceeded(final Bounds parentBounds,
                                              final Bounds bounds); @SuppressWarnings("unchecked") static Node<Definition<C>, ?> getFirstNode(final Graph<?, Node> graph,
                                                          final Class<?> type); @SuppressWarnings("unchecked") static boolean hasChildren(final Node<?, ? extends Edge> element); static boolean hasDockedNodes(final Node<?, ? extends Edge> element); static boolean hasConnections(Node<? extends Definition<?>, ? extends Edge> node); static boolean hasTargetConnections(Node<? extends Definition<?>, ? extends Edge> node); static Predicate<Element> isContentSomeDefinition(); static List<Node> getDockedNodes(final Node<?, ? extends Edge> element); static List<Node> getChildNodes(final Node<?, ? extends Edge> element); static List<Edge<? extends ViewConnector<?>, Node>> getSourceConnections(
            final Node<?, ? extends Edge> element); static List<Edge<? extends ViewConnector<?>, Node>> getTargetConnections(
            final Node<?, ? extends Edge> element); static boolean isDockedNode(final Node<?, ? extends Edge> element); static Optional<Node> getDockParent(final Node<?, ? extends Edge> element); @SuppressWarnings("unchecked") static Long countChildren(final Node<?, ? extends Edge> element); static OptionalInt getChildIndex(final Element element,
                                            final String uuid); }
GraphUtils { public static CardinalityCountState computeCardinalityState(final Diagram diagram) { final String rootUUID = diagram.getMetadata().getCanvasRootUUID(); final Graph graph = diagram.getGraph(); final Iterator nodes = graph.nodes().iterator(); final Node firstElement = nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; final Node secondElement = null != firstElement && nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; final Node thirdElement = null != secondElement && nodes.hasNext() ? ((Element) nodes.next()).asNode() : null; if (null != thirdElement) { return CardinalityCountState.MULTIPLE_NODES; } if (null != secondElement && secondElement.getUUID().equals(rootUUID)) { return CardinalityCountState.SINGLE_NODE; } if (null != firstElement && firstElement.getUUID().equals(rootUUID)) { return null != secondElement ? CardinalityCountState.SINGLE_NODE : CardinalityCountState.EMPTY; } if (null != firstElement && null != secondElement) { return CardinalityCountState.MULTIPLE_NODES; } return null != firstElement ? CardinalityCountState.SINGLE_NODE : CardinalityCountState.EMPTY; }  static int countEdges(final DefinitionManager definitionManager,
                                 final String edgeId,
                                 final Collection<? extends Edge> edges); static Map<String, Integer> getLabelsCount(final Graph<?, ? extends Node> target,
                                                      final Set<String> roleFilter); @SuppressWarnings("unchecked") static Map<String, Integer> getLabelsCount(final Graph<?, ? extends Node> target,
                                                      final Predicate<Element<?>> elementFilter,
                                                      final Set<String> roleFilter); @SuppressWarnings("unchecked") static void computeLabelsCount(final Node node,
                                          final Map<String, Integer> labelsCount,
                                          final Set<String> roleFilter); static CardinalityCountState computeCardinalityState(final Diagram diagram); static Set<String> getLabels(final Element<? extends Definition<?>> element); @SuppressWarnings("unchecked") static Element<?> getParent(final Node<?, ? extends Edge> element); @SuppressWarnings("unchecked") static Optional<Element<? extends Definition>> getParentByDefinitionId(final DefinitionManager definitionManager,
                                                                                  final Function<Node, Element> parentSupplier,
                                                                                  final Node<?, ? extends Edge> candidate,
                                                                                  final Predicate<String> parentDefIdFilter); @SuppressWarnings("unchecked") static Optional<Element<? extends Definition>> getParentByDefinitionId(final DefinitionManager definitionManager,
                                                                                  final Function<Node, Element> parentSupplier,
                                                                                  final Node<?, ? extends Edge> candidate,
                                                                                  final String parentDefId); static Point2D getPosition(final View element); static Point2D getComputedPosition(final Node<?, ? extends Edge> element); static double[] getNodeSize(final View element); static boolean isRootNode(Element<? extends View<?>> element, final Graph<DefinitionSet, Node> graph); static boolean checkBoundsExceeded(final Bounds parentBounds,
                                              final Bounds bounds); @SuppressWarnings("unchecked") static Node<Definition<C>, ?> getFirstNode(final Graph<?, Node> graph,
                                                          final Class<?> type); @SuppressWarnings("unchecked") static boolean hasChildren(final Node<?, ? extends Edge> element); static boolean hasDockedNodes(final Node<?, ? extends Edge> element); static boolean hasConnections(Node<? extends Definition<?>, ? extends Edge> node); static boolean hasTargetConnections(Node<? extends Definition<?>, ? extends Edge> node); static Predicate<Element> isContentSomeDefinition(); static List<Node> getDockedNodes(final Node<?, ? extends Edge> element); static List<Node> getChildNodes(final Node<?, ? extends Edge> element); static List<Edge<? extends ViewConnector<?>, Node>> getSourceConnections(
            final Node<?, ? extends Edge> element); static List<Edge<? extends ViewConnector<?>, Node>> getTargetConnections(
            final Node<?, ? extends Edge> element); static boolean isDockedNode(final Node<?, ? extends Edge> element); static Optional<Node> getDockParent(final Node<?, ? extends Edge> element); @SuppressWarnings("unchecked") static Long countChildren(final Node<?, ? extends Edge> element); static OptionalInt getChildIndex(final Element element,
                                            final String uuid);  }