- 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. Nonullkeys or values are permitted.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOptionMap.BuilderA builder for immutable option maps.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static OptionMap.Builderbuilder()Create a new builder.booleancontains(Option<?> option)Determine whether this option map contains the given option.static <T> OptionMapcreate(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.booleanequals(java.lang.Object other)Determine whether this option map is equal to another.booleanequals(OptionMap other)Determine whether this option map is equal to another.booleanget(Option<java.lang.Boolean> option, boolean defaultValue)Get a boolean value from this option map, with a specified default if the value is missing.intget(Option<java.lang.Integer> option, int defaultValue)Get a int value from this option map, with a specified default if the value is missing.longget(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> Tget(Option<T> option)Get the value of an option from this option map.<T> Tget(Option<T> option, T defaultValue)Get the value of an option from this option map, with a specified default if the value is missing.inthashCode()Get the hash code for this option map.java.util.Iterator<Option<?>>iterator()Iterate over the options in this map.intsize()Get the number of options stored in this map.java.lang.StringtoString()
-
-
-
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:
trueif 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
nullif 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
nullif 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:
iteratorin 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:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
Determine whether this option map is equal to another.- Overrides:
equalsin classjava.lang.Object- Parameters:
other- the other option map- Returns:
trueif they are equal,falseotherwise
-
equals
public boolean equals(OptionMap other)
Determine whether this option map is equal to another.- Parameters:
other- the other option map- Returns:
trueif they are equal,falseotherwise
-
hashCode
public int hashCode()
Get the hash code for this option map.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code
-
-