Class AbstractCondition

java.lang.Object
org.refcodes.cli.AbstractCondition
All Implemented Interfaces:
Condition, Constituent, Synopsisable, org.refcodes.mixin.DescriptionAccessor, org.refcodes.mixin.Resetable, org.refcodes.mixin.Schemable
Direct Known Subclasses:
AllCondition, AndCondition, AnyCondition, OrCondition, XorCondition

public abstract class AbstractCondition extends Object implements Condition
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.
  • Field Details

    • _description

      protected String _description
  • Constructor Details

    • AbstractCondition

      public AbstractCondition(String aDescription, Constituent... aElements)
      Instantiates a new abstract condition.
      Parameters:
      aDescription - The description of this Condition.
      aElements - the elements
  • Method Details

    • toSyntax

      public String toSyntax(CliContext aCliCtx)
      This method is to be called from inside the Constituent hierarchy; use the method Synopsisable.toSynopsis(SyntaxNotation) in case you invoke syntax retrieval from the root Constituent. Returns the human readable (verbose) syntax of this Constituent instance including, in case of being a node in the syntax tree (such as a Condition, the syntax of the child Constituent instances. ATTENTION: As of different parenthesis settings for some notations regarding the root Constituent and the child Constituents, the method Constituent.toSyntax(CliContext) is called from inside the Constituent hierarchy. In case the syntax is to be retrieved from the root Constituent, then the applicable method to be called is Synopsisable.toSynopsis(SyntaxNotation), as for some notations it will for example not create the most outer braces.
      Specified by:
      toSyntax in interface Constituent
      Parameters:
      aCliCtx - The CliContext for which the syntax is being generated.
      Returns:
      The human readable (verbose) command line arguments syntax.
    • reset

      public void reset()
      Specified by:
      reset in interface org.refcodes.mixin.Resetable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toSchema

      public CliSchema toSchema()
      Specified by:
      toSchema in interface Constituent
      Specified by:
      toSchema in interface org.refcodes.mixin.Schemable
    • toOperands

      public List<Operand<?>> toOperands()
      Traverses the hierarchy of Conditions and collects all therein found Operands and sub-types such as the Flag or the Option. This is most useful when creating a list of Options, Flages and Operands when printing out detailed help.
      Specified by:
      toOperands in interface Condition
      Returns:
      The according Operand elements.
    • getChildren

      protected List<Constituent> getChildren()
      Gets the children.
      Returns:
      the children
    • getFirst

      protected Constituent 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(Constituent 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 interface Constituent
      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 of Condition tree and returns the (first) operand matching the given alias and type.
      Specified by:
      toOperand in interface Condition
      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
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in interface org.refcodes.mixin.DescriptionAccessor