Package astra.lang
Class Prelude
- java.lang.Object
-
- astra.core.Module
-
- astra.lang.Prelude
-
public class Prelude extends Module
This API provides support for manipulating ASTRA Lists.- Author:
- Rem Collier
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class astra.core.Module
Module.ACTION, Module.EVENT, Module.FORMULA, Module.SENSOR, Module.SUPPRESS_NOTIFICATIONS, Module.TERM
-
-
Constructor Summary
Constructors Constructor Description Prelude()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(ListTerm list, Boolean object)booleanadd(ListTerm list, Character object)booleanadd(ListTerm list, Double object)booleanadd(ListTerm list, Float object)booleanadd(ListTerm list, Integer object)booleanadd(ListTerm list, Long object)booleanadd(ListTerm list, Object object)Action that adds any object to a listbooleanadd(ListTerm list, String object)booleanaddAt(ListTerm list, int index, Boolean object)booleanaddAt(ListTerm list, int index, Character object)booleanaddAt(ListTerm list, int index, Double object)booleanaddAt(ListTerm list, int index, Float object)booleanaddAt(ListTerm list, int index, Integer object)booleanaddAt(ListTerm list, int index, Long object)booleanaddAt(ListTerm list, int index, Object object)Action that adds any object to a list at a given index.booleanaddAt(ListTerm list, int index, String object)booleanbooleanValueFor(ListTerm list, String funct)booleanbooleanValueFor(ListTerm list, String functor, int index)charcharValueFor(ListTerm list, String funct)charcharValueFor(ListTerm list, String functor, int index)Formulacontains(ListTerm list, char value)Formulacontains(ListTerm list, double value)Formulacontains(ListTerm list, float value)Formulacontains(ListTerm list, int value)Formulacontains(ListTerm list, long value)Formulacontains(ListTerm list, String value)doubledoubleValueFor(ListTerm list, String funct)doubledoubleValueFor(ListTerm list, String functor, int index)floatfloatValueFor(ListTerm list, String funct)floatfloatValueFor(ListTerm list, String functor, int index)ListfromASTRAList(ListTerm list)Term that converts the ASTRA list to a standard list of Java objects.doubleheadAsDouble(ListTerm list)floatheadAsFloat(ListTerm list)intheadAsInt(ListTerm list)longheadAsLong(ListTerm list)StringheadAsString(ListTerm list)intintValueFor(ListTerm list, String funct)intintValueFor(ListTerm list, String functor, int index)FormulaisEmpty(ListTerm list)Formula that returns true if the list is empty, false otherwiselonglongValueFor(ListTerm list, String funct)longlongValueFor(ListTerm list, String functor, int index)ObjectobjectValueFor(ListTerm list, String funct)ObjectobjectValueFor(ListTerm list, String functor, int index)booleanremove(ListTerm list, int index)Action that removes an object from a list at a given index.booleanreverse(ListTerm list)Term that reverses the order of the values stored in the list.booleanshuffle(ListTerm list)intsize(ListTerm list)Term that returns the size of the list.booleansort_asc(ListTerm list)Term that sorts the list in ascending order.booleansort_desc(ListTerm list)Term that sorts the list in descending order.StringstringValueFor(ListTerm list, String funct)StringstringValueFor(ListTerm list, String functor, int index)booleanswap(ListTerm list, int i, int j)Term that swaps the value at index i with the value at index j in the list.ListTermtail(ListTerm list)ListTermtoASTRAList(List list)Term that converts any Java list (anything that implements theListinterface) into an ASTRA list.Object[]toObjectArray(ListTerm list)Term that converts a list to an object array.BooleanvalueAsBoolean(ListTerm list, int index)Term that returns the value at the given index cast as a boolean.doublevalueAsDouble(ListTerm list, int index)Term that returns the value at the given index cast as an double.floatvalueAsFloat(ListTerm list, int index)Term that returns the value at the given index cast as an float.FunctvalueAsFunct(ListTerm list, int index)Term that returns the value at the given index cast as an long.intvalueAsInt(ListTerm list, int index)Term that returns the value at the given index cast as an int.ListTermvalueAsList(ListTerm list, int index)Term that returns the value at the given index cast as a list.longvalueAsLong(ListTerm list, int index)Term that returns the value at the given index cast as an long.StringvalueAsString(ListTerm list, int index)Term that returns the value at the given index cast as an string.
-
-
-
Method Detail
-
headAsInt
public int headAsInt(ListTerm list)
-
headAsLong
public long headAsLong(ListTerm list)
-
headAsFloat
public float headAsFloat(ListTerm list)
-
headAsDouble
public double headAsDouble(ListTerm list)
-
add
public boolean add(ListTerm list, Object object)
Action that adds any object to a list- Parameters:
list- the list that is to be modifiedobject- the object that is to be added to the list- Returns:
- true if the action succeeds, false otherwise
-
addAt
public boolean addAt(ListTerm list, int index, Object object)
Action that adds any object to a list at a given index.- Parameters:
list- the list that is to be modifiedindex- the index at which the object is to be addedobject- the object that is to be added to the list- Returns:
- true if the item is added, false otherwise
-
remove
public boolean remove(ListTerm list, int index)
Action that removes an object from a list at a given index.- Parameters:
list- the list to be modifiedindex- the index of the object to be removed- Returns:
- true if the item is removed, false otherwise
-
size
public int size(ListTerm list)
Term that returns the size of the list.- Parameters:
list- the list whose size is needed.- Returns:
- the size of the list
-
isEmpty
public Formula isEmpty(ListTerm list)
Formula that returns true if the list is empty, false otherwise- Parameters:
list- the list whose state is to be checked- Returns:
- The formula TRUE if the list is empty, or the formula FALSE is the list is not empty
-
shuffle
public boolean shuffle(ListTerm list)
-
valueAsInt
public int valueAsInt(ListTerm list, int index)
Term that returns the value at the given index cast as an int.- Parameters:
list- the list containing the valueindex- the index of the value in the list- Returns:
- the value at the given index in the list
-
valueAsLong
public long valueAsLong(ListTerm list, int index)
Term that returns the value at the given index cast as an long.- Parameters:
list- the list containing the valueindex- the index of the value in the list- Returns:
- the value at the given index in the list
-
valueAsFunct
public Funct valueAsFunct(ListTerm list, int index)
Term that returns the value at the given index cast as an long.- Parameters:
list- the list containing the valueindex- the index of the value in the list- Returns:
- the value at the given index in the list
-
valueAsDouble
public double valueAsDouble(ListTerm list, int index)
Term that returns the value at the given index cast as an double.- Parameters:
list- the list containing the valueindex- the index of the value in the list- Returns:
- the value at the given index in the list
-
valueAsFloat
public float valueAsFloat(ListTerm list, int index)
Term that returns the value at the given index cast as an float.- Parameters:
list- the list containing the valueindex- the index of the value in the list- Returns:
- the value at the given index in the list
-
valueAsList
public ListTerm valueAsList(ListTerm list, int index)
Term that returns the value at the given index cast as a list.- Parameters:
list- the list containing the valueindex- the index of the value in the list- Returns:
- the value at the given index in the list
-
valueAsString
public String valueAsString(ListTerm list, int index)
Term that returns the value at the given index cast as an string.- Parameters:
list- the list containing the valueindex- the index of the value in the list- Returns:
- the value at the given index in the list
-
valueAsBoolean
public Boolean valueAsBoolean(ListTerm list, int index)
Term that returns the value at the given index cast as a boolean.- Parameters:
list- the list containing the valueindex- the index of the value in the list- Returns:
- the value at the given index in the list
-
sort_asc
public boolean sort_asc(ListTerm list)
Term that sorts the list in ascending order. This method assumes that the values stored in the list are comparable.- Parameters:
list- the list to be sorted- Returns:
- true if the action succeeds, false otherwise
-
sort_desc
public boolean sort_desc(ListTerm list)
Term that sorts the list in descending order. This method assumes that the values stored in the list are comparable.- Parameters:
list- the list to be sorted- Returns:
- true if the action succeeds, false otherwise
-
swap
public boolean swap(ListTerm list, int i, int j)
Term that swaps the value at index i with the value at index j in the list.- Parameters:
list- the list to be modifiedi- the index of the first valuej- the index of the second value- Returns:
- true if the action succeeded, false otherwise
-
reverse
public boolean reverse(ListTerm list)
Term that reverses the order of the values stored in the list.- Parameters:
list- the source list- Returns:
- true if the action succeeded, false otherwise
-
fromASTRAList
public List fromASTRAList(ListTerm list)
Term that converts the ASTRA list to a standard list of Java objects. This assumes that the ASTRA list contains only primitives...- Parameters:
list- the source list- Returns:
- the list of values
-
toASTRAList
public ListTerm toASTRAList(List list)
Term that converts any Java list (anything that implements theListinterface) into an ASTRA list. Here the contents of the original list are assumed to be primitives or objects and are converted to ASTRA Primitives.- Parameters:
list- the list to be converted- Returns:
- an ASTRA list of values
-
-