Class OptionFormatter


  • public final class OptionFormatter
    extends java.lang.Object
    The definition of how to display Option attributes.
    Since:
    1.10.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String[] argNameDelimiters
      The delimiters around argument names.
      static java.util.function.Function<Option,​java.lang.String> COMPLEX_DEPRECATED_FORMAT
      A function to display a deprecated option with a "Deprecated" prefix that displays all deprecation information.
      static java.lang.String DEFAULT_ARG_NAME
      The default argument name: "arg".
      private static java.lang.String[] DEFAULT_ARG_NAME_DELIMITERS
      The default delimiters for an argument name
      static java.lang.String DEFAULT_LONG_OPT_PREFIX
      Default prefix for long options: "--".
      static java.lang.String DEFAULT_OPT_ARG_SEPARATOR
      The default separator between the opt and/or longOpt and the argument name: " ".
      static java.lang.String DEFAULT_OPT_PREFIX
      Default prefix for short options: "-".
      static java.lang.String DEFAULT_OPT_SEPARATOR
      The default separator between options: ", ".
      private static java.lang.String[] DEFAULT_OPTIONAL_DELIMITERS
      The default delimiters for optional arguments
      static java.lang.String DEFAULT_SYNTAX_PREFIX
      The string to display at the beginning of the usage statement: "usage: ".
      private java.lang.String defaultArgName
      The default argument name.
      private java.util.function.Function<Option,​java.lang.String> deprecatedFormatFunction
      The function to display the deprecated option message.
      private java.lang.String longOptPrefix
      The prefix for the long option text.
      static java.util.function.Function<Option,​java.lang.String> NO_DEPRECATED_FORMAT
      A function to display a deprecated option with the "[Deprecated]" prefix.
      private java.lang.String optArgSeparator
      the separator between the opt and/or longOpt and the argument name.
      private Option option
      The Option being formatted.
      private java.lang.String[] optionalDelimiters
      The delimiters for optional Options.
      private java.lang.String optPrefix
      The prefix for the short option text.
      private java.lang.String optSeparator
      The separator between the options.
      static java.util.function.Function<Option,​java.lang.String> SIMPLE_DEPRECATED_FORMAT
      A function to display a deprecated option with the "[Deprecated]" prefix.
      private java.util.function.BiFunction<OptionFormatter,​java.lang.Boolean,​java.lang.String> syntaxFormatFunction
      The method to convert an Option formatter into a syntax notation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static OptionFormatter.Builder builder()
      Creates a new builder.
      static OptionFormatter from​(Option option)
      Construct the OptionFormatter from an Option using the default OptionFormatter.Builder.
      java.lang.String getArgName()
      Gets the argument name wrapped in the argument name delimiters.
      java.lang.String getBothOpt()
      Gets both options separated by the specified option separator.
      java.lang.String getDescription()
      Gets the description for the option.
      java.lang.String getLongOpt()
      Gets the long Opt from the @{link Option} with the associate prefix.
      java.lang.String getOpt()
      Gets the Opt from the @{link Option} with the associate prefix.
      java.lang.String getSince()
      Gets the "since" value from the Option.
      boolean isRequired()
      Gets the required flag from the enclosed Option.
      java.lang.String toOptional​(java.lang.String text)
      Wraps the provided text in the optional delimiters.
      java.lang.String toSyntaxOption()
      Gets the syntax format for this option.
      java.lang.String toSyntaxOption​(boolean isRequired)
      Gets the syntax format for this option.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_OPTIONAL_DELIMITERS

        private static final java.lang.String[] DEFAULT_OPTIONAL_DELIMITERS
        The default delimiters for optional arguments
      • DEFAULT_ARG_NAME_DELIMITERS

        private static final java.lang.String[] DEFAULT_ARG_NAME_DELIMITERS
        The default delimiters for an argument name
      • DEFAULT_ARG_NAME

        public static final java.lang.String DEFAULT_ARG_NAME
        The default argument name: "arg".
        See Also:
        Constant Field Values
      • SIMPLE_DEPRECATED_FORMAT

        public static final java.util.function.Function<Option,​java.lang.String> SIMPLE_DEPRECATED_FORMAT
        A function to display a deprecated option with the "[Deprecated]" prefix.
      • COMPLEX_DEPRECATED_FORMAT

        public static final java.util.function.Function<Option,​java.lang.String> COMPLEX_DEPRECATED_FORMAT
        A function to display a deprecated option with a "Deprecated" prefix that displays all deprecation information.
      • NO_DEPRECATED_FORMAT

        public static final java.util.function.Function<Option,​java.lang.String> NO_DEPRECATED_FORMAT
        A function to display a deprecated option with the "[Deprecated]" prefix.
      • DEFAULT_SYNTAX_PREFIX

        public static final java.lang.String DEFAULT_SYNTAX_PREFIX
        The string to display at the beginning of the usage statement: "usage: ".
        See Also:
        Constant Field Values
      • DEFAULT_OPT_PREFIX

        public static final java.lang.String DEFAULT_OPT_PREFIX
        Default prefix for short options: "-".
        See Also:
        Constant Field Values
      • DEFAULT_LONG_OPT_PREFIX

        public static final java.lang.String DEFAULT_LONG_OPT_PREFIX
        Default prefix for long options: "--".
        See Also:
        Constant Field Values
      • DEFAULT_OPT_SEPARATOR

        public static final java.lang.String DEFAULT_OPT_SEPARATOR
        The default separator between options: ", ".
        See Also:
        Constant Field Values
      • DEFAULT_OPT_ARG_SEPARATOR

        public static final java.lang.String DEFAULT_OPT_ARG_SEPARATOR
        The default separator between the opt and/or longOpt and the argument name: " ".
        See Also:
        Constant Field Values
      • argNameDelimiters

        private final java.lang.String[] argNameDelimiters
        The delimiters around argument names.
      • defaultArgName

        private final java.lang.String defaultArgName
        The default argument name.
      • deprecatedFormatFunction

        private final java.util.function.Function<Option,​java.lang.String> deprecatedFormatFunction
        The function to display the deprecated option message.
      • longOptPrefix

        private final java.lang.String longOptPrefix
        The prefix for the long option text.
      • optPrefix

        private final java.lang.String optPrefix
        The prefix for the short option text.
      • optSeparator

        private final java.lang.String optSeparator
        The separator between the options.
      • optArgSeparator

        private final java.lang.String optArgSeparator
        the separator between the opt and/or longOpt and the argument name.
      • optionalDelimiters

        private final java.lang.String[] optionalDelimiters
        The delimiters for optional Options.
      • syntaxFormatFunction

        private final java.util.function.BiFunction<OptionFormatter,​java.lang.Boolean,​java.lang.String> syntaxFormatFunction
        The method to convert an Option formatter into a syntax notation.
      • option

        private final Option option
        The Option being formatted.
    • Constructor Detail

      • OptionFormatter

        private OptionFormatter​(Option option,
                                OptionFormatter.Builder builder)
        An OptionFormatter applies formatting options to various Option attributes for textual display.
        Parameters:
        option - the Option to apply formatting to.
        builder - The Builder that specifies the various formatting options.
    • Method Detail

      • getArgName

        public java.lang.String getArgName()
        Gets the argument name wrapped in the argument name delimiters.
        • If option has no arguments an empty string is returned
        • If the argument name is not set the default argument name is used.
        Returns:
        The argument name wrapped in the argument name delimiters or an empty string.
      • getBothOpt

        public java.lang.String getBothOpt()
        Gets both options separated by the specified option separator. Correctly handles the case where one option is not specified.
        Returns:
        The one or both of the short and/or long Opt with the associate prefixes.
      • getDescription

        public java.lang.String getDescription()
        Gets the description for the option. This will include any deprecation notices if the deprecated format function has been set.
        Returns:
        The Description from the option or an empty string is no description was provided and the option is not deprecated.
      • getLongOpt

        public java.lang.String getLongOpt()
        Gets the long Opt from the @{link Option} with the associate prefix.
        Returns:
        The long Opt from the @{link Option} with the associate prefix or an empty string.
      • getOpt

        public java.lang.String getOpt()
        Gets the Opt from the @{link Option} with the associate prefix.
        Returns:
        The Opt from the @{link Option} with the associate prefix or an empty string.
      • getSince

        public java.lang.String getSince()
        Gets the "since" value from the Option.
        Returns:
        The since valeu from the option or "--" if no since value was set.
      • isRequired

        public boolean isRequired()
        Gets the required flag from the enclosed Option.
        Returns:
        The required flag from the enclosed Option.
      • toOptional

        public java.lang.String toOptional​(java.lang.String text)
        Wraps the provided text in the optional delimiters.
        Parameters:
        text - the text to wrap.
        Returns:
        The text wrapped in the optional delimiters or an eppty string of the text is null or an empty string.
      • toSyntaxOption

        public java.lang.String toSyntaxOption()
        Gets the syntax format for this option.
        Returns:
        the syntax format for this option as specified by the syntaxFormatFunction.
      • toSyntaxOption

        public java.lang.String toSyntaxOption​(boolean isRequired)
        Gets the syntax format for this option.
        Parameters:
        isRequired - if true the options is printed as a required option, otherwise it is optional.
        Returns:
        the syntax format for this option as specified by the syntaxFormatFunction.