osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] brooklyn-server pull request #999: Constraints - serialization and {forbidde...


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

    https://github.com/apache/brooklyn-server/pull/999#discussion_r219567394
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/config/ConfigConstraints.java ---
    @@ -218,4 +228,88 @@ public LocationConfigConstraints(Location brooklynObject) {
             }
         }
     
    +    public static <T> Predicate<T> required() {
    +        return new RequiredPredicate<T>();
    +    }
    +    
    +    /** Predicate indicating a field is required:  it must not be null and if a string it must not be empty */
    +    public static class RequiredPredicate<T> implements Predicate<T> {
    +        @Override
    +        public boolean apply(T input) {
    +            if (input==null) return false;
    +            if (input instanceof CharSequence && ((CharSequence)input).length()==0) return false;
    +            return true;
    +        }
    +        @Override
    +        public String toString() {
    +            return "required()";
    +        }
    +    }
    +    
    +    private static abstract class OtherKeyPredicate implements BrooklynObjectPredicate<Object> {
    +        private String otherKeyName;
    --- End diff --
    
    Declare this final (pretty much wherever we can declare fields final, it's a good idea).


---