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_CHECK  
    static java.util.function.Function<java.lang.Number,​java.util.function.Function<java.lang.String,​java.lang.String>> LIMIT_VALUE_CHECK
    Checker for value to be positive, zero or -1
    static java.util.function.Function<java.lang.Number,​java.util.function.Function<java.lang.String,​java.lang.String>> PERCENT_VALUE_CHECK  
    static java.util.function.Function<java.lang.Number,​java.util.function.Function<java.lang.String,​java.lang.String>> POSITIVE_VALUE_CHECK
    Checker for positive value
    static java.util.function.Function<java.lang.String,​java.time.Duration> TO_DURATION_BOUND_PARSER  
    static 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 double getDoubleOption​(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.Double defVal, java.lang.String valueName)  
    static double getDoubleOption​(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String name)  
    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)  
    static int getIntOption​(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.Integer defVal, java.lang.String valueName)  
    static int getIntOption​(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String name)  
    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)  
    static long getLongOption​(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.Long defVal, java.lang.String valueName)  
    static long getLongOption​(org.apache.commons.cli.CommandLine line, java.lang.String optionName, java.lang.String name)  
    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)  
    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)  
    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.PrintStream getPrintStream​(org.apache.commons.cli.CommandLine line, boolean stdOutAsDefault, java.lang.String fileOptionName)  
    static java.io.PrintStream getPrintStream​(org.apache.commons.cli.CommandLine line, java.lang.String fileOptionName)  
    static java.io.BufferedReader getReader​(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.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)  
    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)  
    static LogPrintStream parseProgressOutputStream​(org.apache.commons.cli.CommandLine line, java.lang.String optionName)  
    static long parseSize​(java.lang.String str)  
    static Verbosity parseVerbosity​(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_CHECK
      Checker 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_CHECK
      Checker 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

      public static Verbosity parseVerbosity​(org.apache.commons.cli.CommandLine cmd)
    • 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 InvalidOptionException
      Parse 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 line
      optionName - 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 InvalidOptionException
      Parse 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 line
      optionName - option name
      defaultValue - 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 InvalidOptionException
      Parse 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 line
      optionName - option name
      defaultValue - default value. If default value is null - IllegalArgumentException will be thrown if option is not set
      parser - string-to-object parser
      arrayGenerator - 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