- java.lang.Object
-
- org.refcodes.cli.AbstractCondition
-
- All Implemented Interfaces:
ArgsSyntax
,Condition
,Synopsis
,Syntaxable
,org.refcodes.component.Resetable
- Direct Known Subclasses:
AllCondition
,AndCondition
,AnyCondition
,OptionCondition
,OrCondition
,XorCondition
public abstract class AbstractCondition extends Object implements Condition
TheAbstractCondition
is an abstract implementation of theArgsSyntax
interface providing the boiler plate when implementing theArgsSyntax
interface as done by theAbstractCondition
's sub-classes.
-
-
Constructor Summary
Constructors Constructor Description AbstractCondition(Syntaxable... aElements)
Instantiates a new abstract condition.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addChild(Syntaxable aArgumentizer)
Adds the child.protected List<Syntaxable>
getChildren()
Gets the children.protected Syntaxable
getFirst()
Gets the first child.void
reset()
<T extends Operand<?>>
TtoOperand(String aAlias, Class<T> aType)
Traverses the hierarchy ofArgsSyntax
tree and returns the (first) operand matching the given alias and type.List<Operand<?>>
toOperands()
Traverses the hierarchy ofArgsSyntax
s and collects all therein foundOperand
s and sub-types such as theFlag
or theOption
.String
toString()
String
toSynopsis(SyntaxNotation aSyntaxNotation, String aOptEscCode, String aParamEscCode, String aResetEscCode)
Returns the human readable (verbose) syntax of implementing class ATTENTION: As of different parenthesis settings for some notations regarding the rootSyntaxable
and the childSyntaxable
s, the methodSyntaxable.toSyntax(SyntaxNotation, String, String, String)
is called from inside aSyntaxable
hierarchy.String
toSyntax(SyntaxNotation aSyntaxNotation, String aOptEscCode, String aParamEscCode, String aResetEscCode)
This method is to be called from inside theSyntaxable
hierarchy; use the methodSynopsis.toSynopsis(SyntaxNotation)
in case you invoke syntax retrieval from the rootSyntaxable
.<V> V
toValue(String aAlias)
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.ArgsSyntax
toOperand, toOperand
-
Methods inherited from interface org.refcodes.cli.Synopsis
toSynopsis, toSynopsis, toSynopsis, toSynopsis
-
-
-
-
Constructor Detail
-
AbstractCondition
public AbstractCondition(Syntaxable... aElements)
Instantiates a new abstract condition.- Parameters:
aElements
- the elements
-
-
Method Detail
-
toSyntax
public String toSyntax(SyntaxNotation aSyntaxNotation, String aOptEscCode, String aParamEscCode, String aResetEscCode)
This method is to be called from inside theSyntaxable
hierarchy; use the methodSynopsis.toSynopsis(SyntaxNotation)
in case you invoke syntax retrieval from the rootSyntaxable
. Returns the human readable (verbose) syntax of thisSyntaxable
instance including, in case of being a node in the syntax tree (such as aArgsSyntax
, the syntax of the childSyntaxable
instances. ATTENTION: As of different parenthesis settings for some notations regarding the rootSyntaxable
and the childSyntaxable
s, the methodSyntaxable.toSyntax(SyntaxNotation, String, String, String)
is called from inside theSyntaxable
hierarchy. In case the syntax is to be retrieved from the rootSyntaxable
, then the applicable method to be called isSynopsis.toSynopsis(SyntaxNotation)
, as for some notations it will for example not create the most outer braces.- Specified by:
toSyntax
in interfaceSyntaxable
- Parameters:
aSyntaxNotation
- The syntax notation used for generating the command line arguments syntax.aOptEscCode
- The escape code to be used when processing an option, e.g. this can be an ANSI Escape-Code to highlight the option.aParamEscCode
- The escape code to be used when processing a keyword, e.g. this can be an ANSI Escape-Code to highlight the option and/or parameters.aResetEscCode
- The escape code to close (reset) any Escape-Code being set before.- Returns:
- The human readable (verbose) command line arguments syntax.
-
reset
public void reset()
- Specified by:
reset
in interfaceorg.refcodes.component.Resetable
-
toOperands
public List<Operand<?>> toOperands()
Traverses the hierarchy ofArgsSyntax
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 interfaceArgsSyntax
- Returns:
- The according
Operand
elements.
-
getChildren
protected List<Syntaxable> getChildren()
Gets the children.- Returns:
- the children
-
getFirst
protected Syntaxable getFirst()
Gets the first child. It is up to the developer to make sure that there actually is(!) a child!- Returns:
- the first child.
-
addChild
protected void addChild(Syntaxable aArgumentizer)
Adds the child.- Parameters:
aArgumentizer
- the argumentizer
-
toValue
public <V> V toValue(String aAlias)
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.- Specified by:
toValue
in interfaceSyntaxable
- Type Parameters:
V
- The type of the value being expected.- Parameters:
aAlias
- The alias for which to seek for a value being set.- Returns:
- The according value or null if none has been set for the given alias.
-
toOperand
public <T extends Operand<?>> T toOperand(String aAlias, Class<T> aType)
Traverses the hierarchy ofArgsSyntax
tree and returns the (first) operand matching the given alias and type.- Specified by:
toOperand
in interfaceArgsSyntax
- Type Parameters:
T
- the generic type- Parameters:
aAlias
- The alias for which to seek for.aType
- The type for which to seek for.- Returns:
- The according
Operand
element or null if none matching was found
-
toSynopsis
public String toSynopsis(SyntaxNotation aSyntaxNotation, String aOptEscCode, String aParamEscCode, String aResetEscCode)
Returns the human readable (verbose) syntax of implementing class ATTENTION: As of different parenthesis settings for some notations regarding the rootSyntaxable
and the childSyntaxable
s, the methodSyntaxable.toSyntax(SyntaxNotation, String, String, String)
is called from inside aSyntaxable
hierarchy. In case the syntax is to be retrieved from the rootSyntaxable
or an encapsulating and different type, then the applicable method to be called isSynopsis.toSynopsis(SyntaxNotation)
, as for some notations it will for example not create the most outer braces.- Specified by:
toSynopsis
in interfaceSynopsis
- Parameters:
aSyntaxNotation
- The syntax notation used for generating the command line arguments syntax.aOptEscCode
- The escape code to be used when processing an option, e.g. this can be an ANSI Escape-Code to highlight the option.aParamEscCode
- The escape code to be used when processing am argument, e.g. this can be an ANSI Escape-Code to highlight the option.aResetEscCode
- The escape code to close (reset) any Escape-Code being set before.- Returns:
- The human readable (verbose) command line arguments syntax.
-
-