### Question:
RelationResolver { static <T> Set<Class<? extends T>> reduceDescendants(Iterable<Class<? extends T>> classes) { Set<Class<? extends T>> result = new HashSet<>(); candidates: for (Class<? extends T> candidate : classes) { Iterator<Class<? extends T>> iterator = result.iterator(); while (iterator.hasNext()) { Class<?> optimized = iterator.next(); if (optimized.isAssignableFrom(candidate)) { continue candidates; } if (candidate.isAssignableFrom(optimized)) { iterator.remove(); } } result.add(candidate); } return result; } private  RelationResolver(); static int calculateInheritanceDistance(Class<?> parent, Class<?> child);  }### Answer:
@Test public void reduceDescendantsEmpty() { List<Class<?>> classes = Collections.emptyList(); Set<Class<?>> set = RelationResolver.reduceDescendants(classes); assertThat(set, is(empty())); }
@Test public void reduceDescendants() { List<Class<?>> classes = asList(Number.class, BigDecimal.class, ArrayList.class, AbstractList.class); Set<Class<?>> reduced = RelationResolver.reduceDescendants(classes); assertThat(reduced, hasSize(2)); @SuppressWarnings("unchecked") Matcher<Iterable<? extends Class<?>>> matcher = Matchers.containsInAnyOrder(Number.class, AbstractList.class); assertThat(reduced, matcher); }