public Node mergeNodes(Node node1, Node node2) {
		Node superNode = new Node(node1.getId() + "-" + node2.getId());
		addNode(superNode);

		List<Node> connectedNodes = new ArrayList<Node>();
		for (Node node : getAdjacentNodes(node1)) {
			if (!node.equals(node1) && !node.equals(node2)) {
				connectedNodes.add(node);
			}
		}
		for (Node node : getAdjacentNodes(node2)) {
			if (!node.equals(node1) && !node.equals(node2)) {
				connectedNodes.add(node);
			}
		}

		Set<Edge> edgesToDelete = new HashSet<Edge>();
		edgesToDelete.addAll(edgesByNode.get(node1));
		edgesToDelete.addAll(edgesByNode.get(node2));

		nodes.remove(node1);
		nodes.remove(node2);
		edgesByNode.remove(node1);
		edgesByNode.remove(node2);

		for (Edge edge : edgesToDelete) {
			removeEdge(edge);
		}

		for (Node connectedNode : connectedNodes) {
			addEdge(superNode, connectedNode);
		}

		return superNode;
	}