Top Description Inners Fields Constructors Methods
org.xnio

public abstract Class Option<T>

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.xnio.SequenceOption, org.xnio.SingleOption, org.xnio.TypeOption, org.xnio.TypeSequenceOption
Type Parameters
<T>
the option value type
Imports
java.io.InvalidObjectException, .ObjectStreamException, .Serializable, java.lang.reflect.Field, .Modifier, java.util.ArrayList, .Collection, .Collections, .HashMap, .LinkedHashSet, .List, .Map, .Set

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Option.SetBuilder

A builder for an immutable option set.

pack-priv static interface

Field Summary

Modifier and TypeField and Description
private final Class<?>
private final String
private static final Option.ValueParser<?>
private static final Map<Class<?>, Option.ValueParser<?>>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
Option(final Class<?> declClass, final String name)

Method Summary

Modifier and TypeMethod and Description
private static <T, E extends Enum<E>> Class<E>
asEnum(final Class<T> enumType)

public abstract T

Returns:

the cast object
cast
(Object
the object to cast
o
)

Return the given object as the type of this option.

public final T

Returns:

the cast object
cast
(Object
the object to cast
o
,
T
the value to return if o is null
defaultVal
)

Return the given object as the type of this option.

public static Option<?>

Returns:

the option
fromString
(String
the option string
name
,
ClassLoader
the class loader
classLoader
)

Get an option from a string name, using the given classloader.

pack-priv static <T> Option.ValueParser<Class<? extends T>>
getClassParser(final Class<T> argType)

pack-priv static <T, E extends Enum<E>> Option.ValueParser<T>
getEnumParser(final Class<T> enumType)

public String

Returns:

the option name
getName
()

Get the name of this option.

pack-priv static <T> Option.ValueParser<T>
getParser(final Class<T> argType)

public abstract T

Returns:

the parsed value
parseValue
(String
the string
string
,
ClassLoader
the class loader to use to parse the value
classLoader
)

Parse a string value for this option.

protected final Object

Returns:

the resolved object
readResolve
()

Resolve this instance for serialization.

public static <T> Option<Sequence<T>>

Returns:

the option instance
sequence
(final Class<?>
the declaring class of the option
declClass
,
final String
the (field) name of this option
name
,
final Class<T>
the class of the sequence element value associated with this option
elementType
)

Create an option with a sequence type.

public static Option.SetBuilder

Returns:

the builder
setBuilder
()

Create a builder for an immutable option set.

public static <T> Option<T>

Returns:

the option instance
simple
(final Class<?>
the declaring class of the option
declClass
,
final String
the (field) name of this option
name
,
final Class<T>
the class of the value associated with this option
type
)

Create an option with a simple type.

public String

Returns:

the string representation
toString
()

Overrides java.lang.Object.toString.

Get a human-readable string representation of this object.

public static <
the type of the class object given
T
>
Option<Class<? extends T>>

Returns:

the option instance
type
(final Class<?>
the declaring class of the option
declClass
,
final String
the (field) name of this option
name
,
final Class<T>
the class object for the type of the class object given
declType
)

Create an option with a class type.

public static <
the type of the sequence element class object given
T
>
Option<Sequence<Class<? extends T>>>

Returns:

the option instance
typeSequence
(final Class<?>
the declaring class of the option
declClass
,
final String
the (field) name of this option
name
,
final Class<T>
the class object for the type of the sequence element class object given
elementDeclType
)

Create an option with a sequence-of-types type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

declClassback to summary
private final Class<?> declClass
nameback to summary
private final String name
noParserback to summary
private static final Option.ValueParser<?> noParser
parsersback to summary
private static final Map<Class<?>, Option.ValueParser<?>> parsers
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

Optionback to summary
pack-priv Option(final Class<?> declClass, final String name)

Method Detail

asEnumback to summary
private static <T, E extends Enum<E>> Class<E> asEnum(final Class<T> enumType)
Annotations
@SuppressWarnings:unchecked
castback to summary
public abstract T cast(Object o) throws ClassCastException

Return the given object as the type of this option. If the cast could not be completed, an exception is thrown.

Parameters
o:Object

the object to cast

Returns:T

the cast object

Exceptions
ClassCastException:
if the object is not of a compatible type
castback to summary
public final T cast(Object o, T defaultVal) throws ClassCastException

Return the given object as the type of this option. If the cast could not be completed, an exception is thrown.

Parameters
o:Object

the object to cast

defaultVal:T

the value to return if o is null

Returns:T

the cast object

Exceptions
ClassCastException:
if the object is not of a compatible type
fromStringback to summary
public static Option<?> fromString(String name, ClassLoader classLoader) throws IllegalArgumentException

Get an option from a string name, using the given classloader. If the classloader is null, the bootstrap classloader will be used.

Parameters
name:String

the option string

classLoader:ClassLoader

the class loader

Returns:Option<?>

the option

Exceptions
IllegalArgumentException:
if the given option name is not valid
getClassParserback to summary
pack-priv static <T> Option.ValueParser<Class<? extends T>> getClassParser(final Class<T> argType)
getEnumParserback to summary
pack-priv static <T, E extends Enum<E>> Option.ValueParser<T> getEnumParser(final Class<T> enumType)
getNameback to summary
public String getName()

Get the name of this option.

Returns:String

the option name

getParserback to summary
pack-priv static <T> Option.ValueParser<T> getParser(final Class<T> argType)
Annotations
@SuppressWarnings:unchecked
parseValueback to summary
public abstract T parseValue(String string, ClassLoader classLoader) throws IllegalArgumentException

Parse a string value for this option.

Parameters
string:String

the string

classLoader:ClassLoader

the class loader to use to parse the value

Returns:T

the parsed value

Exceptions
IllegalArgumentException:
if the argument could not be parsed
readResolveback to summary
protected final Object readResolve() throws ObjectStreamException

Resolve this instance for serialization.

Returns:Object

the resolved object

Exceptions
ObjectStreamException:
if the object could not be resolved
sequenceback to summary
public static <T> Option<Sequence<T>> sequence(final Class<?> declClass, final String name, final 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:Class<?>

the declaring class of the option

name:String

the (field) name of this option

elementType:Class<T>

the class of the sequence element value associated with this option

Returns:Option<Sequence<T>>

the option instance

setBuilderback to summary
public static Option.SetBuilder setBuilder()

Create a builder for an immutable option set.

Returns:Option.SetBuilder

the builder

simpleback to summary
public static <T> Option<T> simple(final Class<?> declClass, final String name, final 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:Class<?>

the declaring class of the option

name:String

the (field) name of this option

type:Class<T>

the class of the value associated with this option

Returns:Option<T>

the option instance

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Get a human-readable string representation of this object.

Returns:String

the string representation

typeback to summary
public static <T> Option<Class<? extends T>> type(final Class<?> declClass, final String name, final Class<T> declType)

Create an option with a class type. The class object given may represent any type.

Parameters
<T>
the type of the class object given
declClass:Class<?>

the declaring class of the option

name:String

the (field) name of this option

declType:Class<T>

the class object for the type of the class object given

Returns:Option<Class<? extends T>>

the option instance

typeSequenceback to summary
public static <T> Option<Sequence<Class<? extends T>>> typeSequence(final Class<?> declClass, final String name, final Class<T> elementDeclType)

Create an option with a sequence-of-types type. The class object given may represent any type.

Parameters
<T>
the type of the sequence element class object given
declClass:Class<?>

the declaring class of the option

name:String

the (field) name of this option

elementDeclType:Class<T>

the class object for the type of the sequence element class object given

Returns:Option<Sequence<Class<? extends T>>>

the option instance

org.xnio back to summary

public Class Option.SetBuilder

extends Object
Class Inheritance

A builder for an immutable option set.

Field Summary

Modifier and TypeField and Description
private List<Option<?>>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Option.SetBuilder

Returns:

this builder
add
(Option<?>
the option to add
option
)

Add an option to this set.

public Option.SetBuilder

Returns:

this builder
add
(Option<?>
the first option to add
option1
,
Option<?>
the second option to add
option2
)

Add options to this set.

public Option.SetBuilder

Returns:

this builder
add
(Option<?>
the first option to add
option1
,
Option<?>
the second option to add
option2
,
Option<?>
the third option to add
option3
)

Add options to this set.

public Option.SetBuilder

Returns:

this builder
add
(Option<?>...
the options to add
options
)

Add options to this set.

public Option.SetBuilder

Returns:

this builder
addAll
(Collection<Option<?>>
the options to add
options
)

Add all options from a collection to this set.

public Set<Option<?>>

Returns:

the option set
create
()

Create the immutable option set instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

optionSetback to summary
private List<Option<?>> optionSet

Constructor Detail

SetBuilderback to summary
pack-priv SetBuilder()

Method Detail

addback to summary
public Option.SetBuilder add(Option<?> option)

Add an option to this set.

Parameters
option:Option<?>

the option to add

Returns:Option.SetBuilder

this builder

addback to summary
public Option.SetBuilder add(Option<?> option1, Option<?> option2)

Add options to this set.

Parameters
option1:Option<?>

the first option to add

option2:Option<?>

the second option to add

Returns:Option.SetBuilder

this builder

addback to summary
public Option.SetBuilder add(Option<?> option1, Option<?> option2, Option<?> option3)

Add options to this set.

Parameters
option1:Option<?>

the first option to add

option2:Option<?>

the second option to add

option3:Option<?>

the third option to add

Returns:Option.SetBuilder

this builder

addback to summary
public Option.SetBuilder add(Option<?>... options)

Add options to this set.

Parameters
options:Option<?>[]

the options to add

Returns:Option.SetBuilder

this builder

addAllback to summary
public Option.SetBuilder addAll(Collection<Option<?>> options)

Add all options from a collection to this set.

Parameters
options:Collection<Option<?>>

the options to add

Returns:Option.SetBuilder

this builder

createback to summary
public Set<Option<?>> create()

Create the immutable option set instance.

Returns:Set<Option<?>>

the option set

org.xnio back to summary

pack-priv Interface Option.ValueParser<T>


Method Summary

Modifier and TypeMethod and Description
public T
parseValue(String string, ClassLoader classLoader)

Method Detail

parseValueback to summary
public T parseValue(String string, ClassLoader classLoader) throws IllegalArgumentException