Class Options

java.lang.Object
com.complexible.common.base.Options
All Implemented Interfaces:
Copyable<Options>, Iterable<Option<Object>>

public class Options extends Object implements Iterable<Option<Object>>, Copyable<Options>
Since:
2.0
Version:
2.2
Author:
Evren Sirin
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Options(Options theOptions)
     
  • Method Summary

    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.
    Creates a mutable copy of the options instance.
    static Options
    Creates a new empty options instance.
    static Options
    Creates a new empty immutable Options instance.
    boolean
    void
    fromJsonString(String theJsonString)
    Caution: Every Option decoded by this function becomes an Option
    <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
    static void
    insert(Options theOptions, Options theOptionsToInsert)
    Inserts the given options into the existing set of options.
    boolean
    is(Option<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 not null or false otherwise.
    static <V> Options
    of(Option<V> key, V value)
    Creates a new options instance with the given single mapping.
    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.
    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.
    <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.
    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
     
     
    static Options
    Creates an unmodifiable, shallow copy of the options instance.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • Options

      public Options()
    • Options

      public Options(Options theOptions)
  • Method Details

    • iterator

      public Iterator<Option<Object>> iterator()
      Specified by:
      iterator in interface Iterable<Option<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.
      Specified by:
      copy in interface Copyable<Options>
      Returns:
      a copy of the object
    • 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 be null so there are cases this function will return null values. Must be used with care in autoboxing.
      See Also:
    • is

      public boolean is(Option<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 not null or false 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 into
      theOptionsToInsert - 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 avoided Options.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(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • size

      public int size()
    • toJsonString

      public String toJsonString()
    • fromJsonString

      public void fromJsonString(String theJsonString)
      Caution: Every Option decoded by this function becomes an Option