Class DictionaryComponents

java.lang.Object
com.singularsys.jep.misc.OneShotComponent
com.singularsys.jep.misc.dictionary.DictionaryComponents
All Implemented Interfaces:
JepComponent, Serializable
Direct Known Subclasses:
FieldDictComponents, MatrixDictComponents, StreamDictComponents, StreamFieldDictComponents, StreamMatrixDictComponents

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:
  • 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.