Class ValueFuncs

java.lang.Object
org.oristool.lello.ValueFuncs

public class ValueFuncs extends Object
This class is a container of static methods which can be called from within the Lello interpreter with their qualified or unqualified Java name; it also acts as a container of shared resources on which the methods may depend, such as output streams and open files.

This class is intended for programmers who can modify the Lello source code and that want a fast and easy way to extend the language with new predefined functions which they think will be useful also for someone else later. All functions must be declared static.

Programmers which can not modify the Lello source, or programmers that have a very specific need and do not want to add clutter to this class, can declare static functions anywhere else in their source code; as long as Lello is given the qualified name it will be able to call them.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    avg(List<Value> params)
    Computes the mean of a list of values.
    static String
    Retrieves the type name of a value.
    static Value
    Returns a value as it is.
    static Value
    If(boolean condition, Value a, Value b)
    Returns one of two values depending on a boolean condition.
    static Value
    max(List<Value> params)
    Finds the maximum of a list of values.
    static Value
    min(List<Value> params)
    Finds the minimum of a list of values.
    static Value
    Acts as a constant function which is always zero.
    static void
    Writes a message to the shared PrintWriter.
    static Value
    PrintValue(String label, Value v)
    Writes a value preceded by a label to the shared PrintWriter; the value itself is also returned.
    static void
    Sets the shared PrintWriter which methods can use to write output.
    static int
    Returns the length of a STRING.
    static boolean
    ToBoolean(boolean x)
    Converts a value to BOOLEAN.
    static boolean
    ToBoolean(double x)
    Converts a value to BOOLEAN.
    static boolean
    ToBoolean(int x)
    Converts a value to BOOLEAN.
    static boolean
    Converts a value to BOOLEAN.
    static int
    ToInteger(boolean x)
    Converts a value to INTEGER.
    static int
    ToInteger(double x)
    Converts a value to INTEGER.
    static int
    ToInteger(int x)
    Converts a value to INTEGER.
    static int
    Converts a value to INTEGER.
    static double
    ToReal(boolean x)
    Converts a value to REAL.
    static double
    ToReal(double x)
    Converts a value to REAL.
    static double
    ToReal(int x)
    Converts a value to REAL.
    static double
    Converts a value to REAL.
    static String
    Converts a value to STRING.
    static Value
    Acts as a constant function which is always zero.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ValueFuncs

      public ValueFuncs()
  • Method Details

    • setPrintWriter

      public static void setPrintWriter(PrintWriter printWriter)
      Sets the shared PrintWriter which methods can use to write output.
      Parameters:
      printWriter - The PrintWriter to which output will be written to.
    • max

      public static Value max(List<Value> params)
      Finds the maximum of a list of values.
      Parameters:
      params - A list of numeric values.
      Returns:
      The maximum of the list.
    • min

      public static Value min(List<Value> params)
      Finds the minimum of a list of values.
      Parameters:
      params - A list of numeric values.
      Returns:
      The minimum of the list.
    • avg

      public static double avg(List<Value> params)
      Computes the mean of a list of values.
      Parameters:
      params - A list of numeric values.
      Returns:
      The mean.
    • If

      public static Value If(boolean condition, Value a, Value b)
      Returns one of two values depending on a boolean condition.
      Parameters:
      condition - The tested condition.
      a - First value.
      b - Second value.
      Returns:
      Value a if condition is true, value b otherwise.
    • ToString

      public static String ToString(Value x)
      Converts a value to STRING.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToBoolean

      public static boolean ToBoolean(String x)
      Converts a value to BOOLEAN.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToBoolean

      public static boolean ToBoolean(int x)
      Converts a value to BOOLEAN.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToBoolean

      public static boolean ToBoolean(double x)
      Converts a value to BOOLEAN.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToBoolean

      public static boolean ToBoolean(boolean x)
      Converts a value to BOOLEAN.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToInteger

      public static int ToInteger(String x)
      Converts a value to INTEGER.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToInteger

      public static int ToInteger(int x)
      Converts a value to INTEGER.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToInteger

      public static int ToInteger(double x)
      Converts a value to INTEGER.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToInteger

      public static int ToInteger(boolean x)
      Converts a value to INTEGER.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToReal

      public static double ToReal(String x)
      Converts a value to REAL.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToReal

      public static double ToReal(int x)
      Converts a value to REAL.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToReal

      public static double ToReal(double x)
      Converts a value to REAL.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • ToReal

      public static double ToReal(boolean x)
      Converts a value to REAL.
      Parameters:
      x - The value to be converted.
      Returns:
      The converted value.
    • GetTypeName

      public static String GetTypeName(Value v)
      Retrieves the type name of a value.

      The name can be one of the following:

      • NIL
      • STRING
      • INTEGER
      • REAL
      • BOOLEAN
      Parameters:
      v - The value whose type name is to be retrieved.
      Returns:
      The type name.
    • Identity

      public static Value Identity(Value v)
      Returns a value as it is.
      Parameters:
      v - The value.
      Returns:
      The same identical value.
    • Print

      public static void Print(String msg)
      Writes a message to the shared PrintWriter.
      Parameters:
      msg - The message to be written.
    • PrintValue

      public static Value PrintValue(String label, Value v)
      Writes a value preceded by a label to the shared PrintWriter; the value itself is also returned.
      Parameters:
      label - The label.
      v - The value.
      Returns:
      The value v unchanged.
    • StrLen

      public static int StrLen(String s)
      Returns the length of a STRING.
      Parameters:
      s - The string.
      Returns:
      The string length.
    • Zero

      public static Value Zero(Value v)
      Acts as a constant function which is always zero. The input value is not taken into account in any way.
      Parameters:
      v - The input value.
      Returns:
      0 of type INTEGER.
    • One

      public static Value One(Value v)
      Acts as a constant function which is always zero. The input value is not taken into account in any way.
      Parameters:
      v - The input value.
      Returns:
      1 of type INTEGER.