PrunedAdjacencyMaps implements AdjacencyMaps { @Override public void add(final AdjacencyMap adjacencyMap) { removeOrphans(adjacencyMaps, adjacencyMap); adjacencyMaps.add(adjacencyMap); }  @Override void add(final AdjacencyMap adjacencyMap); @Override List<AdjacencyMap> asList();  }
@Test public void shouldPrune() { final AdjacencyMaps adjacencyMaps = new PrunedAdjacencyMaps(); final AdjacencyMap first = new AdjacencyMap(); first.putEdge(1, 2, makeEdge(1, 2)); first.putEdge(1, 3, makeEdge(1, 3)); final AdjacencyMap second = new AdjacencyMap(); second.putEdge(2, 3, makeEdge(2, 3)); second.putEdge(2, 4, makeEdge(2, 4)); adjacencyMaps.add(first); adjacencyMaps.add(second); final AdjacencyMap firstPruned = adjacencyMaps.get(0); final AdjacencyMap secondPruned = adjacencyMaps.get(1); assertThat(firstPruned.getDestinations(1), hasSize(1)); assertThat(secondPruned.getDestinations(2), hasSize(2)); }
@Test public void shouldPruneRecursively() { final AdjacencyMaps adjacencyMaps = new PrunedAdjacencyMaps(); final AdjacencyMap first = new AdjacencyMap(); first.putEdge(1, 2, makeEdge(1, 2)); first.putEdge(1, 3, makeEdge(1, 3)); final AdjacencyMap second = new AdjacencyMap(); second.putEdge(2, 4, makeEdge(2, 4)); second.putEdge(2, 5, makeEdge(2, 5)); second.putEdge(3, 6, makeEdge(3, 6)); second.putEdge(3, 7, makeEdge(3, 7)); final AdjacencyMap third = new AdjacencyMap(); third.putEdge(4, 8, makeEdge(4, 8)); third.putEdge(4, 9, makeEdge(4, 9)); third.putEdge(5, 10, makeEdge(5, 10)); third.putEdge(5, 11, makeEdge(5, 11)); adjacencyMaps.add(first); adjacencyMaps.add(second); adjacencyMaps.add(third); final AdjacencyMap firstPruned = adjacencyMaps.get(0); final AdjacencyMap secondPruned = adjacencyMaps.get(1); final AdjacencyMap thirdPruned = adjacencyMaps.get(2); assertThat(firstPruned.getDestinations(1), hasSize(1)); assertThat(secondPruned.getDestinations(2), hasSize(2)); assertThat(thirdPruned.getDestinations(4), hasSize(2)); assertThat(thirdPruned.getDestinations(5), hasSize(2)); }