Package com.complexible.common.base
Class Options
- java.lang.Object
-
- com.complexible.common.base.Options
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Options
combine(Options... theOptionsArray)
Combines the given multiple options instances into one options instance.<V> boolean
contains(Option<V> option)
Returns true if this collection contains a value for the specified option.Options
copy()
Creates a mutable copy of the options instance.static Options
create()
Creates a new empty options instance.static Options
empty()
Creates a new empty immutable Options instance.boolean
equals(java.lang.Object o)
<V> V
get(Option<V> option)
Returns the value associated with the given option or the default value of the option if there is no associated value.int
hashCode()
static void
insert(Options theOptions, Options theOptionsToInsert)
Inserts the given options into the existing set of options.boolean
is(Option<java.lang.Boolean> option)
Returns the value associated with the given boolean option or the default value of the option if there is no associated value and the default value is notnull
orfalse
otherwise.java.util.Iterator<Option<java.lang.Object>>
iterator()
static <V> Options
of(Option<V> key, V value)
Creates a new options instance with the given single mapping.static <V1,V2>
Optionsof(Option<V1> key1, V1 value1, Option<V2> key2, V2 value2)
Creates a new options instance with the given two mappings.static <V1,V2,V3>
Optionsof(Option<V1> key1, V1 value1, Option<V2> key2, V2 value2, Option<V3> key3, V3 value3)
Creates a new options instance with the given three mappings.<V> V
remove(Option<V> option)
Removes any previous value associated with this option.<V> Options
set(Option<V> option, V value)
Associate the given value with the given option overriding any previous value.Options
setAll(Options theOptions)
Copies all of the option value mappings from the specified Options overriding any previous value.static <V> Options
singleton(Option<V> key, V value)
Creates an immutable option instance with the given single mapping.int
size()
java.lang.String
toString()
static Options
unmodifiable(Options options)
Creates an unmodifiable, shallow copy of the options instance.
-
-
-
Constructor Detail
-
Options
public Options()
-
Options
public Options(Options theOptions)
-
-
Method Detail
-
iterator
public java.util.Iterator<Option<java.lang.Object>> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<Option<java.lang.Object>>
-
copy
public Options copy()
Creates a mutable copy of the options instance. Updating the copy will not affect the original options. The copy can be modified even if the original options instance may not be modifiable.
-
create
public static Options create()
Creates a new empty options instance.
-
of
public static <V> Options of(Option<V> key, V value)
Creates a new options instance with the given single mapping.
-
of
public static <V1,V2> Options of(Option<V1> key1, V1 value1, Option<V2> key2, V2 value2)
Creates a new options instance with the given two mappings.
-
of
public static <V1,V2,V3> Options of(Option<V1> key1, V1 value1, Option<V2> key2, V2 value2, Option<V3> key3, V3 value3)
Creates a new options instance with the given three mappings.
-
contains
public <V> boolean contains(Option<V> option)
Returns true if this collection contains a value for the specified option.
-
get
public <V> V get(Option<V> option)
Returns the value associated with the given option or the default value of the option if there is no associated value. The default value for an option might benull
so there are cases this function will returnnull
values. Must be used with care in autoboxing.- See Also:
is(Option)
-
is
public boolean is(Option<java.lang.Boolean> option)
Returns the value associated with the given boolean option or the default value of the option if there is no associated value and the default value is notnull
orfalse
otherwise.
-
set
public <V> Options set(Option<V> option, V value)
Associate the given value with the given option overriding any previous value.
-
setAll
public Options setAll(Options theOptions)
Copies all of the option value mappings from the specified Options overriding any previous value. .- Returns:
- a reference to this object to allow method chaining
-
remove
public <V> V remove(Option<V> option)
Removes any previous value associated with this option.
-
insert
public static void insert(Options theOptions, Options theOptionsToInsert)
Inserts the given options into the existing set of options. Options will only be added if they do not already have a value specified in the existing options.- Parameters:
theOptions
- the options to insert intotheOptionsToInsert
- the new options to insert
-
combine
public static Options combine(Options... theOptionsArray)
Combines the given multiple options instances into one options instance. If there are duplicate options in the given arguments, the value that appears in the last options instance override any previous value.
-
unmodifiable
public static Options unmodifiable(Options options)
Creates an unmodifiable, shallow copy of the options instance. The unmodifiable copy cannot be updated directly but since it is a shallow copy updating the copy. If this needs to be avoidedOptions.unmodifiable(Options.copy())
can be used.- Returns:
- a new options instance that will throw exceptions on modification function
-
empty
public static Options empty()
Creates a new empty immutable Options instance.
-
singleton
public static <V> Options singleton(Option<V> key, V value)
Creates an immutable option instance with the given single mapping.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
size
public int size()
-
-