@Override public void registerEvent(SimpleUri uri, Class<? extends Event> eventType) { eventIdMap.put(uri, eventType); logger.debug("Registering event {}", eventType.getSimpleName()); for (Class parent : ReflectionUtils.getAllSuperTypes(eventType, Predicates.assignableFrom(Event.class))) { if (!AbstractConsumableEvent.class.equals(parent) && !Event.class.equals(parent)) { childEvents.put(parent, eventType); } } if (shouldAddToLibrary(eventType)) { eventLibrary.register(uri, eventType); } }
@Override public void registerEvent(SimpleUri uri, Class<? extends Event> eventType) { eventIdMap.put(uri, eventType); logger.debug("Registering event {}", eventType.getSimpleName()); for (Class parent : ReflectionUtils.getAllSuperTypes(eventType, Predicates.assignableFrom(Event.class))) { if (!AbstractConsumableEvent.class.equals(parent) && !Event.class.equals(parent)) { childEvents.put(parent, eventType); } } if (shouldAddToLibrary(eventType)) { eventLibrary.register(uri, eventType); } }
public static Predicate<Class<?>> assignableFrom(Class<?> clazz) { return com.google.common.base.Predicates.assignableFrom(clazz); }
@Override public boolean apply(@Nullable final Constructor<?> input) { final List<Class<?>> params = Lists.<Class<?>>newArrayList(input.getParameterTypes()); final Predicate<Class<?>> predicate = Predicates.assignableFrom(EventListenerRegistrar.class); return Iterables.any(params, predicate); } };
public boolean implementsInterface(Entity entity, Class<?> type) { return Iterables.tryFind(Arrays.asList(entity.getClass().getInterfaces()), Predicates.assignableFrom(type)).isPresent(); }
/** * Queries recursively the given types (either {@link Class} or {@link RegisteredType}) * to see whether any inherit from the given {@link Class} */ public static boolean isAnyTypeSubtypeOf(Set<Object> candidateTypes, Class<?> superType) { if (superType == Object.class) return true; return isAnyTypeOrSuperSatisfying(candidateTypes, Predicates.assignableFrom(superType)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Predicate<RegisteredType> subtypeOf(final Class<?> filter) { // the assignableFrom predicate checks if this class is assignable from the subsequent *input*. // in other words, we're checking if any input is a subtype of this class return anySuperType((Predicate)Predicates.assignableFrom(filter)); }
/** * Finds classes by the annotation and which extends from the resultingClass * and instantiates them. If the classes which are marked by the annotation * and do not extend the resultingClass then they are ignored. * * @param <T> the class of objects to be returned. * @param annotatedClass the annotation which marks the classes to find. * @param resultingClass the class from which the found classes should extend. * It could be an interface or a class. * @return the collection of objects found. */ public <T> Collection<T> find(final Class<? extends Annotation> annotatedClass, final Class<T> resultingClass) { final Collection<Class<?>> filteredList = Collections2.filter(findClass(annotatedClass), Predicates.assignableFrom(resultingClass)); return Collections2.transform(filteredList, new ClassToObjectTransformer<T>()); }
@GwtIncompatible // Predicates.subtypeOf @SuppressWarnings("deprecation") public void testSubtypeOf_equality() { new EqualsTester() .addEqualityGroup( Predicates.subtypeOf(Integer.class), Predicates.subtypeOf(Integer.class), Predicates.assignableFrom(Integer.class)) .addEqualityGroup(Predicates.subtypeOf(Number.class)) .addEqualityGroup(Predicates.subtypeOf(Float.class)) .testEquals(); }