private static EnumMap<PropertyType, Function<String, Result>> createValidations(List<String> options) { EnumMap<PropertyType, Function<String, Result>> map = new EnumMap<>(PropertyType.class); map.put(BOOLEAN, validateBoolean()); map.put(INTEGER, validateInteger()); map.put(LONG, validateInteger()); map.put(FLOAT, validateFloat()); map.put(REGULAR_EXPRESSION, validateRegexp()); map.put(SINGLE_SELECT_LIST, aValue -> options.contains(aValue) ? Result.SUCCESS : Result.newError("notInOptions")); return map; }
public static Result validate(PropertyType type, @Nullable String value, List<String> options) { if (StringUtils.isNotBlank(value)) { if (type == PropertyType.BOOLEAN) { return validateBoolean(value); } else if (type == PropertyType.INTEGER) { return validateInteger(value); } else if (type == PropertyType.FLOAT) { return validateFloat(value); } else if (type == PropertyType.SINGLE_SELECT_LIST && !options.contains(value)) { return Result.newError("notInOptions"); } } return Result.SUCCESS; }
private static EnumMap<PropertyType, Function<String, Result>> createValidations(List<String> options) { EnumMap<PropertyType, Function<String, Result>> map = new EnumMap<>(PropertyType.class); map.put(BOOLEAN, validateBoolean()); map.put(INTEGER, validateInteger()); map.put(LONG, validateInteger()); map.put(FLOAT, validateFloat()); map.put(REGULAR_EXPRESSION, validateRegexp()); map.put(SINGLE_SELECT_LIST, aValue -> options.contains(aValue) ? Result.SUCCESS : Result.newError("notInOptions")); return map; }