Top Description Inners Fields Constructors Methods
org.xnio

public final Class OptionMap

extends Object
implements Iterable<Option<?>>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Iterable
Imports
java.util.Iterator, .List, .ArrayList, .Map, .Collections, .IdentityHashMap, .Properties, java.io.Serializable

An immutable map of options to option values. No null keys or values are permitted.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
OptionMap.Builder

A builder for immutable option maps.

Field Summary

Modifier and TypeField and Description
public static final OptionMap
EMPTY

The empty option map.

private static final long
private final Map<Option<?>, Object>

Constructor Summary

AccessConstructor and Description
private
OptionMap(final Map<Option<?>, Object> value)

Method Summary

Modifier and TypeMethod and Description
public static OptionMap.Builder

Returns:

a new builder
builder
()

Create a new builder.

public boolean

Returns:

true if the option is present in the option map
contains
(Option<?>
the option to check
option
)

Determine whether this option map contains the given option.

public static <
the option value type
T
>
OptionMap

Returns:

the option map
create
(Option<T>
the option to put in the map
option
,
T
the option value
value
)

Create a single-valued option map.

public static <
the first option value type
T1
,
the second option value type
T2
>
OptionMap

Returns:

the option map
create
(Option<T1>
the first option to put in the map
option1
,
T1
the first option value
value1
,
Option<T2>
the second option to put in the map
option2
,
T2
the second option value
value2
)

Create a two-valued option map.

public boolean

Returns:

true if they are equal, false otherwise
equals
(Object
the other option map
other
)

Overrides java.lang.Object.equals.

Determine whether this option map is equal to another.

public boolean

Returns:

true if they are equal, false otherwise
equals
(OptionMap
the other option map
other
)

Determine whether this option map is equal to another.

public <
the type of the option
T
>
T

Returns:

the option value, or null if it is not present
get
(Option<T>
the option to get
option
)

Get the value of an option from this option map.

public <
the type of the option
T
>
T

Returns:

the option value, or null if it is not present
get
(Option<T>
the option to get
option
,
T
the value to return if the option is not set
defaultValue
)

Get the value of an option from this option map, with a specified default if the value is missing.

public boolean

Returns:

the result
get
(Option<Boolean>
the option to get
option
,
boolean
the default value if the option is not present
defaultValue
)

Get a boolean value from this option map, with a specified default if the value is missing.

public int

Returns:

the result
get
(Option<Integer>
the option to get
option
,
int
the default value if the option is not present
defaultValue
)

Get a int value from this option map, with a specified default if the value is missing.

public long

Returns:

the result
get
(Option<Long>
the option to get
option
,
long
the default value if the option is not present
defaultValue
)

Get a long value from this option map, with a specified default if the value is missing.

public int

Returns:

the hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Get the hash code for this option map.

public Iterator<Option<?>>

Returns:

an iterator over the options
iterator
()

Implements java.lang.Iterable.iterator.

Iterate over the options in this map.

public int

Returns:

the number of options
size
()

Get the number of options stored in this map.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

EMPTYback to summary
public static final OptionMap EMPTY

The empty option map.

serialVersionUIDback to summary
private static final long serialVersionUID
valueback to summary
private final Map<Option<?>, Object> value

Constructor Detail

OptionMapback to summary
private OptionMap(final Map<Option<?>, Object> value)

Method Detail

builderback to summary
public static OptionMap.Builder builder()

Create a new builder.

Returns:OptionMap.Builder

a new builder

containsback to summary
public boolean contains(Option<?> option)

Determine whether this option map contains the given option.

Parameters
option:Option<?>

the option to check

Returns:boolean

true if the option is present in the option map

createback to summary
public static <T> OptionMap create(Option<T> option, T value)

Create a single-valued option map.

Parameters
<T>
the option value type
option:Option<T>

the option to put in the map

value:T

the option value

Returns:OptionMap

the option map

Since
3.0
createback to summary
public static <T1, T2> OptionMap create(Option<T1> option1, T1 value1, Option<T2> option2, T2 value2)

Create a two-valued option map. If both options are the same key, then only the second one is added to the map.

Parameters
<T1>
the first option value type
<T2>
the second option value type
option1:Option<T1>

the first option to put in the map

value1:T1

the first option value

option2:Option<T2>

the second option to put in the map

value2:T2

the second option value

Returns:OptionMap

the option map

Since
3.0
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Determine whether this option map is equal to another.

Parameters
other:Object

the other option map

Returns:boolean

true if they are equal, false otherwise

equalsback to summary
public boolean equals(OptionMap other)

Determine whether this option map is equal to another.

Parameters
other:OptionMap

the other option map

Returns:boolean

true if they are equal, false otherwise

getback to summary
public <T> T get(Option<T> option)

Get the value of an option from this option map.

Parameters
<T>
the type of the option
option:Option<T>

the option to get

Returns:T

the option value, or null if it is not present

getback to summary
public <T> T get(Option<T> option, T defaultValue)

Get the value of an option from this option map, with a specified default if the value is missing.

Parameters
<T>
the type of the option
option:Option<T>

the option to get

defaultValue:T

the value to return if the option is not set

Returns:T

the option value, or null if it is not present

getback to summary
public boolean get(Option<Boolean> option, boolean defaultValue)

Get a boolean value from this option map, with a specified default if the value is missing.

Parameters
option:Option<Boolean>

the option to get

defaultValue:boolean

the default value if the option is not present

Returns:boolean

the result

getback to summary
public int get(Option<Integer> option, int defaultValue)

Get a int value from this option map, with a specified default if the value is missing.

Parameters
option:Option<Integer>

the option to get

defaultValue:int

the default value if the option is not present

Returns:int

the result

getback to summary
public long get(Option<Long> option, long defaultValue)

Get a long value from this option map, with a specified default if the value is missing.

Parameters
option:Option<Long>

the option to get

defaultValue:long

the default value if the option is not present

Returns:long

the result

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Get the hash code for this option map.

Returns:int

the hash code

iteratorback to summary
public Iterator<Option<?>> iterator()

Implements java.lang.Iterable.iterator.

Iterate over the options in this map.

Returns:Iterator<Option<?>>

an iterator over the options

sizeback to summary
public int size()

Get the number of options stored in this map.

Returns:int

the number of options

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

org.xnio back to summary

public final Class OptionMap.Builder

extends Object
Class Inheritance

A builder for immutable option maps. Create an instance with the OptionMap#builder() method.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private List<OptionMap.Builder.OVPair<?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public OptionMap.Builder

Returns:

this builder
add
(Map<?, ?>
the map
map
)

Add all the entries of a map.

public OptionMap.Builder

Returns:

this builder
addAll
(OptionMap
the original option map
optionMap
)

Add all entries from an existing option map to the one being built.

private <T> void
copy(Map<?, ?> map, Option<T> option)

private <T> void
copy(OptionMap optionMap, Option<T> option)

public OptionMap

Returns:

the new immutable option map
getMap
()

Build a map that reflects the current state of this builder.

public <
the option type
T
>
OptionMap.Builder

Returns:

this builder
parse
(Option<T>
the key
key
,
String
the string value
stringValue
)

Set a key-value pair, parsing the value from the given string.

public <
the option type
T
>
OptionMap.Builder

Returns:

this builder
parse
(Option<T>
the key
key
,
String
the string value
stringValue
,
ClassLoader
the class loader to use for parsing the value
classLoader
)

Set a key-value pair, parsing the value from the given string.

public OptionMap.Builder

Returns:

this builder
parseAll
(Properties
the properties to read
props
,
String
the prefix
prefix
,
ClassLoader
the class loader to use to resolve option names
optionClassLoader
)

Add all options from a properties file.

public OptionMap.Builder

Returns:

this builder
parseAll
(Properties
the properties to read
props
,
String
the prefix
prefix
)

Add all options from a properties file.

public <
the option type
T
>
OptionMap.Builder

Returns:

this builder
set
(Option<T>
the key
key
,
T
the value
value
)

Set a key-value pair.

public OptionMap.Builder

Returns:

this builder
set
(Option<Integer>
the option
key
,
int
the value
value
)

Set an int value for an Integer key.

public OptionMap.Builder

Returns:

this builder
set
(Option<Long>
the option
key
,
long
the value
value
)

Set a long value for a Long key.

public OptionMap.Builder

Returns:

this builder
set
(Option<Boolean>
the option
key
,
boolean
the value
value
)

Set a boolean value for a Boolean key.

public OptionMap.Builder

Returns:

this builder
setSequence
(Option<Sequence<Integer>>
the key
key
,
int...
the values
values
)

Set int values for an Integer sequence key.

public OptionMap.Builder

Returns:

this builder
setSequence
(Option<Sequence<Long>>
the key
key
,
long...
the values
values
)

Set long values for a Long sequence key.

public OptionMap.Builder

Returns:

this builder
setSequence
(Option<Sequence<Boolean>>
the key
key
,
boolean...
the values
values
)

Set boolean values for an Boolean sequence key.

public <
the option type
T
>
OptionMap.Builder

Returns:

this builder
setSequence
(Option<Sequence<T>>
the key
key
,
T...
the values
values
)

Set a key-value pair, where the value is a sequence type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

listback to summary
private List<OptionMap.Builder.OVPair<?>> list

Constructor Detail

Builderback to summary
private Builder()

Method Detail

addback to summary
public OptionMap.Builder add(Map<?, ?> map) throws ClassCastException

Add all the entries of a map. Any keys of the map which are not valid Options, or whose values are not valid arguments for the given Option, will cause an exception to be thrown. Any keys which occur more than once in this builder will be overwritten with the last occurring value.

Parameters
map:Map<?, ?>

the map

Returns:OptionMap.Builder

this builder

Exceptions
ClassCastException:
if any entries of the map are not valid option-value pairs
addAllback to summary
public OptionMap.Builder addAll(OptionMap optionMap)

Add all entries from an existing option map to the one being built. Any keys which occur more than once in this builder will be overwritten with the last occurring value.

Parameters
optionMap:OptionMap

the original option map

Returns:OptionMap.Builder

this builder

copyback to summary
private <T> void copy(Map<?, ?> map, Option<T> option)
copyback to summary
private <T> void copy(OptionMap optionMap, Option<T> option)
getMapback to summary
public OptionMap getMap()

Build a map that reflects the current state of this builder.

Returns:OptionMap

the new immutable option map

parseback to summary
public <T> OptionMap.Builder parse(Option<T> key, String stringValue)

Set a key-value pair, parsing the value from the given string.

Parameters
<T>
the option type
key:Option<T>

the key

stringValue:String

the string value

Returns:OptionMap.Builder

this builder

parseback to summary
public <T> OptionMap.Builder parse(Option<T> key, String stringValue, ClassLoader classLoader)

Set a key-value pair, parsing the value from the given string.

Parameters
<T>
the option type
key:Option<T>

the key

stringValue:String

the string value

classLoader:ClassLoader

the class loader to use for parsing the value

Returns:OptionMap.Builder

this builder

parseAllback to summary
public OptionMap.Builder parseAll(Properties props, String prefix, ClassLoader optionClassLoader)

Add all options from a properties file. Finds all entries which start with a given prefix followed by '.'; the remainder of the property key (after the prefix) is the option name, and the value is the option value.

If the prefix does not end with '.' character, a '.' will be appended to it before parsing.

Parameters
props:Properties

the properties to read

prefix:String

the prefix

optionClassLoader:ClassLoader

the class loader to use to resolve option names

Returns:OptionMap.Builder

this builder

parseAllback to summary
public OptionMap.Builder parseAll(Properties props, String prefix)

Add all options from a properties file. Finds all entries which start with a given prefix followed by '.'; the remainder of the property key (after the prefix) is the option name, and the value is the option value.

If the prefix does not end with '.' character, a '.' will be appended to it before parsing.

Parameters
props:Properties

the properties to read

prefix:String

the prefix

Returns:OptionMap.Builder

this builder

setback to summary
public <T> OptionMap.Builder set(Option<T> key, T value)

Set a key-value pair.

Parameters
<T>
the option type
key:Option<T>

the key

value:T

the value

Returns:OptionMap.Builder

this builder

setback to summary
public OptionMap.Builder set(Option<Integer> key, int value)

Set an int value for an Integer key.

Parameters
key:Option<Integer>

the option

value:int

the value

Returns:OptionMap.Builder

this builder

setback to summary
public OptionMap.Builder set(Option<Long> key, long value)

Set a long value for a Long key.

Parameters
key:Option<Long>

the option

value:long

the value

Returns:OptionMap.Builder

this builder

setback to summary
public OptionMap.Builder set(Option<Boolean> key, boolean value)

Set a boolean value for a Boolean key.

Parameters
key:Option<Boolean>

the option

value:boolean

the value

Returns:OptionMap.Builder

this builder

setSequenceback to summary
public OptionMap.Builder setSequence(Option<Sequence<Integer>> key, int... values)

Set int values for an Integer sequence key.

Parameters
key:Option<Sequence<Integer>>

the key

values:int[]

the values

Returns:OptionMap.Builder

this builder

setSequenceback to summary
public OptionMap.Builder setSequence(Option<Sequence<Long>> key, long... values)

Set long values for a Long sequence key.

Parameters
key:Option<Sequence<Long>>

the key

values:long[]

the values

Returns:OptionMap.Builder

this builder

setSequenceback to summary
public OptionMap.Builder setSequence(Option<Sequence<Boolean>> key, boolean... values)

Set boolean values for an Boolean sequence key.

Parameters
key:Option<Sequence<Boolean>>

the key

values:boolean[]

the values

Returns:OptionMap.Builder

this builder

setSequenceback to summary
public <T> OptionMap.Builder setSequence(Option<Sequence<T>> key, T... values)

Set a key-value pair, where the value is a sequence type.

Parameters
<T>
the option type
key:Option<Sequence<T>>

the key

values:T[]

the values

Returns:OptionMap.Builder

this builder

org.xnio back to summary

private Class OptionMap.Builder.OVPair<T>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv Option<T>
pack-priv T

Constructor Summary

AccessConstructor and Description
private
OVPair(final Option<T> option, final T value)

Field Detail

optionback to summary
pack-priv Option<T> option
valueback to summary
pack-priv T value

Constructor Detail

OVPairback to summary
private OVPair(final Option<T> option, final T value)