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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleComputes the mean of a list of values.static StringGetTypeName(Value v) Retrieves the type name of a value.static ValueReturns a value as it is.static ValueReturns one of two values depending on a boolean condition.static ValueFinds the maximum of a list of values.static ValueFinds the minimum of a list of values.static ValueActs as a constant function which is always zero.static voidWrites a message to the shared PrintWriter.static ValuePrintValue(String label, Value v) Writes a value preceded by a label to the shared PrintWriter; the value itself is also returned.static voidsetPrintWriter(PrintWriter printWriter) Sets the shared PrintWriter which methods can use to write output.static intReturns the length of a STRING.static booleanToBoolean(boolean x) Converts a value to BOOLEAN.static booleanToBoolean(double x) Converts a value to BOOLEAN.static booleanToBoolean(int x) Converts a value to BOOLEAN.static booleanConverts a value to BOOLEAN.static intToInteger(boolean x) Converts a value to INTEGER.static intToInteger(double x) Converts a value to INTEGER.static intToInteger(int x) Converts a value to INTEGER.static intConverts a value to INTEGER.static doubleToReal(boolean x) Converts a value to REAL.static doubleToReal(double x) Converts a value to REAL.static doubleToReal(int x) Converts a value to REAL.static doubleConverts a value to REAL.static StringConverts a value to STRING.static ValueActs 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.
-