@Test void testGetAllDependantsCircular() { when(getDepth.apply(0)).thenReturn(1); when(getDependants.apply(0)).thenReturn(ImmutableSet.of(0)); assertEquals(of(0), genericDependencyResolver.getAllDependants(0, getDepth, getDependants)); }
public <A> Set<A> getAllDependants( A item, Function<A, Integer> getDepth, Function<A, Set<A>> getDependants) { Set<A> currentGeneration = singleton(item); Set<A> result = newHashSet(); Set<A> visited = newHashSet(); for (int depth = 0; !currentGeneration.isEmpty(); depth++) { currentGeneration = copyOf(difference(getDirectDependants(currentGeneration, getDependants), visited)); result.addAll( currentGeneration.stream().filter(getDepthFilter(depth, getDepth)).collect(toSet())); visited.addAll(currentGeneration); } return result; }
GenericDependencyResolver { public <A> Set<A> getAllDependants( A item, Function<A, Integer> getDepth, Function<A, Set<A>> getDependants) { Set<A> currentGeneration = singleton(item); Set<A> result = newHashSet(); Set<A> visited = newHashSet(); for (int depth = 0; !currentGeneration.isEmpty(); depth++) { currentGeneration = copyOf(difference(getDirectDependants(currentGeneration, getDependants), visited)); result.addAll( currentGeneration.stream().filter(getDepthFilter(depth, getDepth)).collect(toSet())); visited.addAll(currentGeneration); } return result; } }
GenericDependencyResolver { public <A> Set<A> getAllDependants( A item, Function<A, Integer> getDepth, Function<A, Set<A>> getDependants) { Set<A> currentGeneration = singleton(item); Set<A> result = newHashSet(); Set<A> visited = newHashSet(); for (int depth = 0; !currentGeneration.isEmpty(); depth++) { currentGeneration = copyOf(difference(getDirectDependants(currentGeneration, getDependants), visited)); result.addAll( currentGeneration.stream().filter(getDepthFilter(depth, getDepth)).collect(toSet())); visited.addAll(currentGeneration); } return result; }  }
GenericDependencyResolver { public <A> Set<A> getAllDependants( A item, Function<A, Integer> getDepth, Function<A, Set<A>> getDependants) { Set<A> currentGeneration = singleton(item); Set<A> result = newHashSet(); Set<A> visited = newHashSet(); for (int depth = 0; !currentGeneration.isEmpty(); depth++) { currentGeneration = copyOf(difference(getDirectDependants(currentGeneration, getDependants), visited)); result.addAll( currentGeneration.stream().filter(getDepthFilter(depth, getDepth)).collect(toSet())); visited.addAll(currentGeneration); } return result; }  List<A> resolve(Collection<A> items, Function<A, Set<A>> getDependencies); Set<A> getAllDependants(
      A item, Function<A, Integer> getDepth, Function<A, Set<A>> getDependants); }
GenericDependencyResolver { public <A> Set<A> getAllDependants( A item, Function<A, Integer> getDepth, Function<A, Set<A>> getDependants) { Set<A> currentGeneration = singleton(item); Set<A> result = newHashSet(); Set<A> visited = newHashSet(); for (int depth = 0; !currentGeneration.isEmpty(); depth++) { currentGeneration = copyOf(difference(getDirectDependants(currentGeneration, getDependants), visited)); result.addAll( currentGeneration.stream().filter(getDepthFilter(depth, getDepth)).collect(toSet())); visited.addAll(currentGeneration); } return result; }  List<A> resolve(Collection<A> items, Function<A, Set<A>> getDependencies); Set<A> getAllDependants(
      A item, Function<A, Integer> getDepth, Function<A, Set<A>> getDependants);  }