Package com.singularsys.jep.misc.dictionary

# Class GetOr

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

All Implemented Interfaces:
  `PostfixMathCommandI`, `Serializable`

public class GetOr extends NaryFunction
Gets the value associated with a key, or a default value.

    map = {'x':2, 'y':3};
    getOr(map, 'x', -1);

The function returns either the value associated with the key, supplied default value. If no value is associate with the key then `nullValue` is returned.

Since:
  Jep 4.1
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Object`
  `nullValue`

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

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GetOr()`
  `GetOr(Object nullValue)`
  Constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected boolean`
  `equals(Object key, Object k)`
  Test if key equals k.
  `Object`
  `eval(Object[] args)`
  Evaluate the function
  `protected Object`
  `eval(List<?> list, Object key, Object def)`
  `protected Object`
  `eval(Map<Object,Object> map, Object key, Object def)`

  ### 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, checkNumberOfParameters, getDescription, 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

- ## Constructor Details

  - ### GetOr

    public GetOr(Object nullValue)
    Constructor
    Parameters:
      `nullValue` - , value returned when a key has no value.

  - ### GetOr

    public GetOr()

- ## Method Details

  - ### 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

  - ### eval

    protected Object eval(Map<Object,Object> map, Object key, Object def)

  - ### eval

    protected Object eval(List<?> list, Object key, Object def) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### equals

    protected boolean equals(Object key, Object k) throws EvaluationException
    Test if key equals k. Default implementation uses `key.equals(k)`
    Parameters:
      `key` - key to test
      `k` - key to test
    Returns:
      true if parameters are equal
    Throws:
      `EvaluationException`