Package org.oristool.lello
Class ValueFuncs
java.lang.Object
org.oristool.lello.ValueFuncs
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
Computes the mean of a list of values.static String
GetTypeName
(Value v) Retrieves the type name of a value.static Value
Returns a value as it is.static Value
Returns one of two values depending on a boolean condition.static Value
Finds the maximum of a list of values.static Value
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
setPrintWriter
(PrintWriter printWriter) 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.
-
Constructor Details
-
ValueFuncs
public ValueFuncs()
-
-
Method Details
-
setPrintWriter
Sets the shared PrintWriter which methods can use to write output.- Parameters:
printWriter
- The PrintWriter to which output will be written to.
-
max
Finds the maximum of a list of values.- Parameters:
params
- A list of numeric values.- Returns:
- The maximum of the list.
-
min
Finds the minimum of a list of values.- Parameters:
params
- A list of numeric values.- Returns:
- The minimum of the list.
-
avg
Computes the mean of a list of values.- Parameters:
params
- A list of numeric values.- Returns:
- The mean.
-
If
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
Converts a value to STRING.- Parameters:
x
- The value to be converted.- Returns:
- The converted value.
-
ToBoolean
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
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
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
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
Returns a value as it is.- Parameters:
v
- The value.- Returns:
- The same identical value.
-
Print
Writes a message to the shared PrintWriter.- Parameters:
msg
- The message to be written.
-
PrintValue
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
Returns the length of a STRING.- Parameters:
s
- The string.- Returns:
- The string length.
-
Zero
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
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.
-