visualization/visualization-model/src/main/java/se/jguru/nazgul/tools/visualization/model/diagram/statement/Statements.java
public Edge addEdge(final String fromId, final String toId, final Graph parentGraph) {

        // Check sanity
        if (fromId == null || fromId.isEmpty()) {
            throw new IllegalArgumentException("Cannot handle null or empty 'fromId' argument.");
        }
        if (toId == null || toId.isEmpty()) {
            throw new IllegalArgumentException("Cannot handle null or empty 'toId' argument.");
        }
        if (parentGraph == null) {
            throw new IllegalArgumentException("Cannot handle null 'parentGraph' argument.");
        }

        Edge toReturn = null;

        // Find the nodes between which the Edge should be created.
        final Node fromNode = findNode(fromId, true);
        final Subgraph fromSubgraph = findSubgraph(fromId, true);

        if (fromNode != null || fromSubgraph != null) {

            // Find the RHS edge data.
            final Node toNode = findNode(toId, true);
            final Subgraph toSubgraph = findSubgraph(toId, true);
            final NodeID toNodeId = toNode == null ? null : toNode.getNodeID();

            // Can we actually create an Edge?
            if (toNodeId != null || toSubgraph != null) {

                // Start by creating the RightSideEdge.
                final RightSideEdge rightSideEdge = toNodeId == null
                        ? new RightSideEdge(toSubgraph)
                        : new RightSideEdge(toNodeId);

                // Finally, create the Edge to return.
                toReturn = fromNode == null
                        ? new Edge(fromSubgraph, rightSideEdge)
                        : new Edge(fromNode.getNodeID(), rightSideEdge);
            }
        }

        // Add the newly created Edge, if applicable.
        if (toReturn != null) {
            add(toReturn);
        }

        // All Done.
        return toReturn;
    }
public Edge addEdge(final String fromId, final String toId, final Graph parentGraph) {

        // Check sanity
        if (fromId == null || fromId.isEmpty()) {
            throw new IllegalArgumentException("Cannot handle null or empty 'fromId' argument.");
        }
        if (toId == null || toId.isEmpty()) {
            throw new IllegalArgumentException("Cannot handle null or empty 'toId' argument.");
        }
        if (parentGraph == null) {
            throw new IllegalArgumentException("Cannot handle null 'parentGraph' argument.");
        }

        Edge toReturn = null;

        // Find the nodes between which the Edge should be created.
        final Node fromNode = findNode(fromId, true);
        final Subgraph fromSubgraph = findSubgraph(fromId, true);

        if (fromNode != null || fromSubgraph != null) {

            // Find the RHS edge data.
            final Node toNode = findNode(toId, true);
            final Subgraph toSubgraph = findSubgraph(toId, true);
            final NodeID toNodeId = toNode == null ? null : toNode.getNodeID();

            // Can we actually create an Edge?
            if (toNodeId != null || toSubgraph != null) {

                // Start by creating the RightSideEdge.
                final RightSideEdge rightSideEdge = toNodeId == null
                        ? new RightSideEdge(toSubgraph)
                        : new RightSideEdge(toNodeId);

                // Finally, create the Edge to return.
                toReturn = fromNode == null
                        ? new Edge(fromSubgraph, rightSideEdge)
                        : new Edge(fromNode.getNodeID(), rightSideEdge);
            }
        }

        // Add the newly created Edge, if applicable.
        if (toReturn != null) {
            add(toReturn);
        }

        // All Done.
        return toReturn;
    }
Convenience method to add and return an Edge between a Node/Subgraph and another Node/Subgraph.

@param fromId      The non-empty ID of the Node/Subgraph from which the Edge should originate.
@param toId        The non-empty ID of the Node/Subgraph to which the Edge should be directed.
@param parentGraph The non-null parent {@link Graph} where the Edge is about to be created.
@return The newly created Edge - or {@code null} if the Edge could not be created.