public static <T> void merge(Graph<T> target, Graph<T> toMerge) {
        for (Vertex<T> vertex : toMerge.getVerticies()) {
            target.addVertex(vertex);
        }

        // merge edges
        List<Edge<T>> edges = target.getEdges();
        for (Edge newEdge : toMerge.getEdges()) {
            Optional<Edge<T>> any = edges.stream()
                    .filter(existing ->
                            existing.getFrom().getName().equals(newEdge.getFrom().getName())
                             && existing.getTo().getName().equals(newEdge.getTo().getName())
                    ).findAny();
            if (!any.isPresent()) {
                edges.add(newEdge);
            }
        }
    }
public static <T> void merge(Graph<T> target, Graph<T> toMerge) {
        for (Vertex<T> vertex : toMerge.getVerticies()) {
            target.addVertex(vertex);
        }

        
        List<Edge<T>> edges = target.getEdges();
        for (Edge newEdge : toMerge.getEdges()) {
            Optional<Edge<T>> any = edges.stream()
                    .filter(existing ->
                            existing.getFrom().getName().equals(newEdge.getFrom().getName())
                             && existing.getTo().getName().equals(newEdge.getTo().getName())
                    ).findAny();
            if (!any.isPresent()) {
                edges.add(newEdge);
            }
        }
    }
public static < T > void merge ( Graph < T > target , Graph < T > toMerge ) { for ( Vertex < T > vertex : toMerge . getVerticies ( ) ) { target . addVertex ( vertex ) ; } // merge edges List < Edge < T > > edges = target . getEdges ( ) ; for ( Edge newEdge : toMerge . getEdges ( ) ) { Optional < Edge < T >> any = edges . stream ( ) . filter ( existing -> existing . getFrom ( ) . getName ( ) . equals ( newEdge . getFrom ( ) . getName ( ) ) && existing . getTo ( ) . getName ( ) . equals ( newEdge . getTo ( ) . getName ( ) ) ) . findAny ( ) ; if ( ! any . isPresent ( ) ) { edges . add ( newEdge ) ; } } }
Adds all elements from toMerge to target.
Adds all elements from toMerge to target .