Package org.refcodes.console
Class ConsoleUtility
- java.lang.Object
-
- org.refcodes.console.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 givenString
is contained in the givenString
array.static org.refcodes.structure.Relation<java.lang.String,java.lang.String>
getOptionArgument(Option<?> aOption, java.lang.String[] args)
static boolean
isOptionArgument(java.lang.String aArg)
Determines whether the providedString
starts with one of the prefixes Identifying anOption
.static java.lang.String[]
toArgs(java.util.List<? extends Operand<?>>... aOperands)
Takes allOperand
instances found in the providedList
s and adds all therein found argument arrays (as ofOperand.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 providedList
s therein found argument arrays subset (as ofOperand.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 providedOperand
;.static java.lang.String
toParameterSpec(Operand<?> aOperand)
Creates the parameter specification from the providedOperand
.static java.lang.String
toSpec(Operand<?> aOperand)
Creates a specification for the givenOperand
consisting of the options specification (if any) as oftoOptionsSpec(Operand)
and the parameter specification (if any) as oftoParameterSpec(Operand)
.
-
-
-
Method Detail
-
contains
public static boolean contains(java.lang.String[] aArgs, java.lang.String aArg)
Determines whether a givenString
is contained in the givenString
array.- Parameters:
aArgs
- TheString
array to be tested whether it contains the givenString
.aArg
- TheString
to be tested whether it is contained in the providedString
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 providedString
starts with one of the prefixes Identifying anOption
. The prefixes are defined in theCommandArgPrefix
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[] args)
Takes theOption
's short-option and long-option and tries to determine thatOption
'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 theRelation
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 valueargs
- The command line arguments from which to determine theOption
's 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 allOperand
instances found in the providedList
s and adds all therein found argument arrays (as ofOperand.getArgs()
) to the result.
-
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 providedList
s therein found argument arrays subset (as ofOperand.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 theOperand
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 providedOperand
. In case we got aFlag
, then there will be an empty parameter specification as theFlag
implies a parameter. If theOperand
is an option, then the parameter will be prefixed and suffixed different to anOperand
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 providedOperand
;.- 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 givenOperand
consisting of the options specification (if any) as oftoOptionsSpec(Operand)
and the parameter specification (if any) as oftoParameterSpec(Operand)
.- Parameters:
aOperand
- TheOperand
from which to create the specification.- Returns:
- The specification.
-
-