Package org.xnio

# Class Option<T>

java.lang.Object
org.xnio.Option<T>

Type Parameters:
  `T` - the option value type

All Implemented Interfaces:
  `Serializable`

public abstract class Option<T> extends Object implements 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:
  - 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

Modifier and Type
Method
Description
`abstract T`
`cast(Object o)`
Return the given object as the type of this option.
`final T`
`cast(Object o, T defaultVal)`
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.
`String`
`getName()`
Get the name of this option.
`abstract T`
`parseValue(String string, ClassLoader classLoader)`
Parse a string value for this option.
`protected final Object`
`readResolve()`
Resolve this instance for serialization.
`static <T> Option<Sequence<T>>`
`sequence(Class<?> declClass, String name, 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(Class<?> declClass, String name, Class<T> type)`
Create an option with a simple type.
`String`
`toString()`
Get a human-readable string representation of this object.
`static <T> Option<Class<? extends T>>`
`type(Class<?> declClass, String name, Class<T> declType)`
Create an option with a class type.
`static <T> Option<Sequence<Class<? extends T>>>`
`typeSequence(Class<?> declClass, String name, Class<T> elementDeclType)`
Create an option with a sequence-of-types type.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Method Details

### simple

public static <T> Option<T> simple(Class<?> declClass, String name, 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 option
  `name` - the (field) name of this option
  `type` - 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 option
  `name` - the (field) name of this option
  `elementType` - 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 option
  `name` - the (field) name of this option
  `declType` - 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 option
  `name` - the (field) name of this option
  `elementDeclType` - the class object for the type of the sequence element class object given
Returns:
  the option instance

### getName

public String getName()
Get the name of this option.

Returns:
  the option name

### toString

public String toString()
Get a human-readable string representation of this object.

Overrides:
  `toString` in class `Object`
Returns:
  the string representation

### 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 is `null`, the bootstrap classloader will be used.

Parameters:
  `name` - the option string
  `classLoader` - the class loader
Returns:
  the option
Throws:
  `IllegalArgumentException` - if the given option name is not valid

### cast

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` - the object to cast
Returns:
  the cast object
Throws:
  `ClassCastException` - if the object is not of a compatible type

### cast

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` - the object to cast
  `defaultVal` - the value to return if `o` is `null`
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 string
  `classLoader` - the class loader to use to parse the value
Returns:
  the parsed value
Throws:
  `IllegalArgumentException` - if the argument could not be parsed

### readResolve

protected final Object readResolve() throws ObjectStreamException
Resolve this instance for serialization.

Returns:
  the resolved object
Throws:
  `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