Replace an existing node in the graph with a new node. The new node will be connected to all the nodes the old node was. The old node will be removed. The new node is assumed to have no incoming or outgoing edges @param oldNode Node to be replaced @param newNode Node to add in place of oldNode @th
(E oldNode, E newNode)
| 668 | * @throws PlanException |
| 669 | */ |
| 670 | public void replace(E oldNode, E newNode) throws PlanException { |
| 671 | checkInPlan(oldNode); |
| 672 | add(newNode); |
| 673 | List<E> oldNodeSuccs = (getSuccessors(oldNode) == null? null : new ArrayList<E>(getSuccessors(oldNode))); |
| 674 | List<IndexHelper<E>> indexHelpers = new ArrayList<IndexHelper<E>>(); |
| 675 | if(oldNodeSuccs != null) { |
| 676 | for(int i = 0; i < oldNodeSuccs.size(); ++i) { |
| 677 | E oldNodeSucc = oldNodeSuccs.get(i); |
| 678 | indexHelpers.add(new IndexHelper<E>(new ArrayList<E>(getPredecessors(oldNodeSucc)))); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | |
| 683 | mToEdges = generateNewMap(oldNode, newNode, mToEdges); |
| 684 | mFromEdges = generateNewMap(oldNode, newNode, mFromEdges); |
| 685 | |
| 686 | //ensure that the oldNode's successors are rewired |
| 687 | if(oldNodeSuccs != null) { |
| 688 | for(int i = 0; i < oldNodeSuccs.size(); ++i) { |
| 689 | E oldNodeSucc = oldNodeSuccs.get(i); |
| 690 | oldNodeSucc.rewire(oldNode, indexHelpers.get(i).getIndex(oldNode), newNode, true); |
| 691 | } |
| 692 | } |
| 693 | remove(oldNode); |
| 694 | |
| 695 | } |
| 696 | |
| 697 | private MultiMap<E, E> generateNewMap( |
| 698 | E oldNode, |
nothing calls this directly
no test coverage detected