private IParameterValidator or(IParameterValidator... validators) { return (name, value) -> { boolean isValid = false; List<ParameterException> exceptions = new ArrayList<>(); for (int i = 0; i < validators.length && !isValid; i++) { try { validators[i].validate(name, value); isValid = true; } catch (ParameterException e) { exceptions.add(e); } } if (!isValid) { StringBuilder exceptionMessage = new StringBuilder(); for (ParameterException exception : exceptions) { if (exceptionMessage.length() != 0) { exceptionMessage.append(" or "); } exceptionMessage.append(exception.getMessage()); } throw new ParameterException(exceptionMessage.toString()); } }; }
private <T> T getProperty(String name, T defaultValue, IParameterValidator validator, IStringConverter<T> converter) { String value = properties.getProperty(name); if (value == null && defaultValue != null) { value = defaultValue.toString(); } if (validator != null) { validator.validate(name, value); } return value == null ? null : converter.convert(value); }
private String getProperty(String name, IParameterValidator validator) { return getProperty(name, validator, (IStringConverter<String>)String::toString); }
private <T> T getProperty(String name, IParameterValidator validator, IStringConverter<T> converter) { return getProperty(name, null, validator, converter); }