Package org.xnio
Class Option<T>
java.lang.Object
org.xnio.Option<T>
- Type Parameters:
T
- the option value type
- All Implemented Interfaces:
Serializable
A strongly-typed option to configure an aspect of a service or connection. Options are immutable and use identity comparisons
and hash codes. Options should always be declared as
public static final
members in order to support serialization.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A builder for an immutable option set. -
Method Summary
Modifier and TypeMethodDescriptionabstract T
Return the given object as the type of this option.final T
Return the given object as the type of this option.static Option
<?> fromString
(String name, ClassLoader classLoader) Get an option from a string name, using the given classloader.getName()
Get the name of this option.abstract T
parseValue
(String string, ClassLoader classLoader) Parse a string value for this option.protected final Object
Resolve this instance for serialization.Create an option with a sequence type.static Option.SetBuilder
Create a builder for an immutable option set.static <T> Option
<T> Create an option with a simple type.toString()
Get a human-readable string representation of this object.Create an option with a class type.typeSequence
(Class<?> declClass, String name, Class<T> elementDeclType) Create an option with a sequence-of-types type.
-
Method Details
-
simple
Create an option with a simple type. The class object given must represent some immutable type, otherwise unexpected behavior may result.- Parameters:
declClass
- the declaring class of the optionname
- the (field) name of this optiontype
- the class of the value associated with this option- Returns:
- the option instance
-
sequence
public static <T> Option<Sequence<T>> sequence(Class<?> declClass, String name, Class<T> elementType) Create an option with a sequence type. The class object given must represent some immutable type, otherwise unexpected behavior may result.- Parameters:
declClass
- the declaring class of the optionname
- the (field) name of this optionelementType
- the class of the sequence element value associated with this option- Returns:
- the option instance
-
type
public static <T> Option<Class<? extends T>> type(Class<?> declClass, String name, Class<T> declType) Create an option with a class type. The class object given may represent any type.- Type Parameters:
T
- the type of the class object given- Parameters:
declClass
- the declaring class of the optionname
- the (field) name of this optiondeclType
- the class object for the type of the class object given- Returns:
- the option instance
-
typeSequence
public static <T> Option<Sequence<Class<? extends T>>> typeSequence(Class<?> declClass, String name, Class<T> elementDeclType) Create an option with a sequence-of-types type. The class object given may represent any type.- Type Parameters:
T
- the type of the sequence element class object given- Parameters:
declClass
- the declaring class of the optionname
- the (field) name of this optionelementDeclType
- the class object for the type of the sequence element class object given- Returns:
- the option instance
-
getName
Get the name of this option.- Returns:
- the option name
-
toString
Get a human-readable string representation of this object. -
fromString
public static Option<?> fromString(String name, ClassLoader classLoader) throws IllegalArgumentException Get an option from a string name, using the given classloader. If the classloader isnull
, the bootstrap classloader will be used.- Parameters:
name
- the option stringclassLoader
- the class loader- Returns:
- the option
- Throws:
IllegalArgumentException
- if the given option name is not valid
-
cast
Return the given object as the type of this option. If the cast could not be completed, an exception is thrown.- Parameters:
o
- the object to cast- Returns:
- the cast object
- Throws:
ClassCastException
- if the object is not of a compatible type
-
cast
Return the given object as the type of this option. If the cast could not be completed, an exception is thrown.- Parameters:
o
- the object to castdefaultVal
- the value to return ifo
isnull
- Returns:
- the cast object
- Throws:
ClassCastException
- if the object is not of a compatible type
-
parseValue
public abstract T parseValue(String string, ClassLoader classLoader) throws IllegalArgumentException Parse a string value for this option.- Parameters:
string
- the stringclassLoader
- the class loader to use to parse the value- Returns:
- the parsed value
- Throws:
IllegalArgumentException
- if the argument could not be parsed
-
readResolve
Resolve this instance for serialization.- Returns:
- the resolved object
- Throws:
ObjectStreamException
- if the object could not be resolved
-
setBuilder
Create a builder for an immutable option set.- Returns:
- the builder
-