- java.lang.Object
-
- org.xnio.Option<T>
-
- Type Parameters:
T
- the option value type
- All Implemented Interfaces:
java.io.Serializable
public abstract class Option<T> extends java.lang.Object implements java.io.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 aspublic static final
members in order to support serialization.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Option.SetBuilder
A builder for an immutable option set.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract T
cast(java.lang.Object o)
Return the given object as the type of this option.T
cast(java.lang.Object o, T defaultVal)
Return the given object as the type of this option.static Option<?>
fromString(java.lang.String name, java.lang.ClassLoader classLoader)
Get an option from a string name, using the given classloader.java.lang.String
getName()
Get the name of this option.abstract T
parseValue(java.lang.String string, java.lang.ClassLoader classLoader)
Parse a string value for this option.protected java.lang.Object
readResolve()
Resolve this instance for serialization.static <T> Option<Sequence<T>>
sequence(java.lang.Class<?> declClass, java.lang.String name, java.lang.Class<T> elementType)
Create an option with a sequence type.static Option.SetBuilder
setBuilder()
Create a builder for an immutable option set.static <T> Option<T>
simple(java.lang.Class<?> declClass, java.lang.String name, java.lang.Class<T> type)
Create an option with a simple type.java.lang.String
toString()
Get a human-readable string representation of this object.static <T> Option<java.lang.Class<? extends T>>
type(java.lang.Class<?> declClass, java.lang.String name, java.lang.Class<T> declType)
Create an option with a class type.static <T> Option<Sequence<java.lang.Class<? extends T>>>
typeSequence(java.lang.Class<?> declClass, java.lang.String name, java.lang.Class<T> elementDeclType)
Create an option with a sequence-of-types type.
-
-
-
Method Detail
-
simple
public static <T> Option<T> simple(java.lang.Class<?> declClass, java.lang.String name, java.lang.Class<T> type)
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(java.lang.Class<?> declClass, java.lang.String name, java.lang.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<java.lang.Class<? extends T>> type(java.lang.Class<?> declClass, java.lang.String name, java.lang.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<java.lang.Class<? extends T>>> typeSequence(java.lang.Class<?> declClass, java.lang.String name, java.lang.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
public java.lang.String getName()
Get the name of this option.- Returns:
- the option name
-
toString
public java.lang.String toString()
Get a human-readable string representation of this object.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the string representation
-
fromString
public static Option<?> fromString(java.lang.String name, java.lang.ClassLoader classLoader) throws java.lang.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:
java.lang.IllegalArgumentException
- if the given option name is not valid
-
cast
public abstract T cast(java.lang.Object o) throws java.lang.ClassCastException
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:
java.lang.ClassCastException
- if the object is not of a compatible type
-
cast
public final T cast(java.lang.Object o, T defaultVal) throws java.lang.ClassCastException
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:
java.lang.ClassCastException
- if the object is not of a compatible type
-
parseValue
public abstract T parseValue(java.lang.String string, java.lang.ClassLoader classLoader) throws java.lang.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:
java.lang.IllegalArgumentException
- if the argument could not be parsed
-
readResolve
protected final java.lang.Object readResolve() throws java.io.ObjectStreamException
Resolve this instance for serialization.- Returns:
- the resolved object
- Throws:
java.io.ObjectStreamException
- if the object could not be resolved
-
setBuilder
public static Option.SetBuilder setBuilder()
Create a builder for an immutable option set.- Returns:
- the builder
-
-