/** * Retrieves the argument as an Integer object, if any, of an option. * * @param option the option that we want argument value to be returned for * @param defaultValue is the default value to be returned if the option is not specified * * @return Value of the argument if option is set, and has an argument, otherwise defaultValue. * @throws NumberFormatException if there are problems parsing the option value into the Integer type */ public Integer getIntegerValue(Option option, Integer defaultValue) throws NumberFormatException { Integer answer = getIntegerValue(option); return (answer != null) ? answer : defaultValue; }
/** * Retrieves the argument as an Integer object, if any, of an option. * * @param option the option that we want argument value to be returned for * @param defaultValue is the default value to be returned if the option is not specified * * @return Value of the argument if option is set, and has an argument, otherwise defaultValue. * @throws NumberFormatException if there are problems parsing the option value into the Integer type */ public Integer getIntegerValue(Option option, Integer defaultValue) throws NumberFormatException { Integer answer = getIntegerValue(option); return (answer != null) ? answer : defaultValue; }
/** * Retrieves the argument as an Integer object, if any, of an option and validates it against minimum and maximum allowed values. * * @param option the option that we want argument value to be returned for * @param defaultValue is the default value to be returned if the option is not specified * @param minValue the minimum allowed Integer value for the option * @param maxValue the maximum allowed Integer value for the option * * @return Value of the argument if option is set, and has an argument, otherwise defaultValue. * @throws IllegalArgumentException if there are problems with the option value */ public Integer getIntegerValue(Option option, Integer defaultValue, Integer minValue, Integer maxValue) throws IllegalArgumentException { Integer answer = getIntegerValue(option, defaultValue); if (answer != null) { Assert.isTrue(answer.compareTo(minValue) >= 0, String.format("The %s option value %d is less than the minimum allowed value of %d.", option.getLongOpt(), answer, minValue)); Assert.isTrue(answer.compareTo(maxValue) <= 0, String.format("The %s option value %d is bigger than maximum allowed value of %d.", option.getLongOpt(), answer, maxValue)); } return answer; }
maxRetryAttempts = argParser.getIntegerValue(maxRetryAttemptsOpt, MAX_RETRY_ATTEMPTS_DEFAULT, MAX_RETRY_ATTEMPTS_MIN, MAX_RETRY_ATTEMPTS_MAX); retryDelaySecs = argParser.getIntegerValue(retryDelaySecsOpt, RETRY_DELAY_SECS_DEFAULT, RETRY_DELAY_SECS_MIN, RETRY_DELAY_SECS_MAX);
/** * Retrieves the argument as an Integer object, if any, of an option and validates it against minimum and maximum allowed values. * * @param option the option that we want argument value to be returned for * @param defaultValue is the default value to be returned if the option is not specified * @param minValue the minimum allowed Integer value for the option * @param maxValue the maximum allowed Integer value for the option * * @return Value of the argument if option is set, and has an argument, otherwise defaultValue. * @throws IllegalArgumentException if there are problems with the option value */ public Integer getIntegerValue(Option option, Integer defaultValue, Integer minValue, Integer maxValue) throws IllegalArgumentException { Integer answer = getIntegerValue(option, defaultValue); if (answer != null) { Assert.isTrue(answer.compareTo(minValue) >= 0, String.format("The %s option value %d is less than the minimum allowed value of %d.", option.getLongOpt(), answer, minValue)); Assert.isTrue(answer.compareTo(maxValue) <= 0, String.format("The %s option value %d is bigger than maximum allowed value of %d.", option.getLongOpt(), answer, maxValue)); } return answer; }
regServerPort = argParser.getIntegerValue(regServerPortOpt); if (regServerPort == null) regServerPort = argParser.getIntegerValue(dmRegServerPortOpt); if (regServerPort == null) if (argParser.getIntegerValue(dmRegServerPortOpt) != null) httpProxyPort = argParser.getIntegerValue(httpProxyPortOpt); maxThreads = argParser.getIntegerValue(maxThreadsOpt, ToolsCommonConstants.DEFAULT_THREADS);
regServerPort = argParser.getIntegerValue(regServerPortOpt); if (regServerPort == null) regServerPort = argParser.getIntegerValue(dmRegServerPortOpt); if (regServerPort == null) if (argParser.getIntegerValue(dmRegServerPortOpt) != null) httpProxyPort = argParser.getIntegerValue(httpProxyPortOpt); maxThreads = argParser.getIntegerValue(maxThreadsOpt, ToolsCommonConstants.DEFAULT_THREADS);
@Test public void testGetIntegerNullValue() throws ParseException { // Create an argument parser with an optional "a" option. ArgumentParser argParser = new ArgumentParser(""); Option option = argParser.addArgument("a", "some_required_parameter", false, "Some required parameter with an argument", false); // Parse the arguments and get an integer value which wasn't specified which should return null. argParser.parseArguments(new String[] {}); Integer value = argParser.getIntegerValue(option, null, 0, 100); assertNull(value); }
regServerPort = argParser.getIntegerValue(regServerPortOpt);
assertNull(argParser.getIntegerValue(intOpt)); assertEquals(testDefaultValue, argParser.getIntegerValue(intOpt, testDefaultValue)); resultValue = argParser.getIntegerValue(intOpt); assertNotNull(resultValue); assertEquals(inputValue, resultValue); resultValue = argParser.getIntegerValue(intOpt, testDefaultValue); assertNotNull(resultValue); assertEquals(inputValue, resultValue); resultValue = argParser.getIntegerValue(intOpt); assertNotNull(resultValue); assertEquals(inputValue, resultValue); resultValue = argParser.getIntegerValue(intOpt, testDefaultValue, testMinValue, testMaxValue); assertNotNull(resultValue); assertEquals(inputValue, resultValue); resultValue = argParser.getIntegerValue(intOpt, testDefaultValue, testMinValue, testMaxValue); assertNotNull(resultValue); assertEquals(testDefaultValue, resultValue); resultValue = argParser.getIntegerValue(intOpt, testDefaultValue, testMinValue, testMaxValue); assertNotNull(resultValue); assertEquals(testMinValue, resultValue); resultValue = argParser.getIntegerValue(intOpt, testDefaultValue, testMinValue, testMaxValue); assertNotNull(resultValue);
regServerPort = argParser.getIntegerValue(regServerPortOpt);
.withAwsAccessKeyId(argParser.getStringValue(s3AccessKeyOpt)).withAwsSecretKey(argParser.getStringValue(s3SecretKeyOpt)) .withS3Endpoint(argParser.getStringValue(s3EndpointOpt)).withMaxThreads(maxThreads).withHttpProxyHost(argParser.getStringValue(httpProxyHostOpt)) .withHttpProxyPort(httpProxyPort).withSocketTimeout(argParser.getIntegerValue(socketTimeoutOpt)).build();
.withS3Endpoint(argParser.getStringValue(s3EndpointOpt)).withMaxThreads(maxThreads) .withHttpProxyHost(argParser.getStringValue(httpProxyHostOpt)).withHttpProxyPort(httpProxyPort) .withSocketTimeout(argParser.getIntegerValue(socketTimeoutOpt)).build();