Package com.headius.options
Class Option<T>
java.lang.Object
com.headius.options.Option<T>
- Type Parameters:
T
- the type of value associated with the option
- Direct Known Subclasses:
BooleanOption
,EnumerationOption
,IntegerOption
,StringOption
Represents a single option, with a category, name, value type,
options, default value, and description.
This type should be subclassed for specific types of values.
- See Also:
-
StringOption
IntegerOption
BooleanOption
EnumerationOption
string(java.lang.String, java.lang.String, java.lang.Enum, java.lang.String)
integer(java.lang.String, java.lang.String, java.lang.Enum, java.lang.String)
bool(java.lang.String, java.lang.String, java.lang.Enum, java.lang.String)
enumeration(java.lang.String, java.lang.String, java.lang.Enum, java.lang.Class<T>, java.lang.String)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate a new Boolean option with the given configuration.Create a new Boolean option with the given configuration.Create a new Boolean option with the given configuration.Create a new Boolean option with the given configuration.The display name of the option's property, either the short name or the full name.enumeration
(String longName, Enum category, Class<T> enumClass, String description) Create a new Enumeration-based option with the given configuration.enumeration
(String longName, Enum category, T defval, String description) Create a new Enumeration-based option with the given configuration.Create a new Enumeration-based option with the given configuration.enumeration
(String prefix, String shortName, Enum category, T defval, String description) Create a new Enumeration-based option with the given configuration.void
Force the property value to the given value for all future loads and reloads.static String
formatOptions
(Option... options) Format the given options in a way suitable for use as a configuration file or documentation.static String
formatOptions
(Collection<Option> options) Format the given options in a way suitable for use as a configuration file or documentation.static String
formatValues
(Option... options) Format the given options to show their loaded values in the current JVM.static String
formatValues
(Collection<Option> options) Format the given options to show their loaded values in the current JVM.Create a new Integer option with the given configuration.Create a new Integer option with the given configuration.Create a new Integer option with the given configuration.Create a new Integer option with the given configuration.integer
(String prefix, String shortName, Enum category, Integer[] options, Integer defval, String description) Create a new Integer option with the given configuration.Create a new Integer option with the given configuration.Create a new Integer option with the given configuration.Create a new Integer option with the given configuration.boolean
final T
load()
Load the option's property, as if by calling java.lang.System#getPropertyT[]
options()
The array of accepted values for the option, or null if any values are accepted.prefix()
If the property has a prefix, return it.final T
reload()
Force a load of the option's property and return the loaded value.protected abstract T
Perform the appropriate load and conversion for the option's property.If the option has a short name, return it.Create a new String option with the given configuration.Create a new String option with the given configuration.Create a new String option with the given configuration.Create a new String option with the given configuration.Create a new String option with the given configuration.Create a new String option with the given configuration.string
(String prefix, String shortName, Enum category, String[] options, String defval, String description) Create a new String option with the given configuration.Create a new String option with the given configuration.toString()
type()
The type returned for the option.void
unforce()
Undoes any previous force, and goes back to an unloaded state.
-
Field Details
-
type
-
defval
-
-
Constructor Details
-
Option
public Option(String prefix, String shortName, Class<T> type, Enum category, T[] options, T defval, String description) Create a new option with the given values.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property nametype
- the value type of the optioncategory
- the category to which this option belongsoptions
- a list of supported for the option, or null if the set is not applicabledefval
- the default value for the optiondescription
- a description for the option
-
Option
public Option(String longName, Class<T> type, Enum category, T[] options, T defval, String description) Create a new option with the given values.- Parameters:
longName
- the property nametype
- the value type of the optioncategory
- the category to which this option belongsoptions
- a list of supported for the option, or null if the set is not applicabledefval
- the default value for the optiondescription
- a description for the option
-
-
Method Details
-
string
public static Option<String> string(String prefix, String shortName, Enum category, String description) Create a new String option with the given configuration.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsdescription
- a description for the option- Returns:
- a new String-based option
-
string
Create a new String option with the given configuration.- Parameters:
longName
- the property namecategory
- the category to which this option belongsdescription
- a description for the option- Returns:
- a new String-based option
-
string
public static Option<String> string(String prefix, String shortName, Enum category, String defval, String description) Create a new String option with the given configuration.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsdefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new String-based Option
-
string
public static Option<String> string(String longName, Enum category, String defval, String description) Create a new String option with the given configuration.- Parameters:
longName
- the property namecategory
- the category to which this option belongsdefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new String-based Option
-
string
public static Option<String> string(String prefix, String shortName, Enum category, String[] options, String description) Create a new String option with the given configuration.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsoptions
- a list of supported for the option, or null if the set is not applicabledescription
- a description for the option- Returns:
- a new String-based Option
-
string
public static Option<String> string(String longName, Enum category, String[] options, String description) Create a new String option with the given configuration.- Parameters:
longName
- the property namecategory
- the category to which this option belongsoptions
- a list of supported for the option, or null if the set is not applicabledescription
- a description for the option- Returns:
- a new String-based Option
-
string
public static Option<String> string(String prefix, String shortName, Enum category, String[] options, String defval, String description) Create a new String option with the given configuration.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsoptions
- a list of supported for the option, or null if the set is not applicabledefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new String-based Option
-
string
public static Option<String> string(String longName, Enum category, String[] options, String defval, String description) Create a new String option with the given configuration.- Parameters:
longName
- the property namecategory
- the category to which this option belongsoptions
- a list of supported for the option, or null if the set is not applicabledefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new String-based Option
-
bool
public static Option<Boolean> bool(String prefix, String shortName, Enum category, String description) Create a new Boolean option with the given configuration.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsdescription
- a description for the option- Returns:
- a new Boolean-based Option
-
bool
Create a new Boolean option with the given configuration.- Parameters:
longName
- the property namecategory
- the category to which this option belongsdescription
- a description for the option- Returns:
- a new Boolean-based Option
-
bool
public static Option<Boolean> bool(String prefix, String shortName, Enum category, Boolean defval, String description) Create a new Boolean option with the given configuration.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsdefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new Boolean-based Option
-
bool
public static Option<Boolean> bool(String longName, Enum category, Boolean defval, String description) Create a new Boolean option with the given configuration.- Parameters:
longName
- the property namecategory
- the category to which this option belongsdefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new Boolean-based Option
-
integer
public static Option<Integer> integer(String prefix, String shortName, Enum category, String description) Create a new Integer option with the given configuration.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsdescription
- a description for the option- Returns:
- a new Integer-based Option
-
integer
public static Option<Integer> integer(String prefix, String shortName, Enum category, Integer[] options, String description) Create a new Integer option with the given configuration.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsoptions
- a list of supported for the option, or null if the set is not applicabledescription
- a description for the option- Returns:
- a new Integer-based Option
-
integer
Create a new Integer option with the given configuration.- Parameters:
longName
- the property namecategory
- the category to which this option belongsdescription
- a description for the option- Returns:
- a new Integer-based Option
-
integer
public static Option<Integer> integer(String longName, Enum category, Integer[] options, String description) Create a new Integer option with the given configuration.- Parameters:
longName
- the property namecategory
- the category to which this option belongsoptions
- a list of supported for the option, or null if the set is not applicabledescription
- a description for the option- Returns:
- a new Integer-based Option
-
integer
public static Option<Integer> integer(String prefix, String shortName, Enum category, Integer defval, String description) Create a new Integer option with the given configuration.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsdefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new Integer-based Option
-
integer
public static Option<Integer> integer(String longName, Enum category, Integer defval, String description) Create a new Integer option with the given configuration.- Parameters:
longName
- the property namecategory
- the category to which this option belongsdefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new Integer-based Option
-
integer
public static Option<Integer> integer(String prefix, String shortName, Enum category, Integer[] options, Integer defval, String description) Create a new Integer option with the given configuration.- Parameters:
prefix
- the prefix used for loading this option from propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsoptions
- a list of supported for the option, or null if the set is not applicabledefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new Integer-based Option
-
integer
public static Option<Integer> integer(String longName, Enum category, Integer[] options, Integer defval, String description) Create a new Integer option with the given configuration.- Parameters:
longName
- the property namecategory
- the category to which this option belongsoptions
- a list of supported for the option, or null if the set is not applicabledefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new Integer-based Option
-
enumeration
public static <T extends Enum<T>> Option<T> enumeration(String prefix, String shortName, Enum category, Class<T> enumClass, 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 propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsdescription
- a description for the option- Returns:
- a new Enumeration-based Option
-
enumeration
public static <T extends Enum<T>> Option<T> enumeration(String longName, Enum category, Class<T> enumClass, String description) Create a new Enumeration-based option with the given configuration.- Type Parameters:
T
- the type of the enum- Parameters:
longName
- the property namecategory
- the category to which this option belongsdescription
- a description for the option- Returns:
- a new Enumeration-based Option
-
enumeration
public static <T extends Enum<T>> Option<T> enumeration(String prefix, String shortName, Enum category, T defval, 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 propertiesshortName
- the rest of the property namecategory
- the category to which this option belongsdefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new Enumeration-based Option
-
enumeration
public static <T extends Enum<T>> Option<T> enumeration(String longName, Enum category, T defval, String description) Create a new Enumeration-based option with the given configuration.- Type Parameters:
T
- the type of the enum- Parameters:
longName
- the property namecategory
- the category to which this option belongsdefval
- the default value for the optiondescription
- a description for the option- Returns:
- a new Enumeration-based Option
-
formatValues
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
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
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
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
-
toString
-
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
- Returns:
- the value of the option, loading if it has not been already.
-
reload
Force a load of the option's property and return the loaded value.- Returns:
- the loaded value
-
force
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
Perform the appropriate load and conversion for the option's property.- Returns:
- the updated value after reload
-
shortName
If the option has a short name, return it. Otherwise null.- Returns:
- the short name, or else null
-
propertyName
- Returns:
- the full property name for the option.
-
prefix
If the property has a prefix, return it. Otherwise null.- Returns:
- the property prefix, or else null
-
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
The type returned for the option.- Returns:
- the type of option that this is
-
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
- Returns:
- the default value for the option, or null if no default is provided.
-
description
- Returns:
- the long description of the property, as for documentation and configuration file templates.
-