Class Options

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String QUOTE  
    • Constructor Summary

      Constructors 
      Constructor Description
      Options()
      Constructor.
      Options​(Options options)
      Constructor which shadow copies an existing Options
      Options​(String key, Object value)
      Constructor which adds an options defined by a key/value pair.
      Options​(String key, Object... values)
      Constructor which adds an array of objects, ie: "key" : ["value1", "value2"].
      Options​(String key, List<?> values)
      Constructor which a list of objects, ie: "key" : ["value1", "value2"].
    • Constructor Detail

      • Options

        public Options()
        Constructor.
      • Options

        public Options​(Options options)
        Constructor which shadow copies an existing Options
        Parameters:
        options - the base Options
      • Options

        public Options​(String key,
                       Object value)
        Constructor which adds an options defined by a key/value pair.
        Parameters:
        key - the option name
        value - the option value
      • Options

        public Options​(String key,
                       Object... values)
        Constructor which adds an array of objects, ie: "key" : ["value1", "value2"].
        Parameters:
        key - the option name
        values - the option values
      • Options

        public Options​(String key,
                       List<?> values)
        Constructor which a list of objects, ie: "key" : ["value1", "value2"].
        Parameters:
        key - the option name
        values - the option values
    • Method Detail

      • asString

        public static String asString​(Object value)
        Converts an object to its javascript representation. ie: "myvalue" (with the double quotes)
        If the supplied value is null, "null" is returned
        Parameters:
        value - the object
        Returns:
        the JSON value
      • asString

        public static String asString​(String value)
        Converts a string to its javascript representation. ie: "myvalue" (with the double quotes)
        Parameters:
        value - the object
        Returns:
        the JSON value
      • asString

        public static String asString​(List<?> values)
        Converts a list of objects to its javascript representation. ie: [ "myvalue1", "myvalue2" ] (with the double quotes)
        Parameters:
        values - the List of values
        Returns:
        the JSON value
      • asDate

        public static String asDate​(long date)
        Converts a date to its ISO8601/javascript representation. ie: "2009-11-05T13:15:30+0200" (with the double quotes)
        Parameters:
        date - the date to convert
        Returns:
        the JSON value
      • asDate

        public static String asDate​(Date date)
        Converts a date to its ISO8601/javascript representation. ie: "2009-11-05T13:15:30+0200" (with the double quotes)
        Parameters:
        date - the date to convert
        Returns:
        the JSON value
      • fromArray

        public static String fromArray​(Object... objects)
        Converts a list of options to a comma delimited string.
        Parameters:
        objects - options
        Returns:
        a comma delimited string
      • get

        public <T> T get​(String key)
        Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
        Type Parameters:
        T - the object type
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped, or null if this map contains no mapping for the key
      • set

        public final Options set​(String key,
                                 Object value)
        Adds or replace an option defined by a key/value pair.
        If for a given key, the value is null, then the pair is removed.
        Parameters:
        key - - key with which the specified value is to be associated
        value - - value to be associated with the specified key
        Returns:
        this, for chaining
      • set

        public final Options set​(String key,
                                 Object... values)
        In addition to set(String, Object) this enables to build trees of Options.

        Example:
        
         Options o = new Options();
         o.set("foo", new Options("foo1", "value1"), new Options("foo2", Options.asString("value2")));
        
         results in json:
         { "foo": [
                    { "foo1": value1 },
                    { "foo2": "value2" }
                  ]
         }
         
        Parameters:
        key - - key with which the specified value is to be associated
        values - - values to be associated with the specified key
        Returns:
        this, for chaining
      • set

        public final Options set​(String key,
                                 List<?> values)
        In addition to set(String, Object) this enables to build trees of Options.

        Example:
        
         Options o = new Options();
         o.set("foo", new Options("foo1", "value1"), new Options("foo2", Options.asString("value2")));
        
         results in json:
         { "foo": [
                    { "foo1": value1 },
                    { "foo2": "value2" }
                  ]
         }
         
        Parameters:
        key - - key with which the specified value is to be associated
        values - - values to be associated with the specified key
        Returns:
        this, for chaining
      • entries

        public Set<Map.Entry<String,​Object>> entries()
        Gets a read-only entry set of options
        Returns:
        an unmodifiable set of internal map entries
      • toString

        public String toString()
        Gets the JSON representation of the Options
        Overrides:
        toString in class Object