Class ConsoleUtility



  • public final class ConsoleUtility
    extends java.lang.Object
    This utility class provides method useful for the refcodes-console artifact and whose implementation has been motivated by the implementation of the refcodes-console artifact.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean contains​(java.lang.String[] aArgs, java.lang.String aArg)
      Determines whether a given String is contained in the given String array.
      static org.refcodes.structure.Relation<java.lang.String,java.lang.String> getOptionArgument​(Option<?> aOption, java.lang.String[] aArgs, java.lang.String[] aOptions)
      Takes the Option's short-option and long-option and tries to determine that Option's value in the provided command line arguments.
      static boolean isOptionArgument​(java.lang.String aArg)
      Determines whether the provided String starts with one of the prefixes Identifying an Option.
      static java.lang.String[] toArgs​(java.util.List<? extends Operand<?>>... aOperands)
      Takes all Operand instances found in the provided Lists and adds all therein found argument arrays (as of Operand.getArgs()) to the result.
      static java.lang.String[] toDiff​(java.lang.String[] aSet, java.lang.String[] aSubset)
      Creates the difference between the provided set and the provided subset.
      static java.lang.String[] toDiff​(java.lang.String[] aSet, java.util.List<? extends Operand<?>> aSubset)
      Creates the difference between the provided set and the provided Lists therein found argument arrays subset (as of Operand.getArgs()).
      static java.lang.String toOptionsSpec​(Operand<?> aOperand)
      Creates the options specification containing the short option (if any) and the long option ( if any) from the provided Operand;.
      static java.lang.String toParameterSpec​(Operand<?> aOperand)
      Creates the parameter specification from the provided Operand.
      static java.lang.String toSpec​(Operand<?> aOperand)
      Creates a specification for the given Operand consisting of the options specification (if any) as of toOptionsSpec(Operand) and the parameter specification (if any) as of toParameterSpec(Operand).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • contains

        public static boolean contains​(java.lang.String[] aArgs,
                                       java.lang.String aArg)
        Determines whether a given String is contained in the given String array.
        Parameters:
        aArgs - The String array to be tested whether it contains the given String.
        aArg - The String to be tested whether it is contained in the provided String array.
        Returns:
        True in case the String is contained in the array, else false.
      • isOptionArgument

        public static boolean isOptionArgument​(java.lang.String aArg)
        Determines whether the provided String starts with one of the prefixes Identifying an Option. The prefixes are defined in the CommandArgPrefix enumeration and are usually the single hyphen-minus "-" and the double hyphen-minus "--". Usually option arguments are prefixed either with a
        Parameters:
        aArg - The argument for which to determines whether it represents an option argument or not.
        Returns:
        True, in case the provided argument is an option argument.
      • getOptionArgument

        public static org.refcodes.structure.Relation<java.lang.String,java.lang.String> getOptionArgument​(Option<?> aOption,
                                                                                                           java.lang.String[] aArgs,
                                                                                                           java.lang.String[] aOptions)
        Takes the Option's short-option and long-option and tries to determine that Option's value in the provided command line arguments. Depending on whether the short-option or the long-option was detected with a value, the result contains the according option as the key with the detected value in the Relation instance. Null is returned when either no option was found or no value for one of the options.
        Parameters:
        aOption - The option for which to get the value
        aArgs - The command line arguments from which to determine the Option's value.
        aOptions - The list of options (short and well as long) which are reserved and cannot be used as value.
        Returns:
        A key/value-pair containing the detected (short / long) option alongside the detected value.
      • toArgs

        @SafeVarargs
        public static java.lang.String[] toArgs​(java.util.List<? extends Operand<?>>... aOperands)
        Takes all Operand instances found in the provided Lists and adds all therein found argument arrays (as of Operand.getArgs()) to the result.
        Parameters:
        aOperands - The lists containing the Operand instances whose command line arguments are to be added to the result.
        Returns:
        All the command line arguments detected in the provided Operands Lists.
      • toDiff

        public static java.lang.String[] toDiff​(java.lang.String[] aSet,
                                                java.lang.String[] aSubset)
        Creates the difference between the provided set and the provided subset.
        Parameters:
        aSet - The set to be used for the diff operation.
        aSubset - The subset to be used for the diff operation.
        Returns:
        The difference between the set and the subset.
      • toDiff

        public static java.lang.String[] toDiff​(java.lang.String[] aSet,
                                                java.util.List<? extends Operand<?>> aSubset)
        Creates the difference between the provided set and the provided Lists therein found argument arrays subset (as of Operand.getArgs()).
        Parameters:
        aSet - The set to be used for the diff operation.
        aSubset - The subset to be used for the diff operation being the lists containing the Operand instances whose command line arguments are to be diffed.
        Returns:
        The difference between the set and the subset.
      • toParameterSpec

        public static java.lang.String toParameterSpec​(Operand<?> aOperand)
        Creates the parameter specification from the provided Operand. In case we got a Flag, then there will be an empty parameter specification as the Flag implies a parameter. If the Operand is an option, then the parameter will be prefixed and suffixed different to an Operand type.
        Parameters:
        aOperand - The operand from which to get the parameter specification.
        Returns:
        The parameter specification.
      • toOptionsSpec

        public static java.lang.String toOptionsSpec​(Operand<?> aOperand)
        Creates the options specification containing the short option (if any) and the long option ( if any) from the provided Operand;.
        Parameters:
        aOperand - The operand from which to create the options specification.
        Returns:
        The options specification String.
      • toSpec

        public static java.lang.String toSpec​(Operand<?> aOperand)
        Creates a specification for the given Operand consisting of the options specification (if any) as of toOptionsSpec(Operand) and the parameter specification (if any) as of toParameterSpec(Operand).
        Parameters:
        aOperand - The Operand from which to create the specification.
        Returns:
        The specification.