/** * 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); }
public static void validateField(String name, Class<?> type, Object o) { ConfigValidationUtils.NestableFieldValidator validator = ConfigValidationUtils.listFv(type, false); validator.validateField(name, o); }
@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"); } } }
/** * 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); }
public static void validateField(String name, Class type, Object o) { ConfigValidationUtils.NestableFieldValidator validator = ConfigValidationUtils.listFv(type, false); validator.validateField(name, o); } }
@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"); } } }