Package org.xblackcat.sjpu.cli
Class OptionUtils
java.lang.Object
org.xblackcat.sjpu.cli.OptionUtils
public class OptionUtils
extends java.lang.Object
-
Field Summary
Fields Modifier and Type Field Description static java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>>ANY_VALUE_CHECKstatic java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>>LIMIT_VALUE_CHECKChecker for value to be positive, zero or -1static java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>>PERCENT_VALUE_CHECKstatic java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>>POSITIVE_VALUE_CHECKChecker for positive valuestatic java.util.function.Function<java.lang.String,java.time.Duration>TO_DURATION_BOUND_PARSERstatic java.util.function.Function<java.lang.String,java.time.LocalDateTime>TO_TIME_PERIOD_BOUND_PARSER -
Constructor Summary
Constructors Constructor Description OptionUtils() -
Method Summary
Modifier and Type Method Description static Bounds<java.lang.Integer>getBounds(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String description, int defaultLowerBound, int defaultUpperBound)static <T extends java.lang.Comparable<? super T>>
Bounds<T>getBounds(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String description, java.util.function.Function<java.lang.String,T> convert, java.lang.String defaultLowerBound, java.lang.String defaultUpperBound)static <T extends java.lang.Comparable<? super T>>
Bounds<T>getBounds(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String description, java.util.function.Function<java.lang.String,T> convert, T defaultLowerBound, T defaultUpperBound)static doublegetDoubleOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.Double defVal, java.lang.String valueName)static doublegetDoubleOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String name)static doublegetDoubleOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.util.function.Function<java.lang.Number,java.lang.Double> valueChecker, java.lang.Double defVal, java.lang.String valueName)static intgetIntOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.Integer defVal, java.lang.String valueName)static intgetIntOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String name)static intgetIntOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>> valueChecker, java.lang.Integer defVal, java.lang.String valueName)static longgetLongOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.Long defVal, java.lang.String valueName)static longgetLongOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String name)static longgetLongOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>> valueTester, java.lang.Long defVal, java.lang.String valueName)static <T extends java.lang.Number>
TgetNumericOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.util.function.Function<java.lang.Number,T> fieldExtractor, java.util.function.Function<? super T,java.util.function.Function<java.lang.String,java.lang.String>> valueTester, T defVal, java.lang.String valueName)static <T> T[]getObjectList(org.apache.commons.cli.CommandLine line, java.lang.String optionName, T[] defaultValue, java.util.function.Function<java.lang.String,T> parser, java.util.function.IntFunction<T[]> arrayGenerator)Parse option from command line to read list of custom objects.static java.io.PrintStreamgetPrintStream(org.apache.commons.cli.CommandLine line, boolean stdOutAsDefault, java.lang.String fileOptionName)static java.io.PrintStreamgetPrintStream(org.apache.commons.cli.CommandLine line, java.lang.String fileOptionName)static java.io.BufferedReadergetReader(org.apache.commons.cli.CommandLine line, java.lang.String optionName)static java.lang.String[]getStringList(org.apache.commons.cli.CommandLine line, java.lang.String optionName)Parse option from command line to read string list.static java.lang.String[]getStringList(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String[] defaultValue)Parse option from command line to read string list.static java.util.Set<java.lang.String>getStringsAsSet(org.apache.commons.cli.CommandLine cmd, java.lang.String opt)static org.apache.commons.cli.CommandLineparseCommandLine(java.lang.String[] args, boolean showHelpWithoutArgs, org.apache.commons.cli.Options options, java.lang.String cmdLineSyntax, java.lang.String description, java.lang.String... requiredAnyOpt)static org.apache.commons.cli.CommandLineparseCommandLine(java.lang.String[] args, org.apache.commons.cli.Options options, java.lang.String cmdLineSyntax, java.lang.String description, java.lang.String... requiredAnyOpt)static LogPrintStreamparseProgressOutputStream(org.apache.commons.cli.CommandLine line, java.lang.String optionName)static longparseSize(java.lang.String str)static VerbosityparseVerbosity(org.apache.commons.cli.CommandLine cmd)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
POSITIVE_VALUE_CHECK
public static final java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>> POSITIVE_VALUE_CHECKChecker for positive value -
LIMIT_VALUE_CHECK
public static final java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>> LIMIT_VALUE_CHECKChecker for value to be positive, zero or -1 -
ANY_VALUE_CHECK
public static final java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>> ANY_VALUE_CHECK -
PERCENT_VALUE_CHECK
public static final java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>> PERCENT_VALUE_CHECK -
TO_TIME_PERIOD_BOUND_PARSER
public static java.util.function.Function<java.lang.String,java.time.LocalDateTime> TO_TIME_PERIOD_BOUND_PARSER -
TO_DURATION_BOUND_PARSER
public static java.util.function.Function<java.lang.String,java.time.Duration> TO_DURATION_BOUND_PARSER
-
-
Constructor Details
-
OptionUtils
public OptionUtils()
-
-
Method Details
-
parseProgressOutputStream
public static LogPrintStream parseProgressOutputStream(org.apache.commons.cli.CommandLine line, java.lang.String optionName) throws InvalidOptionException- Throws:
InvalidOptionException
-
parseVerbosity
-
getReader
public static java.io.BufferedReader getReader(org.apache.commons.cli.CommandLine line, java.lang.String optionName) throws java.io.IOException- Throws:
java.io.IOException
-
getPrintStream
public static java.io.PrintStream getPrintStream(org.apache.commons.cli.CommandLine line, java.lang.String fileOptionName) throws java.io.IOException- Throws:
java.io.IOException
-
getPrintStream
public static java.io.PrintStream getPrintStream(org.apache.commons.cli.CommandLine line, boolean stdOutAsDefault, java.lang.String fileOptionName) throws java.io.IOException- Throws:
java.io.IOException
-
getBounds
public static <T extends java.lang.Comparable<? super T>> Bounds<T> getBounds(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String description, java.util.function.Function<java.lang.String,T> convert, java.lang.String defaultLowerBound, java.lang.String defaultUpperBound) throws InvalidOptionException- Throws:
InvalidOptionException
-
getBounds
public static <T extends java.lang.Comparable<? super T>> Bounds<T> getBounds(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String description, java.util.function.Function<java.lang.String,T> convert, T defaultLowerBound, T defaultUpperBound) throws InvalidOptionException- Throws:
InvalidOptionException
-
getBounds
public static Bounds<java.lang.Integer> getBounds(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String description, int defaultLowerBound, int defaultUpperBound) throws InvalidOptionException- Throws:
InvalidOptionException
-
getStringList
public static java.lang.String[] getStringList(org.apache.commons.cli.CommandLine line, java.lang.String optionName) throws InvalidOptionExceptionParse option from command line to read string list. Values could be specified as comma-separated argument of option or file name. To pass file name as source of string list use @ prefix for option value. IllegalArgumentException will be thrown if option is not set. Examples:-<option> "value1,value2,value3"
-<option> "@source_file_name"
- Parameters:
line- parsed command lineoptionName- option name- Returns:
- string list parsed from argument or read from external file
- Throws:
InvalidOptionException
-
getStringList
public static java.lang.String[] getStringList(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String[] defaultValue) throws InvalidOptionExceptionParse option from command line to read string list. Values could be specified as comma-separated argument of option or file name. To pass file name as source of string list use @ prefix for option value. Examples:-<option> "value1,value2,value3"
-<option> "@source_file_name"
- Parameters:
line- parsed command lineoptionName- option namedefaultValue- default value. If default value is null - IllegalArgumentException will be thrown if option is not set- Returns:
- string list parsed from argument or read from external file
- Throws:
InvalidOptionException
-
getObjectList
public static <T> T[] getObjectList(org.apache.commons.cli.CommandLine line, java.lang.String optionName, T[] defaultValue, java.util.function.Function<java.lang.String,T> parser, java.util.function.IntFunction<T[]> arrayGenerator) throws InvalidOptionExceptionParse option from command line to read list of custom objects. Values could be specified as comma-separated argument of option or file name. To pass file name as source of string list use @ prefix for option value. Examples:-<option> "value1,value2,value3"
-<option> "@source_file_name"
Values are parsed by parser function and arrayGenerator should provide correct result array for storing values.
- Parameters:
line- parsed command lineoptionName- option namedefaultValue- default value. If default value is null - IllegalArgumentException will be thrown if option is not setparser- string-to-object parserarrayGenerator- result array generator- Returns:
- string list parsed from argument or read from external file
- Throws:
InvalidOptionException
-
getIntOption
public static int getIntOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String name) throws org.apache.commons.cli.ParseException- Throws:
org.apache.commons.cli.ParseException
-
getIntOption
public static int getIntOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.Integer defVal, java.lang.String valueName) throws org.apache.commons.cli.ParseException- Throws:
org.apache.commons.cli.ParseException
-
getIntOption
public static int getIntOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>> valueChecker, java.lang.Integer defVal, java.lang.String valueName) throws org.apache.commons.cli.ParseException- Throws:
org.apache.commons.cli.ParseException
-
getLongOption
public static long getLongOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String name) throws org.apache.commons.cli.ParseException- Throws:
org.apache.commons.cli.ParseException
-
getLongOption
public static long getLongOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.Long defVal, java.lang.String valueName) throws org.apache.commons.cli.ParseException- Throws:
org.apache.commons.cli.ParseException
-
getLongOption
public static long getLongOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.util.function.Function<java.lang.Number,java.util.function.Function<java.lang.String,java.lang.String>> valueTester, java.lang.Long defVal, java.lang.String valueName) throws org.apache.commons.cli.ParseException- Throws:
org.apache.commons.cli.ParseException
-
getDoubleOption
public static double getDoubleOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String name) throws org.apache.commons.cli.ParseException- Throws:
org.apache.commons.cli.ParseException
-
getDoubleOption
public static double getDoubleOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.Double defVal, java.lang.String valueName) throws org.apache.commons.cli.ParseException- Throws:
org.apache.commons.cli.ParseException
-
getDoubleOption
public static double getDoubleOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.util.function.Function<java.lang.Number,java.lang.Double> valueChecker, java.lang.Double defVal, java.lang.String valueName) throws org.apache.commons.cli.ParseException- Throws:
org.apache.commons.cli.ParseException
-
getNumericOption
public static <T extends java.lang.Number> T getNumericOption(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.util.function.Function<java.lang.Number,T> fieldExtractor, java.util.function.Function<? super T,java.util.function.Function<java.lang.String,java.lang.String>> valueTester, T defVal, java.lang.String valueName) throws org.apache.commons.cli.ParseException- Throws:
org.apache.commons.cli.ParseException
-
parseCommandLine
public static org.apache.commons.cli.CommandLine parseCommandLine(java.lang.String[] args, org.apache.commons.cli.Options options, java.lang.String cmdLineSyntax, java.lang.String description, java.lang.String... requiredAnyOpt) -
parseCommandLine
public static org.apache.commons.cli.CommandLine parseCommandLine(java.lang.String[] args, boolean showHelpWithoutArgs, org.apache.commons.cli.Options options, java.lang.String cmdLineSyntax, java.lang.String description, java.lang.String... requiredAnyOpt) -
getStringsAsSet
public static java.util.Set<java.lang.String> getStringsAsSet(org.apache.commons.cli.CommandLine cmd, java.lang.String opt) -
parseSize
public static long parseSize(java.lang.String str) throws java.lang.NumberFormatException- Throws:
java.lang.NumberFormatException
-