RemoveFlattenInstructionsFunction implements Function<MutableNetwork<Node, Edge>, MutableNetwork<Node, Edge>> { @Override public MutableNetwork<Node, Edge> apply(MutableNetwork<Node, Edge> network) { for (Node node : ImmutableList.copyOf(Iterables.filter(network.nodes(), IsFlatten.INSTANCE))) { Node flattenPCollection = Iterables.getOnlyElement(network.successors(node)); for (Node successorInstruction : ImmutableList.copyOf(network.successors(flattenPCollection))) { for (Edge edge : ImmutableList.copyOf( network.edgesConnecting(flattenPCollection, successorInstruction))) { for (Node predecessorPCollection : ImmutableList.copyOf(network.predecessors(node))) { network.addEdge(predecessorPCollection, successorInstruction, edge.clone()); } } } network.removeNode(flattenPCollection); network.removeNode(node); } return network; }  @Override MutableNetwork<Node, Edge> apply(MutableNetwork<Node, Edge> network);  }
@Test public void testEmptyNetwork() { assertEquals( createEmptyNetwork(), new RemoveFlattenInstructionsFunction().apply(createEmptyNetwork())); }