Class AbstractCondition

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

    • _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 org.refcodes.mixin.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 CliSchema toSchema()
      Specified by:
      toSchema in interface org.refcodes.schema.Schemable
      Specified by:
      toSchema in interface Term
    • toString

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

      public String toSyntax(CliContext aCliCtx)
      This method is to be called from inside the Term hierarchy; use the method Synopsisable.toSynopsis(SyntaxNotation) in case you invoke syntax retrieval from the root Term. Returns the human readable (verbose) syntax of this Term instance including, in case of being a node in the syntax tree (such as a Condition, the syntax of the child Term instances. ATTENTION: As of different parenthesis settings for some notations regarding the root Term and the child Terms, the method Term.toSyntax(CliContext) is called from inside the Term hierarchy. In case the syntax is to be retrieved from the root Term, 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 Term
      Parameters:
      aCliCtx - The CliContext for which the syntax is being generated.
      Returns:
      The human readable (verbose) command line arguments syntax.
    • 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 Term
      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.
    • getChildren

      public Term[] getChildren()
      Specified by:
      getChildren in interface org.refcodes.mixin.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 org.refcodes.graphical.VisibleAccessor
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in interface org.refcodes.mixin.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 org.refcodes.exception.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 org.refcodes.graphical.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.