brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorbett <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: EntityPredicates.hasInterfaceMatc...
Date Tue, 05 May 2015 11:05:29 GMT
Github user sjcorbett commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/616#discussion_r29659456
  
    --- 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 --
    
    commons-lang3 is coming from camp-base rather than core directly. I'll swap it for Reflections.



---
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.
---

Mime
View raw message