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

    https://github.com/apache/brooklyn-server/pull/821#discussion_r142351685
  
    --- Diff: 
rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
 ---
    @@ -130,6 +143,36 @@ public Policy getPolicy(Entity entity, String policy) {
             
             throw WebResourceUtils.notFound("Cannot find policy '%s' in entity 
'%s'", policy, entity);
         }
    +    
    +    /** finds the policy indicated by the given ID or name.
    +     * @see {@link #getAdjunct(String,String,String)}.
    +     * <p>
    +     * 
    +     * @throws 404 or 412 (unless input is null in which case output is 
null) */
    +    public EntityAdjunct getAdjunct(Entity entity, String adjunct) {
    +        if (adjunct==null) return null;
    +
    +        for (Policy p: entity.policies()) {
    +            if (adjunct.equals(p.getId())) return p;
    +        }
    +        for (Policy p: entity.policies()) {
    +            if (adjunct.equals(p.getDisplayName())) return p;
    +        }
    +        for (Enricher p: entity.enrichers()) {
    +            if (adjunct.equals(p.getId())) return p;
    +        }
    +        for (Enricher p: entity.enrichers()) {
    +            if (adjunct.equals(p.getDisplayName())) return p;
    +        }
    +        for (Feed p: ((EntityInternal)entity).feeds()) {
    +            if (adjunct.equals(p.getId())) return p;
    +        }
    +        for (Feed p: ((EntityInternal)entity).feeds()) {
    +            if (adjunct.equals(p.getDisplayName())) return p;
    +        }
    --- End diff --
    
    no - in perverse case where we have feed<ID=1 name=2> and feed<ID=2 
name=foo> a call to get "2" should return the latter, whereas combining loops 
would return the former
    
    we do need to compare all by ID's first however
    
    agree it's an edge case and isn't significant but think the code should 
stay with separate loops.
    
    PS processing time change would not be as large as you say as the string 
comparison dominates execution time and that is unchanged by combining loops.


---

Reply via email to