public class CmdLineUtils extends Object
public static Set<CmdLineOption> determineRequired(CmdLineAction action, Set<CmdLineOption> options)
CmdLineOption
s are either always
required and are required because the given CmdLineAction
was
specified.action
- The CmdLineAction
which was specified.options
- The CmdLineOption
s in question of being required or not.Set
of CmdLineOption
s which are either always
required or are required because the given CmdLineAction
was specified.public static Set<CmdLineOption> determineRequired(CmdLineAction action, Set<CmdLineOption> options, boolean ignoreActionOption)
public static Set<CmdLineOption> determineRelevantSubOptions(CmdLineAction action, GroupCmdLineOption option)
GroupCmdLineOption
's sub-options which
affect the given CmdLineAction
.action
- The CmdLineAction
for which given
GroupCmdLineOption
's sub-options will be determined
relevant or notoption
- The GroupCmdLineOption
whose sub-options are in question
of being relevant to the given CmdLineAction
GroupCmdLineOption
's sub-options who are relevant to
given CmdLineAction
public static Set<CmdLineOption> determineRequiredSubOptions(GroupCmdLineOption option)
GroupCmdLineOption
who are
always required.option
- The GroupCmdLineOption
whose sub-options are check where
they are requiredGroupCmdLineOption
public static Set<CmdLineOption> determineRequiredSubOptions(CmdLineAction action, GroupCmdLineOption option)
GroupCmdLineOption
who are
either always required for become requried when given
CmdLineAction
is specified.action
- The specified CmdLineAction
option
- The GroupCmdLineOption
whose sub-options are checked if
they are requiredGroupCmdLineOption
's required sub-optionspublic static boolean isRequired(CmdLineAction action, CmdLineOption option)
CmdLineOption
is required because the
given CmdLineAction
was specified or because it is always required.action
- The CmdLineAction
which was specified.option
- The CmdLineOption
in question of being required or not.public static Set<CmdLineOption> determineOptional(CmdLineAction action, Set<CmdLineOption> options)
CmdLineOption
s are optional because
the given CmdLineAction
was specified.action
- The CmdLineAction
which was specified.options
- The CmdLineOption
in question of being optional or not.Set
of CmdLineOption
s where are optional
because the given CmdLineAction
was specified.public static boolean isOptional(CmdLineAction action, CmdLineOption option)
CmdLineOption
is optional either because
it is always optional or because the given CmdLineAction
was
specified.action
- The CmdLineAction
which was specified.option
- The CmdLineOption
in question of being optional or not.public static boolean isStrictlyOptional(CmdLineAction action, CmdLineOption option)
CmdLineOption
is optional ONLY because the
given CmdLineAction
was specified.action
- The CmdLineAction
which was specified.option
- The CmdLineOption
in question of being optional or not.public static Set<CmdLineOption> getRequiredOptions(Set<CmdLineOption> options)
CmdLineOption
s which are always required regardless of
CmdLineAction
specified. NOTE: Ignores CmdLineOption
s of
type ActionCmdLineOption
.options
- The CmdLineOption
S to check for required
CmdLineOption
sCmdLineOption
s which will be check for always required
CmdLineOption
spublic static Set<CmdLineOption> getRequiredOptions(Set<CmdLineOption> options, boolean ignoreActionOption)
CmdLineOption
s which are always required regardless of
CmdLineAction
specified.options
- The CmdLineOption
S to check for required
CmdLineOption
signoreActionOption
- Where or not to ignore CmdLineOption
s of type
ActionCmdLineOption
CmdLineOption
s which will be check for always required
CmdLineOption
spublic static List<CmdLineOption> sortOptionsByRequiredStatus(Set<CmdLineOption> options)
CmdLineOption
s by requirement levels. CmdLineOption
s
which are always required have highest sort score, followed by
CmdLineOption
s which have RequirementRule
s, followed by
all others.options
- The Set
of CmdLineOption
s to sort.CmdLineOption
s sorted by requirement.public static List<CmdLineOption> sortOptions(Set<CmdLineOption> options)
CmdLineOption
s by there long name.options
- The CmdLineOption
s to be sortedList
of CmdLineOption
spublic static List<CmdLineAction> sortActions(Set<CmdLineAction> actions)
CmdLineAction
s by there name.actions
- The CmdLineAction
s to be sortedList
of CmdLineAction
spublic static CmdLineOption getOptionByName(String optionName, Set<CmdLineOption> options)
CmdLineOption
whose short name or long name equals given
option name.optionName
- The short or long name of the CmdLineOption
to findoptions
- The CmdLineOption
s to search inCmdLineOption
found or null if not found.public static CmdLineOptionInstance getOptionInstanceByName(String optionName, Set<CmdLineOptionInstance> optionInsts)
CmdLineOptionInstance
whose CmdLineOption
's short
name or long name equals given option name.optionName
- The short or long name of the CmdLineOptionInstance
's
CmdLineOption
to findoptionInsts
- The CmdLineOptionIntance
s to search inCmdLineOptionInstance
found or null if not found.public static boolean isSubOption(CmdLineOption option, CmdLineOption subOption)
CmdLineOption
is a sub-option of other given
CmdLineOption
.option
- CmdLineOption
which is being checked if the other given
CmdLineOption
is one of its sub-optionssubOption
- The CmdLineOption
which is being check if it is a
sub-option of the other given CmdLineOption
public static Set<CmdLineOptionInstance> findPerformAndQuitOptions(Set<CmdLineOptionInstance> options)
CmdLineOptionInstance
s from
the given Set
of CmdLineOptionInstance
s.options
- The Set
of CmdLineOptionInstance
who will be
check for perform-and-quit CmdLineOptionInstance
sCmdLineOptionInstance
s foundpublic static boolean isPerformAndQuitOption(CmdLineOption option)
CmdLineOption
is a perform-and-quit type
CmdLineOption
.option
- The CmdLineOption
being checked if it is
perform-and-quit type.CmdLineOption
is a perform-and-quit type, false
otherwise.public static CmdLineOptionInstance findSpecifiedOption(CmdLineOption option, Set<CmdLineOptionInstance> specifiedOptions)
option
- The CmdLineOption
to find.specifiedOptions
- The CmdLineOptionInstance
whose CmdLineOption
is
the given CmdLineOption
CmdLineOptionInstance
whose
CmdLineOption
is the given CmdLineOption
, or null
if not foundpublic static Set<CmdLineOptionInstance> findAllOfSpecifiedOption(CmdLineOption option, Set<CmdLineOptionInstance> specifiedOptions)
option
- The CmdLineOption
to find.specifiedOptions
- The CmdLineOptionInstance
whose CmdLineOption
is
the given CmdLineOption
CmdLineOptionInstance
s whose CmdLineOption
is
the given CmdLineOption
public static boolean isPrintSupportedActionsOption(CmdLineOption option)
CmdLineOption
is a PrintSupportedActionsOption
.option
- The CmdLineOption
in questionCmdLineOption
is a
PrintSupportedActionsOption
, false otherwisepublic static PrintSupportedActionsCmdLineOption findPrintSupportedActionsOption(Set<CmdLineOption> options)
CmdLineOption
of type
PrintSupportedActionsCmdLineOption
.options
- The Set
of CmdLineOption
to find a
PrintSupportedActionsCmdLineOption
inPrintSupportedActionsCmdLineOption
, or null if
not found.public static CmdLineOptionInstance findSpecifiedPrintSupportedActionsOption(Set<CmdLineOptionInstance> options)
options
- The Set
of CmdLineOptionInstance
to find the
CmdLineOptionInstance
whose CmdLineOption
is of
type PrintSupportedActionsCmdLineOption
inCmdLineOptionInstance
whose
CmdLineOption
is of type
PrintSupportedActionsCmdLineOption
, or null if not found.IllegalArgumentException
- If more than one print supported actions option is specifiedpublic static boolean isAdvancedOption(CmdLineOption option)
CmdLineOption
is a AdvancedCmdLineOption
.option
- The CmdLineOption
checked if it is a
AdvancedCmdLineOption
CmdLineOption
is a AdvancedCmdLineOption
,
false otherwisepublic static AdvancedCmdLineOption asAdvancedOption(CmdLineOption option)
CmdLineOption
to a AdvancedCmdLineOption
.option
- The CmdLineOption
to cast as a
AdvancedCmdLineOption
CmdLineOption
public static boolean isSimpleOption(CmdLineOption option)
CmdLineOption
is a SimpleCmdLineOption
.option
- The CmdLineOption
checked if it is a
SimpleCmdLineOption
CmdLineOption
is a SimpleCmdLineOption
,
false otherwisepublic static SimpleCmdLineOption asSimpleOption(CmdLineOption option)
CmdLineOption
to a SimpleCmdLineOption
.option
- The CmdLineOption
to cast as a
SimpleCmdLineOption
CmdLineOption
public static boolean isActionOption(CmdLineOption option)
CmdLineOption
is a ActionCmdLineOption
.option
- CmdLineOption
check if a ActionCmdLineOption
CmdLineOption
is a ActionCmdLineOption
,
false otherwisepublic static ActionCmdLineOption findFirstActionOption(Set<CmdLineOption> options)
options
- The Set
of CmdLineOption
to search through for a
ActionCmdLineOption
ActionCmdLineOption
, or null if not foundpublic static List<ActionCmdLineOption> findActionOptions(Set<CmdLineOption> options)
CmdLineOption
s that are ActionCmdLineOption
s.options
- The CmdLineOption
s to look through for
ActionCmdLineOption
sActionCmdLineOption
s foundpublic static CmdLineOptionInstance findSpecifiedActionOption(Set<CmdLineOptionInstance> options)
options
- The Set
of CmdLineOption
to search through for a
ActionCmdLineOption
ActionCmdLineOption
, or null if not foundIllegalArgumentException
- If more than one action option has be specifiedpublic static boolean isGroupOption(CmdLineOption option)
CmdLineOption
is a GroupCmdLineOption
.option
- CmdLineOption
in questionCmdLineOption
is a GroupCmdLineOption
,
false otherwisepublic static GroupCmdLineOption asGroupOption(CmdLineOption option)
CmdLineOption
to a GroupCmdLineOption
.option
- The CmdLineOption
to be cast as a
GroupCmdLineOption
GroupCmdLineOption
public static boolean isHelpOption(CmdLineOption option)
CmdLineOption
is a HelpCmdLineOption
.option
- The CmdLineOption
that is checked if it is a
HelpCmdLineOption
CmdLineOption
is a HelpCmdLineOption
,
otherwise falsepublic static HelpCmdLineOption asHelpOption(CmdLineOption option)
CmdLineOption
to a HelpCmdLineOption
.option
- The CmdLineOption
to be cast as a
HelpCmdLineOption
HelpCmdLineOption
public static HelpCmdLineOption findHelpOption(Set<CmdLineOption> options)
options
- The Set
of CmdLineOption
s to search through for
HelpCmdLineOption
HelpCmdLineOption
, null if not foundpublic static CmdLineOptionInstance findSpecifiedHelpOption(Set<CmdLineOptionInstance> options)
options
- The Set
of CmdLineOptionInstance
s to search
through for the CmdLineOptionInstance
whose
CmdLineOption
is of type HelpCmdLineOption
CmdLineOptionInstance
, null if not foundIllegalArgumentException
- If more than one help option is specifiedpublic static CmdLineAction findAction(CmdLineOptionInstance actionOption, Set<CmdLineAction> supportedActions)
CmdLineAction
specified by the given
CmdLineOptionInstance
.actionOption
- The CmdLineOptionInstance
which specifies an
ActionCmdLineOption
supportedActions
- Set
of supported CmdLineAction
sCmdLineAction
, null if not foundpublic static CmdLineAction findAction(String actionName, Set<CmdLineAction> supportedActions)
CmdLineAction
by its name.actionName
- Name of CmdLineAction
to findsupportedActions
- Set
of supported CmdLineAction
sCmdLineAction
or null if not foundpublic static List<CmdLineOptionValidator.Result> validate(CmdLineOptionInstance option)
CmdLineOptionInstance
.option
- The CmdLineOptionInstance
to be validatedCmdLineOptionValidator.Result
s from running
CmdLineOptionValidator
s.public static List<CmdLineOptionValidator.Result> determineFailedValidation(List<CmdLineOptionValidator.Result> results)
CmdLineOptionValidator.Result
s with grade of FAIL.results
- The CmdLineOptionValidator.Result
s which are checked if
they have a failing grade.CmdLineOptionValidator.Result
s with grade of FAIL.public static void handlePerformAndQuitOption(CmdLineOptionInstance option)
CmdLineOptionInstance
's handler if it a perform and
quit option.option
- The CmdLineOptionInstance
whose handler will be runpublic static void handle(CmdLineAction action, CmdLineOptionInstance option)
CmdLineOptionInstance
's handler against the given
CmdLineAction
.action
- The CmdLineAction
which the given
CmdLineOptionInstance
's handler will be run againstoption
- The CmdLineOptionInstance
whose handler will be run
against the given CmdLineAction
public static String getFormattedString(String string, int startIndex, int endIndex)
public static List<?> convertToType(List<String> values, Class<?> type) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException
Copyright © 1999–2017 Apache OODT. All rights reserved.