java.lang.Object
org.refcodes.cli.AbstractCondition
- All Implemented Interfaces:
Condition
,MatchCountAccessor
,Synopsisable
,Term
,org.refcodes.exception.ExceptionAccessor<ArgsSyntaxException>
,org.refcodes.mixin.ChildrenAccessor<Term[]>
,org.refcodes.mixin.DescriptionAccessor
,org.refcodes.mixin.Resetable
,org.refcodes.mixin.Schemable
- Direct Known Subclasses:
AllCondition
,AndCondition
,AnyCondition
,OrCondition
,XorCondition
The
AbstractCondition
is an abstract implementation of the
Condition
interface providing the boiler plate when implementing the
Condition
interface as done by the AbstractCondition
's
sub-classes.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.mixin.ChildrenAccessor
org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<T extends Object,
B extends org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<T, B>>, org.refcodes.mixin.ChildrenAccessor.ChildrenMutator<T extends Object>, org.refcodes.mixin.ChildrenAccessor.ChildrenProperty<T extends Object> Nested classes/interfaces inherited from interface org.refcodes.mixin.DescriptionAccessor
org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<B extends org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<B>>, org.refcodes.mixin.DescriptionAccessor.DescriptionMutator, org.refcodes.mixin.DescriptionAccessor.DescriptionProperty
Nested classes/interfaces inherited from interface org.refcodes.exception.ExceptionAccessor
org.refcodes.exception.ExceptionAccessor.ExceptionBuilder<EXC extends Throwable,
B extends org.refcodes.exception.ExceptionAccessor.ExceptionBuilder<EXC, B>>, org.refcodes.exception.ExceptionAccessor.ExceptionMutator<EXC extends Throwable>, org.refcodes.exception.ExceptionAccessor.ExceptionProperty<EXC extends Throwable> Nested classes/interfaces inherited from interface org.refcodes.cli.MatchCountAccessor
MatchCountAccessor.MatchCountBuilder<B extends MatchCountAccessor.MatchCountBuilder<B>>, MatchCountAccessor.MatchCountMutator, MatchCountAccessor.MatchCountProperty
-
Field Summary
-
Constructor Summary
ConstructorDescriptionAbstractCondition
(String aDescription, Term... aElements) Instantiates anAbstractCondition
' s sub-class with the according arguments. -
Method Summary
Modifier and TypeMethodDescriptionTerm[]
Retrieves theArgsSyntaxException
exception in case invokingTerm.parseArgs(String[], CliContext)
failed.int
Determines the number of args being matched by theTerm.parseArgs(String[], CliContext)
(and similar) method(s) of the according syntax.void
reset()
protected static String[]
toArgsDiff
(String[] aArgs, String[] aArgsSubset) Creates the difference between the provided set and the provided subset.protected static String[]
toArgsDiff
(String[] aArgs, List<? extends Operand<?>> aArgsSubset) Creates the difference between the provided set and the providedList
s therein found argument arrays subset (as ofOperand.getArgs()
).<T extends Operand<?>>
TTraverses the hierarchy ofCondition
tree and returns the (first) operand matching the given alias and type.Operand<?>[]
protected static String[]
toParsedArgs
(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.toSchema()
toString()
toSyntax
(CliContext aCliCtx) This method is to be called from inside theTerm
hierarchy; use the methodSynopsisable.toSynopsis(SyntaxNotation)
in case you invoke syntax retrieval from the rootTerm
.<V> V
Searches for a value being set for the given for given alias in the syntax tree parsing the command line arguments; if a node in the syntax tree has a value for the given alias, then this value is returned.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.refcodes.cli.Condition
hasChild, isChild, toConditions, toOperand, toOperand, toOperands
Methods inherited from interface org.refcodes.mixin.DescriptionAccessor
getDescription
Methods inherited from interface org.refcodes.cli.Synopsisable
toSynopsis, toSynopsis, toSynopsis, toSynopsis
Methods inherited from interface org.refcodes.cli.Term
getException, parseArgs, parseArgs, toSynopsis, toSyntax, toSyntax, toSyntax, toSyntax
-
Field Details
-
_children
-
_description
-
_exception
-
-
Constructor Details
-
AbstractCondition
Instantiates anAbstractCondition
' s sub-class with the according arguments.
-
-
Method Details
-
getMatchCount
public int getMatchCount()Determines the number of args being matched by theTerm.parseArgs(String[], CliContext)
(and similar) method(s) of the according syntax. This way we can determine which part of the syntax (tree) had most matches.- Specified by:
getMatchCount
in interfaceMatchCountAccessor
- Specified by:
getMatchCount
in interfaceTerm
- Returns:
- The number of args matching the according syntax (tree).
-
reset
public void reset()- Specified by:
reset
in interfaceorg.refcodes.mixin.Resetable
-
toOperand
Traverses the hierarchy ofCondition
tree and returns the (first) operand matching the given alias and type. -
toOperands
Traverses the hierarchy ofCondition
s and collects all therein foundOperand
s and sub-types such as theFlag
or theOption
. This is most useful when creating a list ofOption
s,Flag
es andOperand
s when printing out detailed help.- Specified by:
toOperands
in interfaceCondition
- Returns:
- The according
Operand
elements.
-
toSchema
-
toString
-
toSyntax
This method is to be called from inside theTerm
hierarchy; use the methodSynopsisable.toSynopsis(SyntaxNotation)
in case you invoke syntax retrieval from the rootTerm
. Returns the human readable (verbose) syntax of thisTerm
instance including, in case of being a node in the syntax tree (such as aCondition
, the syntax of the childTerm
instances. ATTENTION: As of different parenthesis settings for some notations regarding the rootTerm
and the childTerm
s, the methodTerm.toSyntax(CliContext)
is called from inside theTerm
hierarchy. In case the syntax is to be retrieved from the rootTerm
, then the applicable method to be called isSynopsisable.toSynopsis(SyntaxNotation)
, as for some notations it will for example not create the most outer braces.- Specified by:
toSyntax
in interfaceTerm
- Parameters:
aCliCtx
- TheCliContext
for which the syntax is being generated.- Returns:
- The human readable (verbose) command line arguments syntax.
-
toValue
Searches for a value being set for the given for given alias in the syntax tree parsing the command line arguments; if a node in the syntax tree has a value for the given alias, then this value is returned. -
getChildren
- Specified by:
getChildren
in interfaceorg.refcodes.mixin.ChildrenAccessor<Term[]>
-
getDescription
- Specified by:
getDescription
in interfaceorg.refcodes.mixin.DescriptionAccessor
-
getException
Retrieves theArgsSyntaxException
exception in case invokingTerm.parseArgs(String[], CliContext)
failed. The exception (and the according suppressed ones alongside the causes) does not necessarily have been thrown by theTerm.parseArgs(String[], CliContext)
method depending on the semantics of theTerm
handing the exception (theAnyCondition
provides any exceptions it caught even though it did not throw them as of its semantics).- Specified by:
getException
in interfaceorg.refcodes.exception.ExceptionAccessor<ArgsSyntaxException>
- Specified by:
getException
in interfaceTerm
- Returns:
- The
ArgsSyntaxException
exception occurring while parsing the arguments.
-
toArgsDiff
Creates the difference between the provided set and the providedList
s therein found argument arrays subset (as ofOperand.getArgs()
).- Parameters:
aArgs
- The set to be used for the diff operation.aArgsSubset
- 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.
-
toArgsDiff
Creates the difference between the provided set and the provided subset.- Parameters:
aArgs
- The set to be used for the diff operation.aArgsSubset
- The subset to be used for the diff operation.- Returns:
- The difference between the set and the subset.
-
toParsedArgs
Takes allOperand
instances found in the providedList
s and adds all therein found argument arrays (as ofOperand.getArgs()
) to the result.
-