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
A set of components for parsing and operating on associative arrays.
It allows parsing of JSON like syntax for maps
and add functions
map = {'x':2, 'y':3}
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
Mapallowing missing values{'x':3, 'y'}. - Using
Maprequiring a value for each key. - Using doubly nested
Vectorand allowing missing values. - Using doubly nested
Vectorand requiring a value for each key.
{'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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumKeys for the two operators used to build maps.static enumType of configuration. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor, 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 TypeMethodDescriptionprotected voidaddFunctions(Jep jep, boolean missing) voidThe value used for key's with no values.getType()The configuration type specified in the constructor.protected voidputIfSet(Jep jep, String string, Supplier<PostfixMathCommandI> sup) Methods inherited from class com.singularsys.jep.misc.OneShotComponent
getLightWeightInstance, init
-
Field Details
-
nullValue
Special value for keys with no value
-
-
Constructor Details
-
DictionaryComponents
Constructor, used a default object for null values.- Parameters:
type- configuration type
-
DictionaryComponents
Constructor with a specified value used for null values.- Parameters:
type- configuration typenullValue- value used to represent null values.
-
-
Method Details
-
firstInit
- Specified by:
firstInitin classOneShotComponent
-
addFunctions
-
putIfSet
-
getType
The configuration type specified in the constructor.- Returns:
- The configuration type
-
getNullValue
The value used for key's with no values.- Returns:
- the Object used for null values.
-