Class AbstractCondition

java.lang.Object
org.refcodes.cli.AbstractCondition
All Implemented Interfaces:
Condition, MatchCountAccessor, Synopsisable, Term, ExceptionAccessor<ArgsSyntaxException>, VisibleAccessor, VisibleAccessor.VisibleBuilder<Term>, VisibleAccessor.VisibleMutator, VisibleAccessor.VisibleProperty, ChildrenAccessor<Term[]>, DescriptionAccessor, Resetable, Diagnosable, Schemable<DiagnosticOptions>
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

    • _children

      protected Term[] _children
    • _description

      protected String _description
    • _exception

      protected ArgsSyntaxException _exception
    • _isVisible

      protected boolean _isVisible
  • Constructor Details

    • AbstractCondition

      public AbstractCondition(String aDescription, Term... aElements)
      Instantiates an AbstractCondition' s sub-class with the according arguments.
      Parameters:
      aDescription - The description of this Condition.
      aElements - The elements managed by the Condition.
  • Method Details

    • getMatchCount

      public int getMatchCount()
      Determines the number of args being matched by the Term.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 interface MatchCountAccessor
      Specified by:
      getMatchCount in interface Term
      Returns:
      The number of args matching the according syntax (tree).
    • reset

      public void reset()
      Specified by:
      reset in interface Resetable
    • 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
    • toOperands

      public 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.
    • toSchema

      public Schema toSchema()
      Specified by:
      toSchema in interface Schemable<DiagnosticOptions>
    • toString

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

      public String toSyntax(CliContext aCliCtx)
      Creates a syntax including its arguments.

      A specification differs from a syntax in that the specification provides the full definition not omitting any choices whereas the syntax only provides a syntactically correct variant. For example, having an option with a short option and a long option, the specification will show the short option and the long option whereas the syntax will only show either the short option or, if no short option is set, the long option.

      Specified by:
      toSyntax in interface Term
      Parameters:
      aCliCtx - The CLI context controlling notation and formatting
      Returns:
      The human readable command line syntax
    • toValue

      public <V> V toValue(String aAlias)
      Retrieves the value associated with the given alias after parsing.

      The syntax tree is searched for a Term that has produced a value for the specified alias.

      Specified by:
      toValue in interface Term
      Type Parameters:
      V - The expected value type
      Parameters:
      aAlias - The alias to resolve
      Returns:
      The resolved value or null if not set
    • getChildren

      public Term[] getChildren()
      Specified by:
      getChildren in interface ChildrenAccessor<Term[]>
    • isVisible

      public boolean isVisible()

      Visibility in this context means displaying or hiding this Term's existence to the user (defaults to true).

      Specified by:
      isVisible in interface Term
      Specified by:
      isVisible in interface VisibleAccessor
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in interface DescriptionAccessor
    • getException

      public ArgsSyntaxException getException()
      Retrieves the ArgsSyntaxException exception in case invoking Term.parseArgs(String[], CliContext) failed. The exception (and the according suppressed ones alongside the causes) does not necessarily have been thrown by the Term.parseArgs(String[], CliContext) method depending on the semantics of the Term handing the exception (the AnyCondition provides any exceptions it caught even though it did not throw them as of its semantics).
      Specified by:
      getException in interface ExceptionAccessor<ArgsSyntaxException>
      Specified by:
      getException in interface Term
      Returns:
      The ArgsSyntaxException exception occurring while parsing the arguments.
    • setVisible

      public void setVisible(boolean isVisible)

      Visibility in this context means displaying or hiding this Term's existence to the user (defaults to true).

      Specified by:
      setVisible in interface Term
      Specified by:
      setVisible in interface VisibleAccessor.VisibleMutator
    • toArgsDiff

      protected static String[] toArgsDiff(String[] aArgs, List<? extends Operand<?>> aArgsSubset)
      Creates the difference between the provided set and the provided Lists therein found argument arrays subset (as of Operand.getParsedArgs()).
      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 the Operand instances whose command line arguments are to be diffed.
      Returns:
      The difference between the set and the subset.
    • toArgsDiff

      protected static String[] toArgsDiff(String[] aArgs, Operand<?>[] aArgsSubset)
      Creates the difference between the provided set and the provided Lists therein found argument arrays subset (as of Operand.getParsedArgs()).
      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 the Operand instances whose command line arguments are to be diffed.
      Returns:
      The difference between the set and the subset.
    • toArgsDiff

      protected static String[] toArgsDiff(String[] aArgs, String[] aArgsSubset)
      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

      protected static String[] toParsedArgs(Operand<?>[]... aOperands)
      Takes all Operand instances found in the provided Lists and adds all therein found argument arrays (as of Operand.getParsedArgs()) to the result.
      Parameters:
      aOperands - The lists containing the Operand instances whose command line arguments are to be added to the result.
      Returns:
      All the command line arguments detected in the provided Operands Lists.