com.beust.jcommander.IParameterValidator Java Examples

The following examples show how to use com.beust.jcommander.IParameterValidator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PropertiesConfig.java    From jsflight with Apache License 2.0 5 votes vote down vote up
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());
        }
    };
}
 
Example #2
Source File: PropertiesConfig.java    From jsflight with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #3
Source File: PropertiesConfig.java    From jsflight with Apache License 2.0 4 votes vote down vote up
private String getProperty(String name, IParameterValidator validator)
{
    return getProperty(name, validator, (IStringConverter<String>)String::toString);
}
 
Example #4
Source File: PropertiesConfig.java    From jsflight with Apache License 2.0 4 votes vote down vote up
private <T> T getProperty(String name, IParameterValidator validator, IStringConverter<T> converter)
{
    return getProperty(name, null, validator, converter);
}