Class Option<T>

    • Constructor Summary

      Constructors 
      Constructor Description
      Option​(java.lang.String longName, java.lang.Class<T> type, java.lang.Enum category, T[] options, T defval, java.lang.String description)
      Create a new option with the given values.
      Option​(java.lang.String prefix, java.lang.String shortName, java.lang.Class<T> type, java.lang.Enum category, T[] options, T defval, java.lang.String description)
      Create a new option with the given values.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static Option<java.lang.Boolean> bool​(java.lang.String longName, java.lang.Enum category, java.lang.Boolean defval, java.lang.String description)
      Create a new Boolean option with the given configuration.
      static Option<java.lang.Boolean> bool​(java.lang.String longName, java.lang.Enum category, java.lang.String description)
      Create a new Boolean option with the given configuration.
      static Option<java.lang.Boolean> bool​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.Boolean defval, java.lang.String description)
      Create a new Boolean option with the given configuration.
      static Option<java.lang.Boolean> bool​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.String description)
      Create a new Boolean option with the given configuration.
      T defaultValue()  
      java.lang.String description()  
      java.lang.String displayName()
      The display name of the option's property, either the short name or the full name.
      private static java.lang.String encodeWhitespace​(java.lang.Object obj)  
      static <T extends java.lang.Enum<T>>
      Option<T>
      enumeration​(java.lang.String longName, java.lang.Enum category, java.lang.Class<T> enumClass, java.lang.String description)
      Create a new Enumeration-based option with the given configuration.
      static <T extends java.lang.Enum<T>>
      Option<T>
      enumeration​(java.lang.String longName, java.lang.Enum category, T defval, java.lang.String description)
      Create a new Enumeration-based option with the given configuration.
      static <T extends java.lang.Enum<T>>
      Option<T>
      enumeration​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.Class<T> enumClass, java.lang.String description)
      Create a new Enumeration-based option with the given configuration.
      static <T extends java.lang.Enum<T>>
      Option<T>
      enumeration​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, T defval, java.lang.String description)
      Create a new Enumeration-based option with the given configuration.
      void force​(java.lang.String value)
      Force the property value to the given value for all future loads and reloads.
      static java.lang.String formatOptions​(Option... options)
      Format the given options in a way suitable for use as a configuration file or documentation.
      static java.lang.String formatOptions​(java.util.Collection<Option> options)
      Format the given options in a way suitable for use as a configuration file or documentation.
      static java.lang.String formatValues​(Option... options)
      Format the given options to show their loaded values in the current JVM.
      static java.lang.String formatValues​(java.util.Collection<Option> options)
      Format the given options to show their loaded values in the current JVM.
      static Option<java.lang.Integer> integer​(java.lang.String longName, java.lang.Enum category, java.lang.Integer[] options, java.lang.Integer defval, java.lang.String description)
      Create a new Integer option with the given configuration.
      static Option<java.lang.Integer> integer​(java.lang.String longName, java.lang.Enum category, java.lang.Integer[] options, java.lang.String description)
      Create a new Integer option with the given configuration.
      static Option<java.lang.Integer> integer​(java.lang.String longName, java.lang.Enum category, java.lang.Integer defval, java.lang.String description)
      Create a new Integer option with the given configuration.
      static Option<java.lang.Integer> integer​(java.lang.String longName, java.lang.Enum category, java.lang.String description)
      Create a new Integer option with the given configuration.
      static Option<java.lang.Integer> integer​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.Integer[] options, java.lang.Integer defval, java.lang.String description)
      Create a new Integer option with the given configuration.
      static Option<java.lang.Integer> integer​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.Integer[] options, java.lang.String description)
      Create a new Integer option with the given configuration.
      static Option<java.lang.Integer> integer​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.Integer defval, java.lang.String description)
      Create a new Integer option with the given configuration.
      static Option<java.lang.Integer> integer​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.String description)
      Create a new Integer option with the given configuration.
      boolean isSpecified()  
      T load()  
      java.lang.String loadProperty()
      Load the option's property, as if by calling java.lang.System#getProperty
      T[] options()
      The array of accepted values for the option, or null if any values are accepted.
      java.lang.String prefix()
      If the property has a prefix, return it.
      java.lang.String propertyName()  
      T reload()
      Force a load of the option's property and return the loaded value.
      protected abstract T reloadValue()
      Perform the appropriate load and conversion for the option's property.
      java.lang.String shortName()
      If the option has a short name, return it.
      static Option<java.lang.String> string​(java.lang.String longName, java.lang.Enum category, java.lang.String description)
      Create a new String option with the given configuration.
      static Option<java.lang.String> string​(java.lang.String longName, java.lang.Enum category, java.lang.String[] options, java.lang.String description)
      Create a new String option with the given configuration.
      static Option<java.lang.String> string​(java.lang.String longName, java.lang.Enum category, java.lang.String[] options, java.lang.String defval, java.lang.String description)
      Create a new String option with the given configuration.
      static Option<java.lang.String> string​(java.lang.String longName, java.lang.Enum category, java.lang.String defval, java.lang.String description)
      Create a new String option with the given configuration.
      static Option<java.lang.String> string​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.String description)
      Create a new String option with the given configuration.
      static Option<java.lang.String> string​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.String[] options, java.lang.String description)
      Create a new String option with the given configuration.
      static Option<java.lang.String> string​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.String[] options, java.lang.String defval, java.lang.String description)
      Create a new String option with the given configuration.
      static Option<java.lang.String> string​(java.lang.String prefix, java.lang.String shortName, java.lang.Enum category, java.lang.String defval, java.lang.String description)
      Create a new String option with the given configuration.
      java.lang.String toString()  
      java.lang.Class<T> type()
      The type returned for the option.
      void unforce()
      Undoes any previous force, and goes back to an unloaded state.
      • Methods inherited from class java.lang.Object

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

      • OptionComparator

        private static java.util.Comparator<Option> OptionComparator
      • category

        private final java.lang.Enum category
      • prefix

        private final java.lang.String prefix
      • shortName

        private final java.lang.String shortName
      • longName

        private final java.lang.String longName
      • displayName

        private final java.lang.String displayName
      • type

        protected final java.lang.Class<T> type
      • options

        private final T[] options
      • defval

        protected final T defval
      • description

        private final java.lang.String description
      • forced

        private java.lang.String forced
      • specified

        private boolean specified
      • value

        private volatile T value
      • loaded

        private volatile boolean loaded
    • Constructor Detail

      • Option

        public Option​(java.lang.String prefix,
                      java.lang.String shortName,
                      java.lang.Class<T> type,
                      java.lang.Enum category,
                      T[] options,
                      T defval,
                      java.lang.String description)
        Create a new option with the given values.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        type - the value type of the option
        category - the category to which this option belongs
        options - a list of supported for the option, or null if the set is not applicable
        defval - the default value for the option
        description - a description for the option
      • Option

        public Option​(java.lang.String longName,
                      java.lang.Class<T> type,
                      java.lang.Enum category,
                      T[] options,
                      T defval,
                      java.lang.String description)
        Create a new option with the given values.
        Parameters:
        longName - the property name
        type - the value type of the option
        category - the category to which this option belongs
        options - a list of supported for the option, or null if the set is not applicable
        defval - the default value for the option
        description - a description for the option
    • Method Detail

      • string

        public static Option<java.lang.String> string​(java.lang.String prefix,
                                                      java.lang.String shortName,
                                                      java.lang.Enum category,
                                                      java.lang.String description)
        Create a new String option with the given configuration.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        description - a description for the option
        Returns:
        a new String-based option
      • string

        public static Option<java.lang.String> string​(java.lang.String longName,
                                                      java.lang.Enum category,
                                                      java.lang.String description)
        Create a new String option with the given configuration.
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        description - a description for the option
        Returns:
        a new String-based option
      • string

        public static Option<java.lang.String> string​(java.lang.String prefix,
                                                      java.lang.String shortName,
                                                      java.lang.Enum category,
                                                      java.lang.String defval,
                                                      java.lang.String description)
        Create a new String option with the given configuration.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new String-based Option
      • string

        public static Option<java.lang.String> string​(java.lang.String longName,
                                                      java.lang.Enum category,
                                                      java.lang.String defval,
                                                      java.lang.String description)
        Create a new String option with the given configuration.
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new String-based Option
      • string

        public static Option<java.lang.String> string​(java.lang.String prefix,
                                                      java.lang.String shortName,
                                                      java.lang.Enum category,
                                                      java.lang.String[] options,
                                                      java.lang.String description)
        Create a new String option with the given configuration.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        options - a list of supported for the option, or null if the set is not applicable
        description - a description for the option
        Returns:
        a new String-based Option
      • string

        public static Option<java.lang.String> string​(java.lang.String longName,
                                                      java.lang.Enum category,
                                                      java.lang.String[] options,
                                                      java.lang.String description)
        Create a new String option with the given configuration.
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        options - a list of supported for the option, or null if the set is not applicable
        description - a description for the option
        Returns:
        a new String-based Option
      • string

        public static Option<java.lang.String> string​(java.lang.String prefix,
                                                      java.lang.String shortName,
                                                      java.lang.Enum category,
                                                      java.lang.String[] options,
                                                      java.lang.String defval,
                                                      java.lang.String description)
        Create a new String option with the given configuration.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        options - a list of supported for the option, or null if the set is not applicable
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new String-based Option
      • string

        public static Option<java.lang.String> string​(java.lang.String longName,
                                                      java.lang.Enum category,
                                                      java.lang.String[] options,
                                                      java.lang.String defval,
                                                      java.lang.String description)
        Create a new String option with the given configuration.
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        options - a list of supported for the option, or null if the set is not applicable
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new String-based Option
      • bool

        public static Option<java.lang.Boolean> bool​(java.lang.String prefix,
                                                     java.lang.String shortName,
                                                     java.lang.Enum category,
                                                     java.lang.String description)
        Create a new Boolean option with the given configuration.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        description - a description for the option
        Returns:
        a new Boolean-based Option
      • bool

        public static Option<java.lang.Boolean> bool​(java.lang.String longName,
                                                     java.lang.Enum category,
                                                     java.lang.String description)
        Create a new Boolean option with the given configuration.
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        description - a description for the option
        Returns:
        a new Boolean-based Option
      • bool

        public static Option<java.lang.Boolean> bool​(java.lang.String prefix,
                                                     java.lang.String shortName,
                                                     java.lang.Enum category,
                                                     java.lang.Boolean defval,
                                                     java.lang.String description)
        Create a new Boolean option with the given configuration.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new Boolean-based Option
      • bool

        public static Option<java.lang.Boolean> bool​(java.lang.String longName,
                                                     java.lang.Enum category,
                                                     java.lang.Boolean defval,
                                                     java.lang.String description)
        Create a new Boolean option with the given configuration.
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new Boolean-based Option
      • integer

        public static Option<java.lang.Integer> integer​(java.lang.String prefix,
                                                        java.lang.String shortName,
                                                        java.lang.Enum category,
                                                        java.lang.String description)
        Create a new Integer option with the given configuration.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        description - a description for the option
        Returns:
        a new Integer-based Option
      • integer

        public static Option<java.lang.Integer> integer​(java.lang.String prefix,
                                                        java.lang.String shortName,
                                                        java.lang.Enum category,
                                                        java.lang.Integer[] options,
                                                        java.lang.String description)
        Create a new Integer option with the given configuration.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        options - a list of supported for the option, or null if the set is not applicable
        description - a description for the option
        Returns:
        a new Integer-based Option
      • integer

        public static Option<java.lang.Integer> integer​(java.lang.String longName,
                                                        java.lang.Enum category,
                                                        java.lang.String description)
        Create a new Integer option with the given configuration.
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        description - a description for the option
        Returns:
        a new Integer-based Option
      • integer

        public static Option<java.lang.Integer> integer​(java.lang.String longName,
                                                        java.lang.Enum category,
                                                        java.lang.Integer[] options,
                                                        java.lang.String description)
        Create a new Integer option with the given configuration.
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        options - a list of supported for the option, or null if the set is not applicable
        description - a description for the option
        Returns:
        a new Integer-based Option
      • integer

        public static Option<java.lang.Integer> integer​(java.lang.String prefix,
                                                        java.lang.String shortName,
                                                        java.lang.Enum category,
                                                        java.lang.Integer defval,
                                                        java.lang.String description)
        Create a new Integer option with the given configuration.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new Integer-based Option
      • integer

        public static Option<java.lang.Integer> integer​(java.lang.String longName,
                                                        java.lang.Enum category,
                                                        java.lang.Integer defval,
                                                        java.lang.String description)
        Create a new Integer option with the given configuration.
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new Integer-based Option
      • integer

        public static Option<java.lang.Integer> integer​(java.lang.String prefix,
                                                        java.lang.String shortName,
                                                        java.lang.Enum category,
                                                        java.lang.Integer[] options,
                                                        java.lang.Integer defval,
                                                        java.lang.String description)
        Create a new Integer option with the given configuration.
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        options - a list of supported for the option, or null if the set is not applicable
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new Integer-based Option
      • integer

        public static Option<java.lang.Integer> integer​(java.lang.String longName,
                                                        java.lang.Enum category,
                                                        java.lang.Integer[] options,
                                                        java.lang.Integer defval,
                                                        java.lang.String description)
        Create a new Integer option with the given configuration.
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        options - a list of supported for the option, or null if the set is not applicable
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new Integer-based Option
      • enumeration

        public static <T extends java.lang.Enum<T>> Option<T> enumeration​(java.lang.String prefix,
                                                                          java.lang.String shortName,
                                                                          java.lang.Enum category,
                                                                          java.lang.Class<T> enumClass,
                                                                          java.lang.String description)
        Create a new Enumeration-based option with the given configuration.
        Type Parameters:
        T - the type of the enum
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        description - a description for the option
        Returns:
        a new Enumeration-based Option
      • enumeration

        public static <T extends java.lang.Enum<T>> Option<T> enumeration​(java.lang.String longName,
                                                                          java.lang.Enum category,
                                                                          java.lang.Class<T> enumClass,
                                                                          java.lang.String description)
        Create a new Enumeration-based option with the given configuration.
        Type Parameters:
        T - the type of the enum
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        description - a description for the option
        Returns:
        a new Enumeration-based Option
      • enumeration

        public static <T extends java.lang.Enum<T>> Option<T> enumeration​(java.lang.String prefix,
                                                                          java.lang.String shortName,
                                                                          java.lang.Enum category,
                                                                          T defval,
                                                                          java.lang.String description)
        Create a new Enumeration-based option with the given configuration.
        Type Parameters:
        T - the type of the enum
        Parameters:
        prefix - the prefix used for loading this option from properties
        shortName - the rest of the property name
        category - the category to which this option belongs
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new Enumeration-based Option
      • enumeration

        public static <T extends java.lang.Enum<T>> Option<T> enumeration​(java.lang.String longName,
                                                                          java.lang.Enum category,
                                                                          T defval,
                                                                          java.lang.String description)
        Create a new Enumeration-based option with the given configuration.
        Type Parameters:
        T - the type of the enum
        Parameters:
        longName - the property name
        category - the category to which this option belongs
        defval - the default value for the option
        description - a description for the option
        Returns:
        a new Enumeration-based Option
      • formatValues

        public static java.lang.String formatValues​(Option... options)
        Format the given options to show their loaded values in the current JVM.
        Parameters:
        options - the options to format
        Returns:
        a formatted string representing the options
      • formatValues

        public static java.lang.String formatValues​(java.util.Collection<Option> options)
        Format the given options to show their loaded values in the current JVM.
        Parameters:
        options - the options to format
        Returns:
        a formatted string representing the options
      • formatOptions

        public static java.lang.String formatOptions​(Option... options)
        Format the given options in a way suitable for use as a configuration file or documentation.
        Parameters:
        options - the options to format
        Returns:
        a formatted string representing the options as a config file or document
      • formatOptions

        public static java.lang.String formatOptions​(java.util.Collection<Option> options)
        Format the given options in a way suitable for use as a configuration file or documentation.
        Parameters:
        options - the options to format
        Returns:
        a formatted string representing the options as a config file or document
      • encodeWhitespace

        private static java.lang.String encodeWhitespace​(java.lang.Object obj)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • loadProperty

        public java.lang.String loadProperty()
        Load the option's property, as if by calling java.lang.System#getProperty
        Returns:
        the option's property's current value, or a value previously forced into this option by force(String)
      • isSpecified

        public boolean isSpecified()
        Returns:
        true if the option's property was specified, false otherwise.
      • load

        public final T load()
        Returns:
        the value of the option, loading if it has not been already.
      • reload

        public final T reload()
        Force a load of the option's property and return the loaded value.
        Returns:
        the loaded value
      • force

        public void force​(java.lang.String value)
        Force the property value to the given value for all future loads and reloads.
        Parameters:
        value - a value to force for the Option's property, as if set in JVM
      • unforce

        public void unforce()
        Undoes any previous force, and goes back to an unloaded state.
      • reloadValue

        protected abstract T reloadValue()
        Perform the appropriate load and conversion for the option's property.
        Returns:
        the updated value after reload
      • shortName

        public java.lang.String shortName()
        If the option has a short name, return it. Otherwise null.
        Returns:
        the short name, or else null
      • propertyName

        public java.lang.String propertyName()
        Returns:
        the full property name for the option.
      • prefix

        public java.lang.String prefix()
        If the property has a prefix, return it. Otherwise null.
        Returns:
        the property prefix, or else null
      • displayName

        public java.lang.String displayName()
        The display name of the option's property, either the short name or the full name.
        Returns:
        the full display name of this option's property
      • type

        public java.lang.Class<T> type()
        The type returned for the option.
        Returns:
        the type of option that this is
      • options

        public T[] options()
        The array of accepted values for the option, or null if any values are accepted.
        Returns:
        an array of accepted values, or null if any values are allowed
      • defaultValue

        public T defaultValue()
        Returns:
        the default value for the option, or null if no default is provided.
      • description

        public java.lang.String description()
        Returns:
        the long description of the property, as for documentation and configuration file templates.