Package com.singularsys.jep.misc.dictionary

# Class DictionaryComponents

java.lang.Object
com.singularsys.jep.misc.OneShotComponent
com.singularsys.jep.misc.dictionary.DictionaryComponents

All Implemented Interfaces:
  `JepComponent`, `Serializable`

public class DictionaryComponents extends OneShotComponent
A set of components for parsing and operating on associative arrays. It allows parsing of JSON like syntax for maps

    map = {'x':2, 'y':3}

and add functions `put(map,'x',5)`, `getOr(map,'x',-1)`, `get(map,'x')`, `containsKey(map,'x')`, `remove(map,'x')`, `clear(map)`, `keys(map)`, `values(map)`, `entries(map)`, `entriesIter(map)`, `size(map)` `hashMap()`, `linkedMap()`, {code treeMap()}.

Symbols used and function names can be configured in the properties file.

It can be set up in four ways:

- Using `Map` allowing missing values `{'x':3, 'y'}` .
- Using `Map` requiring a value for each key.
- Using doubly nested `Vector` and allowing missing values.
- Using doubly nested `Vector` and requiring a value for each key.

When using a double nested vectors `{'x':3, 'y'}` is evaluated as `[['x', 3.0],['y']]`. The `entries` function will always fill in null values.

Three functions `entriesIter(map)`, `keysIter(map)`, and `valuesIter(map)` are included but not enabled by default. These can be included by modifying the properties file, or by manually adding them. These functions are provided for use by the com.singularsys.extensions.stream package.

See Also:
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `DictionaryComponents.DictionaryKeys`
  Keys for the two operators used to build maps.
  `static enum`
  `DictionaryComponents.Type`
  Type of configuration.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final Object`
  `nullValue`
  Special value for keys with no value

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DictionaryComponents(DictionaryComponents.Type type)`
  Constructor, used a default object for null values.
  `DictionaryComponents(DictionaryComponents.Type type, Object nullValue)`
  Constructor with a specified value used for null values.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `addFunctions(Jep jep, boolean missing)`
  `void`
  `firstInit(Jep jep)`
  `Object`
  `getNullValue()`
  The value used for key's with no values.
  `DictionaryComponents.Type`
  `getType()`
  The configuration type specified in the constructor.
  `protected void`
  `putIfSet(Jep jep, String string, Supplier<PostfixMathCommandI> sup)`

  ### Methods inherited from class com.singularsys.jep.misc.OneShotComponent

  `getLightWeightInstance, init`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### nullValue

    protected final Object nullValue
    Special value for keys with no value

- ## Constructor Details

  - ### DictionaryComponents

    public DictionaryComponents(DictionaryComponents.Type type)
    Constructor, used a default object for null values.
    Parameters:
      `type` - configuration type

  - ### DictionaryComponents

    public DictionaryComponents(DictionaryComponents.Type type, Object nullValue)
    Constructor with a specified value used for null values.
    Parameters:
      `type` - configuration type
      `nullValue` - value used to represent null values.

- ## Method Details

  - ### firstInit

    public void firstInit(Jep jep)
    Specified by:
      `firstInit` in class `OneShotComponent`

  - ### addFunctions

    protected void addFunctions(Jep jep, boolean missing)

  - ### putIfSet

    protected void putIfSet(Jep jep, String string, Supplier<PostfixMathCommandI> sup)

  - ### getType

    public DictionaryComponents.Type getType()
    The configuration type specified in the constructor.
    Returns:
      The configuration type

  - ### getNullValue

    public Object getNullValue()
    The value used for key's with no values.
    Returns:
      the Object used for null values.