@Deprecated public String get( String key, String defaultValue ) { String value = getSingleOptionOrNull( key ); return value != null ? value : defaultValue; }
/** * Get a config option by name. * @param key name of the option, without any `-` or `--` prefix, eg. "o". * @return the string value of the option, or null if the user has not specified it */ @Deprecated public String get( String key ) { return getSingleOptionOrNull( key ); }
@Deprecated public Number getNumber( String key, Number defaultValue ) { String value = getSingleOptionOrNull( key ); return value != null ? Double.valueOf( value ) : defaultValue; }
@Deprecated public String get( String key, String defaultValueIfNotFound, String defaultValueIfNoValue ) { String value = getSingleOptionOrNull( key ); if ( value != null ) { return value; } return this.map.containsKey( key ) ? defaultValueIfNoValue : defaultValueIfNotFound; }
@Deprecated public long getDuration( String key, long defaultValueInMillis ) { String value = getSingleOptionOrNull( key ); return value != null ? TimeUtil.parseTimeMillis.apply(value) : defaultValueInMillis; }
@Deprecated public <T extends Enum<T>> T getEnum( Class<T> enumClass, String key, T defaultValue ) { String raw = getSingleOptionOrNull( key ); if ( raw == null ) { return defaultValue; } for ( T candidate : enumClass.getEnumConstants() ) { if ( candidate.name().equals( raw ) ) { return candidate; } } throw new IllegalArgumentException( "No enum instance '" + raw + "' in " + enumClass.getName() ); }
/** * Parses a {@code boolean} argument. There are a couple of cases: * <ul> * <li>The argument isn't specified. In this case the value of {@code defaultValueIfNotSpecified} * will be returned.</li> * <li>The argument is specified without value, for example <pre>--myboolean</pre>. In this case * the value of {@code defaultValueIfNotSpecified} will be returned.</li> * <li>The argument is specified with value, for example <pre>--myboolean=true</pre>. * In this case the actual value will be returned.</li> * </ul> * * @param key argument key. * @param defaultValueIfNotSpecified used if argument not specified. * @param defaultValueIfSpecifiedButNoValue used if argument specified w/o value. * @return argument boolean value depending on what was specified, see above. */ @Deprecated public Boolean getBoolean( String key, Boolean defaultValueIfNotSpecified, Boolean defaultValueIfSpecifiedButNoValue ) { String value = getSingleOptionOrNull( key ); if ( value != null ) { return Boolean.valueOf( value ); } return this.map.containsKey( key ) ? defaultValueIfSpecifiedButNoValue : defaultValueIfNotSpecified; }
@Deprecated public String get( String key, String defaultValue ) { String value = getSingleOptionOrNull( key ); return value != null ? value : defaultValue; }
/** * Get a config option by name. * @param key name of the option, without any `-` or `--` prefix, eg. "o". * @return the string value of the option, or null if the user has not specified it */ @Deprecated public String get( String key ) { return getSingleOptionOrNull( key ); }
@Deprecated public Number getNumber( String key, Number defaultValue ) { String value = getSingleOptionOrNull( key ); return value != null ? Double.valueOf( value ) : defaultValue; }
@Deprecated public String get( String key, String defaultValueIfNotFound, String defaultValueIfNoValue ) { String value = getSingleOptionOrNull( key ); if ( value != null ) { return value; } return this.map.containsKey( key ) ? defaultValueIfNoValue : defaultValueIfNotFound; }
@Deprecated public long getDuration( String key, long defaultValueInMillis ) { String value = getSingleOptionOrNull( key ); return value != null ? TimeUtil.parseTimeMillis.apply(value) : defaultValueInMillis; }
@Deprecated public <T extends Enum<T>> T getEnum( Class<T> enumClass, String key, T defaultValue ) { String raw = getSingleOptionOrNull( key ); if ( raw == null ) { return defaultValue; } for ( T candidate : enumClass.getEnumConstants() ) { if ( candidate.name().equals( raw ) ) { return candidate; } } throw new IllegalArgumentException( "No enum instance '" + raw + "' in " + enumClass.getName() ); }
/** * Parses a {@code boolean} argument. There are a couple of cases: * <ul> * <li>The argument isn't specified. In this case the value of {@code defaultValueIfNotSpecified} * will be returned.</li> * <li>The argument is specified without value, for example <pre>--myboolean</pre>. In this case * the value of {@code defaultValueIfNotSpecified} will be returned.</li> * <li>The argument is specified with value, for example <pre>--myboolean=true</pre>. * In this case the actual value will be returned.</li> * </ul> * * @param key argument key. * @param defaultValueIfNotSpecified used if argument not specified. * @param defaultValueIfSpecifiedButNoValue used if argument specified w/o value. * @return argument boolean value depending on what was specified, see above. */ @Deprecated public Boolean getBoolean( String key, Boolean defaultValueIfNotSpecified, Boolean defaultValueIfSpecifiedButNoValue ) { String value = getSingleOptionOrNull( key ); if ( value != null ) { return Boolean.valueOf( value ); } return this.map.containsKey( key ) ? defaultValueIfSpecifiedButNoValue : defaultValueIfNotSpecified; }