You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by aledsage <gi...@git.apache.org> on 2015/05/02 23:21:55 UTC

[GitHub] incubator-brooklyn pull request: EntityPredicates.hasInterfaceMatc...

Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/616#discussion_r29550849
  
    --- Diff: core/src/main/java/brooklyn/entity/basic/EntityPredicates.java ---
    @@ -271,9 +274,38 @@ public boolean apply(@Nullable Entity input) {
         // ---------------------------
     
         /**
    +     * @param typeRegex a regular expression
    +     * @return true if any of the interfaces implemented by the entity (including those derived) match typeRegex.
    +     */
    +    public static Predicate<Entity> hasInterfaceMatching(String typeRegex) {
    +        return new ImplementsInterface(typeRegex);
    +    }
    +
    +    protected static class ImplementsInterface implements SerializablePredicate<Entity> {
    +        protected final Pattern pattern;
    +
    +        public ImplementsInterface(String typeRegex) {
    +            this.pattern = Pattern.compile(typeRegex);
    +        }
    +
    +        @Override
    +        public boolean apply(@Nullable Entity input) {
    +            if (input == null) return false;
    +            for (Class<?> cls : ClassUtils.getAllInterfaces(input.getClass())) {
    --- End diff --
    
    We also have `brooklyn.util.javalang.Reflections.getAllInterfaces(Class)`, which does the same as in `ClassUtils`.
    
    If we're going to keep the dependency on apache-commons lang3, then we should probably delete that brooklyn code! (Or more specifically deprecate it, and have its impl delegate to the lang3 version).
    
    But that's not for this PR.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---