public class Predefined extends Object
Predefined provides the module of predefined functions in Golo. The provided module is imported by
default.| Modifier and Type | Method and Description |
|---|---|
static Object |
aget(Object a,
Object i)
Access an array element by index.
|
static Object |
alength(Object a)
Array length.
|
static Object |
Array(Object... values)
Makes a Java primitive array out of values.
|
static Class<?> |
arrayTypeOf(Object klass)
Returns an array class given a type class.
|
static void |
aset(Object a,
Object i,
Object value)
Updates an array element by index.
|
static Object |
asInterfaceInstance(Object interfaceClass,
Object target)
Turns a method handle into a instance of a single-method interface.
|
static Object |
atoList(Object[] values)
Makes a list out of a Java primitive array.
|
static boolean |
fileExists(Object file)
Check if a file exists.
|
static Object |
fileToText(Object file,
Object encoding)
Reads the content of a text file.
|
static Object |
fun(Object name,
Object module)
Obtains the first method handle / closure to a function.
|
static Object |
fun(Object name,
Object module,
Object arity)
Obtains a method handle / closure to a function.
|
static boolean |
isArray(Object object)
Checks if an object is a (JVM) array or not.
|
static Object |
isClosure(Object object)
Test whether an object is a closure or not.
|
static Object |
mapEntry(Object key,
Object value)
Makes a key / value pair.
|
static Class<?> |
objectArrayType()
Function to obtain the
Object[].class reference. |
static void |
print(Object obj)
Prints to the standard console.
|
static void |
println(Object obj)
Prints to the standard console, including a newline.
|
static void |
raise(Object message)
Raises a
RuntimeException with a message. |
static void |
raise(Object message,
Object cause)
Raises a
RuntimeException with a message and a cause. |
static Object |
range(Object from,
Object to)
Makes an integer range object between two bounds.
|
static String |
readln()
Reads the next line of characters from the console.
|
static String |
readln(String message)
Reads the next line of characters from the console.
|
static String |
readPassword()
Reads a password from the console with echoing disabled.
|
static String |
readPassword(String message)
Reads a password from the console with echoing disabled.
|
static void |
require(Object condition,
Object errorMessage)
Requires that a condition be
true. |
static void |
requireNotNull(Object obj)
Requires that an object is not the
null reference. |
static char[] |
secureReadPassword()
Reads a password from the console with echoing disabled, returning an
char[] array. |
static char[] |
secureReadPassword(String message)
Reads a password from the console with echoing disabled, returning an
char[] array. |
static void |
textToFile(Object text,
Object file)
Writes some text to a file.
|
public static void raise(Object message)
RuntimeException with a message.message - the exception description.RuntimeException - (always)public static void raise(Object message, Object cause)
RuntimeException with a message and a cause.message - the exception description.cause - the exception cause.RuntimeException - (always)public static void print(Object obj)
obj - the object to be printed.public static void println(Object obj)
obj - obj the object to be printed.public static String readln() throws IOException
IOExceptionpublic static String readln(String message) throws IOException
message - displays a prompt message.IOExceptionpublic static String readPassword() throws IOException
IOExceptionpublic static String readPassword(String message) throws IOException
message - displays a prompt message.IOExceptionpublic static char[] secureReadPassword()
throws IOException
char[] array.IOExceptionpublic static char[] secureReadPassword(String message) throws IOException
char[] array.message - displays a prompt message.IOExceptionpublic static void requireNotNull(Object obj) throws AssertionError
null reference.obj - the object to test against null.AssertionError - if obj is null.public static void require(Object condition, Object errorMessage) throws IllegalArgumentException, AssertionError
true.condition - the condition, must be a Boolean.errorMessage - the error message, must be a String.IllegalArgumentException - if the arguments are of the wrong type.AssertionError - if condition is false.public static Object Array(Object... values)
values - the values.public static Object atoList(Object[] values)
values - the array.java.util package.public static Object aget(Object a, Object i)
a - the array.i - the index.i.public static void aset(Object a, Object i, Object value)
a - the array.i - the index.value - the new value.public static Object alength(Object a)
a - the array.a.public static Object range(Object from, Object to)
java.lang.Iterable, so
they can be used in Golo foreach loops.from - the lower-bound (inclusive) as an Integer or Long.to - the upper-bound (exclusive) as an Integer or Long.Iterablepublic static Object mapEntry(Object key, Object value)
key - the key.value - the value.AbstractMap.SimpleEntryAbstractMap.SimpleEntrypublic static Object asInterfaceInstance(Object interfaceClass, Object target)
interfaceClass - the target single-method interface class.target - the implementation method handle.interfaceClass.MethodHandleProxies.asInterfaceInstance(Class, java.lang.invoke.MethodHandle)public static Object isClosure(Object object)
object - the object.true if object is an instance of java.lang.invoke.MethodHandle,
false otherwise.public static Object fun(Object name, Object module, Object arity) throws Throwable
name - the function name.module - the function enclosing module (a Java class).arity - the function arity, where a negative value means that any arity will do.NoSuchMethodException - if the target function could not be found.IllegalArgumentException - if the argument types are not of types (String, Class, Integer).Throwable - if an error occurs.public static Object fun(Object name, Object module) throws Throwable
This is the same as calling fun(name, module, -1).
Throwablefun(Object, Object, Object)public static Object fileToText(Object file, Object encoding) throws Throwable
public static void textToFile(Object text, Object file) throws Throwable
public static boolean fileExists(Object file)
public static boolean isArray(Object object)
object - the object to check.true if object is an array, false otherwise or if null.public static Class<?> objectArrayType()
Object[].class reference.Object[].classpublic static Class<?> arrayTypeOf(Object klass) throws ClassNotFoundException
klass - the array type.klass, i.e., klass[].ClassNotFoundException - if the type could not be found.Copyright © 2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon). All Rights Reserved.