Package com.singularsys.jep.misc.dictionary

# Class MakeMap

java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.NaryFunction
com.singularsys.jep.misc.dictionary.MakeMap

All Implemented Interfaces:
  `PostfixMathCommandI`, `Serializable`

public class MakeMap extends NaryFunction
Create a map of a given type, either creates an empty map or uses a list or map of data.

     * jep.addFunction("hashMap", new MakeMap(MakeMap.Type.HashMap));
    jep.addFunction("linkedMap", new MakeMap(MakeMap.Type.LinkedMap));
    jep.addFunction("treeMap",  new MatrixDictMakeMap(MakeMap.Type.TreeMap));
    jep.addFunction("mymap",
        new MakeMap(() ->
            new TreeMap<Object,Object>( (x,y) ->
                 Double.compare(
                    ((Number) x).doubleValue(),
                    ((Number) y).doubleValue() ) ) );

See Also:
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `MakeMap.Type`
  Configuration type.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Object`
  `nullValue`
  `protected final Supplier<Map<Object,Object>>`
  `sup`
  `protected final MakeMap.Type`
  `type`

  ### Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MakeMap(MakeMap.Type type)`
  Create maps of a given type.
  `MakeMap(Supplier<Map<Object,Object>> sup)`
  Create a map with a given supplier.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `checkNumberOfParameters(int n)`
  Checks the number of parameters of the function.
  `Object`
  `eval(Object[] args)`
  Evaluate the function
  `String`
  `getDescription()`
  Return a description of the function from the properties file.

  ### Methods inherited from class com.singularsys.jep.functions.NaryFunction

  `run`

  ### Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, setName, toString, toString`

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

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

- ## Field Details

  - ### nullValue

    protected Object nullValue

  - ### sup

    protected final Supplier<Map<Object,Object>> sup

  - ### type

    protected final MakeMap.Type type

- ## Constructor Details

  - ### MakeMap

    public MakeMap(MakeMap.Type type)
    Create maps of a given type.
    Parameters:
      `type` - configurations type
    Throws:
      `IllegalArgumentException` - if type is `MakeMap.Type.Supplier`.

  - ### MakeMap

    public MakeMap(Supplier<Map<Object,Object>> sup)
    Create a map with a given supplier. For example

        jep.addFunction("mymap",
            new MakeMap(() ->
                new TreeMap<Object,Object>( (x,y) ->
                     Double.compare(
                        ((Number) x).doubleValue(),
                        ((Number) y).doubleValue() ) ) );

    Parameters:
      `sup` - a supplied that created maps.

- ## Method Details

  - ### checkNumberOfParameters

    public boolean checkNumberOfParameters(int n)
    Description copied from class: `PostfixMathCommand`
    Checks the number of parameters of the function. Functions which set numberOfParameter=-1 should overload this method
    Specified by:
      `checkNumberOfParameters` in interface `PostfixMathCommandI`
    Overrides:
      `checkNumberOfParameters` in class `PostfixMathCommand`
    Parameters:
      `n` - number of parameters function will be called with.
    Returns:
      false if an illegal number of parameters is supplied, true otherwise.

  - ### eval

    public Object eval(Object[] args) throws EvaluationException
    Description copied from class: `NaryFunction`
    Evaluate the function
    Specified by:
      `eval` in class `NaryFunction`
    Parameters:
      `args` - arguments to the function
    Returns:
      value returned by the function
    Throws:
      `EvaluationException` - if the calculation cannot be performed

  - ### getDescription

    public String getDescription()
    Description copied from class: `PostfixMathCommand`
    Return a description of the function from the properties file. The property name is the class name followed by ".description". The property is found using the `JepMessages` class, which can be configured to add additional properties files. If `PostfixMathCommand.setDescription(String)` has been called, return the description set by that method instead.
    Specified by:
      `getDescription` in interface `PostfixMathCommandI`
    Overrides:
      `getDescription` in class `PostfixMathCommand`
    Returns:
      the description of the function