/** * Removes the junction that links the node where this action is executed and the target node. */ @Override public void execute(final Node<Double> targetNode) { if (targetNode instanceof CellNode) { getNode().removeJunction(jun, (CellNode) targetNode); } else { throw new UnsupportedOperationException("Can't remove Junction in a node that it's not a CellNode"); } }
@Override public void execute(final Node<Double> targetNode) { if (targetNode instanceof CellNode) { ((CellNode) targetNode).removeJunction(jun, getNode()); } else { throw new UnsupportedOperationException("Can't add Junction in a node that it's not a CellNode"); } }
@Override public void moveNode(final Node<Double> node, final Position direction) { if (node instanceof CellNode) { super.moveNode(node, direction); final CellNode nodeToMove = (CellNode) node; final Neighborhood<Double> neigh = getNeighborhood(nodeToMove); final Map<Junction, Map<CellNode, Integer>> jun = nodeToMove.getJunctions(); jun.entrySet().stream().forEach(e -> e.getValue().entrySet().forEach(e2 -> { if (!neigh.contains(e2.getKey())) { // there is a junction that links a node which isn't in the neighborhood after the movement for (int i = 0; i < e2.getValue(); i++) { nodeToMove.removeJunction(e.getKey(), e2.getKey()); e2.getKey().removeJunction(e.getKey().reverse(), nodeToMove); } } })); } }