/** * Returns a new NestableFieldValidator for a Map of key to val. * * @param key the Class of keys in the map * @param val the Class of values in the map * @param notNull whether or not a value of null is valid * @return a NestableFieldValidator for a Map of key to val */ public static NestableFieldValidator mapFv(Class key, Class val, boolean notNull) { return mapFv(fv(key, false), fv(val, false), notNull); }
/** * Returns a new NestableFieldValidator for a List of the given Class. * * @param cls the Class of elements composing the list * @param notNull whether or not a value of null is valid * @return a NestableFieldValidator for a list of the given class */ public static NestableFieldValidator listFv(Class cls, boolean notNull) { return listFv(fv(cls, notNull), notNull); }
@Override public void validateField(String name, Object o) { if (o == null) { return; } ConfigValidationUtils.NestableFieldValidator validator = ConfigValidationUtils.mapFv(ConfigValidationUtils.fv(String.class, false), ConfigValidationUtils.listFv(String.class, false), false); validator.validateField(name, o); @SuppressWarnings("unchecked") Map<String, List<String>> mapObject = (Map<String, List<String>>) o; if (!mapObject.containsKey("hosts")) { throw new IllegalArgumentException(name + " should contain Map entry with key: hosts"); } if (!mapObject.containsKey("groups")) { throw new IllegalArgumentException(name + " should contain Map entry with key: groups"); } } }
@Override public void validateField(String name, Object o) { ConfigValidationUtils.NestableFieldValidator validator = ConfigValidationUtils.mapFv(ConfigValidationUtils.fv(String.class, false), ConfigValidationUtils.mapFv(String.class, Object.class, true), true); validator.validateField(name, o); } }
/** * Returns a new NestableFieldValidator for a Map of key to val. * @param key the Class of keys in the map * @param val the Class of values in the map * @param notNull whether or not a value of null is valid * @return a NestableFieldValidator for a Map of key to val */ public static NestableFieldValidator mapFv(Class key, Class val, boolean notNull) { return mapFv(fv(key, false), fv(val, false), notNull); }
/** * Returns a new NestableFieldValidator for a List of the given Class. * @param cls the Class of elements composing the list * @param notNull whether or not a value of null is valid * @return a NestableFieldValidator for a list of the given class */ public static NestableFieldValidator listFv(Class cls, boolean notNull) { return listFv(fv(cls, notNull), notNull); }
@Override public void validateField(String name, Object o) { if (o == null) { return; } ConfigValidationUtils.NestableFieldValidator validator = ConfigValidationUtils.mapFv(ConfigValidationUtils.fv(String.class, false), ConfigValidationUtils.listFv(String.class, false), false); validator.validateField(name, o); Map<String, List<String>> mapObject = (Map<String, List<String>>) o; if (!mapObject.containsKey("hosts")) { throw new IllegalArgumentException(name + " should contain Map entry with key: hosts"); } if (!mapObject.containsKey("groups")) { throw new IllegalArgumentException(name + " should contain Map entry with key: groups"); } } }
@Override public void validateField(String name, Object o) { ConfigValidationUtils.NestableFieldValidator validator = ConfigValidationUtils.mapFv(ConfigValidationUtils.fv(String.class, false), ConfigValidationUtils.mapFv(String.class, Object.class,true), true); validator.validateField(name, o); } }