- java.lang.Object
-
- org.xnio.OptionMap
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<Option<?>>
public final class OptionMap extends java.lang.Object implements java.lang.Iterable<Option<?>>, java.io.Serializable
An immutable map of options to option values. Nonull
keys or values are permitted.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OptionMap.Builder
A builder for immutable option maps.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static OptionMap.Builder
builder()
Create a new builder.boolean
contains(Option<?> option)
Determine whether this option map contains the given option.static <T> OptionMap
create(Option<T> option, T value)
Create a single-valued option map.static <T1,T2>
OptionMapcreate(Option<T1> option1, T1 value1, Option<T2> option2, T2 value2)
Create a two-valued option map.boolean
equals(java.lang.Object other)
Determine whether this option map is equal to another.boolean
equals(OptionMap other)
Determine whether this option map is equal to another.boolean
get(Option<java.lang.Boolean> option, boolean defaultValue)
Get a boolean value from this option map, with a specified default if the value is missing.int
get(Option<java.lang.Integer> option, int defaultValue)
Get a int value from this option map, with a specified default if the value is missing.long
get(Option<java.lang.Long> option, long defaultValue)
Get a long value from this option map, with a specified default if the value is missing.<T> T
get(Option<T> option)
Get the value of an option from this option map.<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.int
hashCode()
Get the hash code for this option map.java.util.Iterator<Option<?>>
iterator()
Iterate over the options in this map.int
size()
Get the number of options stored in this map.java.lang.String
toString()
-
-
-
Field Detail
-
EMPTY
public static final OptionMap EMPTY
The empty option map.
-
-
Method Detail
-
contains
public boolean contains(Option<?> option)
Determine whether this option map contains the given option.- Parameters:
option
- the option to check- Returns:
true
if the option is present in the option map
-
get
public <T> T get(Option<T> option)
Get the value of an option from this option map.- Type Parameters:
T
- the type of the option- Parameters:
option
- the option to get- Returns:
- the option value, or
null
if it is not present
-
get
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.- Type Parameters:
T
- the type of the option- Parameters:
option
- the option to getdefaultValue
- the value to return if the option is not set- Returns:
- the option value, or
null
if it is not present
-
get
public boolean get(Option<java.lang.Boolean> option, boolean defaultValue)
Get a boolean value from this option map, with a specified default if the value is missing.- Parameters:
option
- the option to getdefaultValue
- the default value if the option is not present- Returns:
- the result
-
get
public int get(Option<java.lang.Integer> option, int defaultValue)
Get a int value from this option map, with a specified default if the value is missing.- Parameters:
option
- the option to getdefaultValue
- the default value if the option is not present- Returns:
- the result
-
get
public long get(Option<java.lang.Long> option, long defaultValue)
Get a long value from this option map, with a specified default if the value is missing.- Parameters:
option
- the option to getdefaultValue
- the default value if the option is not present- Returns:
- the result
-
iterator
public java.util.Iterator<Option<?>> iterator()
Iterate over the options in this map.- Specified by:
iterator
in interfacejava.lang.Iterable<Option<?>>
- Returns:
- an iterator over the options
-
size
public int size()
Get the number of options stored in this map.- Returns:
- the number of options
-
builder
public static OptionMap.Builder builder()
Create a new builder.- Returns:
- a new builder
-
create
public static <T> OptionMap create(Option<T> option, T value)
Create a single-valued option map.- Type Parameters:
T
- the option value type- Parameters:
option
- the option to put in the mapvalue
- the option value- Returns:
- the option map
- Since:
- 3.0
-
create
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.- Type Parameters:
T1
- the first option value typeT2
- the second option value type- Parameters:
option1
- the first option to put in the mapvalue1
- the first option valueoption2
- the second option to put in the mapvalue2
- the second option value- Returns:
- the option map
- Since:
- 3.0
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
Determine whether this option map is equal to another.- Overrides:
equals
in classjava.lang.Object
- Parameters:
other
- the other option map- Returns:
true
if they are equal,false
otherwise
-
equals
public boolean equals(OptionMap other)
Determine whether this option map is equal to another.- Parameters:
other
- the other option map- Returns:
true
if they are equal,false
otherwise
-
hashCode
public int hashCode()
Get the hash code for this option map.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code
-
-