Class Argument.ArgumentBuilder<T>

java.lang.Object
com.clumd.projects.java_common_utils.arg_parser.Argument.ArgumentBuilder<T>
Type Parameters:
T - The param type for the builder matching that of the base Argument class.
Enclosing class:
Argument<T>

public static class Argument.ArgumentBuilder<T> extends Object
Overridden Builder for part of the Lombok process. This is used to alter the basic setter functionality of the chained methods in the builder, dependent on the field being overridden.
  • Method Details

    • uniqueId

      public Argument.ArgumentBuilder<T> uniqueId(String toValue)
      This is used to set the uniqueId of this argument, it is only required as an override to the default constructor to have the value available to the exception strings in the FunctionPotentialException methods below
      Parameters:
      toValue - Used to index the options, must be unique and supplied by the user.
      Returns:
      This continued builder instance.
    • hasValue

      public Argument.ArgumentBuilder<T> hasValue(boolean toValue)
      This is used to set the hasValue of this argument, it is only required as an override to the default constructor to allow the conversionFunction to trigger a change of state when a conversionFunction is provided.
      Parameters:
      toValue - Used to determine whether this Argument can be followed with a value.
      Returns:
      This continued builder instance.
    • defaultValue

      public Argument.ArgumentBuilder<T> defaultValue(T toValue)
      Used to set the default value, and also mark that the default value has been set. This can be used to notify a local Arg Parser that a local value exists, in case it wants to display this in help text.
      Parameters:
      toValue - The value to use as a default value for this argument.
      Returns:
      This continued builder instance.
    • conversionFunction

      public <E extends Exception> Argument.ArgumentBuilder<T> conversionFunction(FunctionPotentialException<String,T,E> functionWhichMayThrowException)
      This constructor is used to override the conversion function in order to wrap the call to the Function.apply(Object) such that the implementing user can use checked exceptions if they want, without it causing compile time issues. Any exceptions will be wrapped into the reason for an IllegalArgumentException.
      Type Parameters:
      E - Allowing the FunctionPotentialException to throw an instance of an Exception, as a child reason to an IllegalArgumentException.
      Parameters:
      functionWhichMayThrowException - An input lambda which may or may not throw an exception. The lambda's single input parameter will be a String which would be the command line argument value. The return type is tied to the typing of the base Argument<T>. The exception is introspected by the definition of the provided lambda.
      Returns:
      This continued builder instance.
    • validationFunction

      public <E extends Exception> Argument.ArgumentBuilder<T> validationFunction(FunctionPotentialException<T,Boolean,E> functionWhichMayThrowException)
      This constructor is used to override the value validation function in order to wrap the call to the Function.apply(Object) such that the implementing user can use checked exceptions if they want, without it causing compile time issues. Any exceptions will be wrapped into the reason for an IllegalArgumentException.
      Type Parameters:
      E - Allowing the FunctionPotentialException to throw an instance of an Exception, as a child reason to an IllegalArgumentException.
      Parameters:
      functionWhichMayThrowException - An input lambda which may or may not throw an exception. The lambda's single input parameter will be the type-safe value, typed against the T of the base Argument. The return type will be a boolean determining whether the successfully parsed value is within some user-defined acceptable range. The exception is introspected by the definition of the provided lambda.
      Returns:
      This continued builder instance.
    • shortOptions

      public Argument.ArgumentBuilder<T> shortOptions(Set<Character> shortOptions)
      Used to contain all the single character alias' to indicate this option
      Returns:
      this.
    • longOptions

      public Argument.ArgumentBuilder<T> longOptions(Set<String> longOptions)
      Used to contain all the word alias' to indicate this option
      Returns:
      this.
    • mustBeUsedWith

      public Argument.ArgumentBuilder<T> mustBeUsedWith(Set<String> mustBeUsedWith)
      Used to denote other CLI Arguments (by reference to their Argument.uniqueId) which MUST be present if, and only if, this Argument is found on the CLI.
      Returns:
      this.
    • mustNotBeUsedWith

      public Argument.ArgumentBuilder<T> mustNotBeUsedWith(Set<String> mustNotBeUsedWith)
      Used to denote other CLI Arguments (by reference to their Argument.uniqueId) which MUST NOT be used in conjunction with this one if, and only if, this Argument is found on the CLI.
      Returns:
      this.
    • isMandatory

      public Argument.ArgumentBuilder<T> isMandatory(boolean isMandatory)
      Used to indicate if this argument is mandatory and MUST be provided for the utilising code to function. If you set this value to true, you probably don't want to set a default value.
      Returns:
      this.
    • shouldShortCircuit

      public Argument.ArgumentBuilder<T> shouldShortCircuit(boolean shouldShortCircuit)
      Used to tell a parser that if this argument is detected on the CLI at all, it should ALWAYS be returnable to the caller with all present short circuit args. Ideally ignoring any other constraints, such as Argument.isMandatory = true; or an already parsed argument with Argument.mustBeUsedWith set. This will only take effect, if a short-circuiting argument is found on the command line before another CLI option which would cause the parser to fail.
      Returns:
      this.
    • valueIsOptional

      public Argument.ArgumentBuilder<T> valueIsOptional(boolean valueIsOptional)
      Used to indicate if the value to this argument can be optional, defaults to false. (e.g. value MUST be provided)
      Returns:
      this.
    • description

      public Argument.ArgumentBuilder<T> description(String description)
      Used to describe the purpose of this Argument and how it should be used.
      Returns:
      this.
    • defaultValueSet

      public Argument.ArgumentBuilder<T> defaultValueSet(boolean defaultValueSet)
      Used to track if a default value has been set for this argument to be used if no CLI value is found.
      Returns:
      this.
    • argumentResult

      public Argument.ArgumentBuilder<T> argumentResult(T argumentResult)
      If this argument needs a value, then this should be the fully validated and parsed output of that value.
      Returns:
      this.
    • build

      public Argument<T> build()
    • toString

      public String toString()
      Overrides:
      toString in class Object