Class Options

  • All Implemented Interfaces:
    Copyable<Options>, java.lang.Iterable<Option<java.lang.Object>>

    public class Options
    extends java.lang.Object
    implements java.lang.Iterable<Option<java.lang.Object>>, Copyable<Options>
    Since:
    2.0
    Version:
    2.2
    Author:
    Evren Sirin
    • 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)
      void fromJsonString​(java.lang.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 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 not null or false 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>
      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.
      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 toJsonString()  
      java.lang.String toString()
      static Options unmodifiable​(Options 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 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 interface java.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.
        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(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 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​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

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

        public int size()
      • toJsonString

        public java.lang.String toJsonString()
      • fromJsonString

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