/** * Selects first only the classes that are assignable from the target, and * then returns the most specific matching classes. * * @param target the Class to match * @param availableClasses classes to search * @return Set of only the most specific classes that match the target. */ static Set<Class<?>> findBestMatches(Class<?> target, Set<Class<?>> availableClasses) { Set<Class<?>> matches = new HashSet<Class<?>>(); if (availableClasses.contains(target)) { return ImmutableSet.<Class<?>> of(target); } else { for (Class<?> clazz : availableClasses) { if (clazz.isAssignableFrom(target)) { matches.add(clazz); } } } Predicate<Class<?>> moreSpecificClassPredicate = createMostSpecificMatchPredicate( matches, Functions.<Class<?>> identity()); return Sets.filter(matches, moreSpecificClassPredicate); }
/** * Selects first only the classes that are assignable from the target, and * then returns the most specific matching classes. * * @param target the Class to match * @param availableClasses classes to search * @return Set of only the most specific classes that match the target. */ static Set<Class<?>> findBestMatches(Class<?> target, Set<Class<?>> availableClasses) { Set<Class<?>> matches = new HashSet<Class<?>>(); if (availableClasses.contains(target)) { return ImmutableSet.<Class<?>> of(target); } else { for (Class<?> clazz : availableClasses) { if (clazz.isAssignableFrom(target)) { matches.add(clazz); } } } Predicate<Class<?>> moreSpecificClassPredicate = createMostSpecificMatchPredicate( matches, Functions.<Class<?>> identity()); return Sets.filter(matches, moreSpecificClassPredicate); }
/** * Selects first only the classes that are assignable from the target, and then returns the most * specific matching classes. * * @param target the Class to match * @param availableClasses classes to search * @return Set of only the most specific classes that match the target. */ static Set<Class<?>> findBestMatches(final Class<?> target, final Set<Class<?>> availableClasses) { final Set<Class<?>> matches = new HashSet<>(); if (availableClasses.contains(target)) { return ImmutableSet.<Class<?>>of(target); } else { for (final Class<?> clazz : availableClasses) { if (clazz.isAssignableFrom(target)) { matches.add(clazz); } } } final Predicate<Class<?>> moreSpecificClassPredicate = createMostSpecificMatchPredicate(matches, Functions.<Class<?>>identity()); return Sets.filter(matches, moreSpecificClassPredicate); }