Package org.protelis
Class Builtins
- java.lang.Object
-
- org.protelis.Builtins
-
public final class Builtins extends java.lang.ObjectCollection of static methods automatically imported by Protelis.
-
-
Field Summary
Fields Modifier and Type Field Description static com.google.common.collect.ImmutableList<java.lang.Integer>MAXIMUM_PARSER_VERSIONThis variable is used by the interpreter for providing compatibility hints in the Eclipse plugin.static com.google.common.collect.ImmutableList<java.lang.Integer>MINIMUM_PARSER_VERSIONThis variable is used by the interpreter for providing compatibility hints in the Eclipse plugin.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanall(Field<java.lang.Boolean> target)static booleanallButSelf(Field<java.lang.Boolean> target)static booleanany(Field<java.lang.Boolean> target)static booleananyButSelf(Field<java.lang.Boolean> target)static <T> java.util.Map<DeviceUID,T>fieldToMap(Field<T> field)Reifies a Field into a Java Map for interoperability and debug purposes.static <T> TfoldHood(ExecutionContext context, T base, Field<T> target, FunctionDefinition reductionFunction)Folds a field, excluding the local value.static <T> TfoldHoodPlusSelf(ExecutionContext context, Field<T> target, FunctionDefinition reductionFunction)Folds the field, including the local value.static <T extends java.lang.Comparable<T>>
TfoldMax(Field<T> target)Folds the field, including the local value, by picking the maximum value.static <T extends java.lang.Comparable<T>>
TfoldMax(T base, Field<T> target)Folds a field by picking the maximum of its values, excluding the local value.static doublefoldMean(Field<? extends java.lang.Number> target)Folds a field of numbers by computing the mathematical mean.static <T extends java.lang.Comparable<T>>
TfoldMin(Field<T> target)Folds the field, including the local value, by picking the minimum value.static <T extends java.lang.Comparable<T>>
TfoldMin(T base, Field<T> target)Folds a field by picking the minimum of its values, excluding the local value.static <T> TfoldSum(Field<T> target)Folds the field, including the local value, by computing the sum.static <T> TfoldSum(T base, Field<T> target)Folds a field by computing the sum of its values, excluding the local value.static <T> TfoldUnion(Field<T> target)Folds the field, including the local value, by computing the union.static <T> TfoldUnion(T base, Field<T> target)Folds a field by computing the union, excluding the local value.static <T> Tlocal(Field<T> target)Picks the local field value (same operation of the previously available "localHood" and "pickHood").static <T> Option<T>maybe(T object)Given a nullable reference, builds anOption.static <T extends java.lang.Comparable<T>>
Tmin(T a, T b)Compares two arbitraryComparables and returns the smaller.static booleannone(Field<java.lang.Boolean> target)Returns true if all the elements of the field are false, including the local value.static booleannoneButSelf(Field<java.lang.Boolean> target)Returns true if all the elements of the field are false, not considering the local value.static <T> Option<T>optionally(T object)Produces an Option value.static <T> Option<T>reduceHood(ExecutionContext context, Field<T> target, FunctionDefinition reductionFunction)Reduces a field, excluding the local value.static <T extends java.lang.Comparable<T>>
Option<T>reduceMax(Field<T> target)Reduces a field, excluding the local value, by picking the maximum value.static Option<java.lang.Double>reduceMean(Field<? extends java.lang.Number> target)Reduces a field, excluding the local value, by computing the arithmetic mean of the values.static <T extends java.lang.Comparable<T>>
Option<T>reduceMin(Field<T> target)Reduces a field by picking the minimum of its values, excluding the local value.static <T> Option<T>reduceSum(Field<T> target)Reduces a field, excluding the local value, by computing the sum of the values.static <T> Option<T>reduceUnion(Field<T> target)Reduces a field, excluding the local value, by computing the union of the values.
-
-
-
Field Detail
-
MINIMUM_PARSER_VERSION
public static final com.google.common.collect.ImmutableList<java.lang.Integer> MINIMUM_PARSER_VERSION
This variable is used by the interpreter for providing compatibility hints in the Eclipse plugin. See https://github.com/Protelis/Protelis/issues/245.
-
MAXIMUM_PARSER_VERSION
public static final com.google.common.collect.ImmutableList<java.lang.Integer> MAXIMUM_PARSER_VERSION
This variable is used by the interpreter for providing compatibility hints in the Eclipse plugin. See https://github.com/Protelis/Protelis/issues/245.
-
-
Method Detail
-
all
public static boolean all(Field<java.lang.Boolean> target)
- Parameters:
target- the field- Returns:
- true if all the elements of the field are true
-
allButSelf
public static boolean allButSelf(Field<java.lang.Boolean> target)
- Parameters:
target- the field- Returns:
- true if all the elements of the field are true. The local element is not considered.
-
any
public static boolean any(Field<java.lang.Boolean> target)
- Parameters:
target- the field- Returns:
- true if any of the elements of the field is true
-
anyButSelf
public static boolean anyButSelf(Field<java.lang.Boolean> target)
- Parameters:
target- the field- Returns:
- true if any of the elements of the field are true. The local element is not considered.
-
fieldToMap
public static <T> java.util.Map<DeviceUID,T> fieldToMap(Field<T> field)
Reifies a Field into a Java Map for interoperability and debug purposes.- Type Parameters:
T- the field (and return map values) type- Parameters:
field- the field to reify- Returns:
- a map having
DeviceUIDs as keys and field values as values
-
foldHood
public static <T> T foldHood(@Nonnull ExecutionContext context, @Nonnull T base, @Nonnull Field<T> target, @Nonnull FunctionDefinition reductionFunction)Folds a field, excluding the local value. This method requires a base value to begin the computation with. The base value is used as initial element. If the field only contains the local value, then the base value is returned.- Type Parameters:
T- field and result type- Parameters:
context-ExecutionContexttarget- the field to be reducedreductionFunction- the reduction functionbase- the base value- Returns:
- an
Optionwith the result of the field reduction, or an empty option.
-
foldHoodPlusSelf
public static <T> T foldHoodPlusSelf(@Nonnull ExecutionContext context, @Nonnull Field<T> target, @Nonnull FunctionDefinition reductionFunction)Folds the field, including the local value.- Type Parameters:
T- field and result type- Parameters:
context-ExecutionContexttarget- target fieldreductionFunction- a Protelis function (T, T)=>T- Returns:
- the folded value
-
foldMax
public static <T extends java.lang.Comparable<T>> T foldMax(Field<T> target)
Folds the field, including the local value, by picking the maximum value. This method requires the field elements to implementComparable.- Type Parameters:
T- field and result type- Parameters:
target- target field- Returns:
- the maximum value among the field values
-
foldMax
public static <T extends java.lang.Comparable<T>> T foldMax(T base, Field<T> target)Folds a field by picking the maximum of its values, excluding the local value. This method requires a base value to begin the computation with. The base value is used as initial element. If the field only contains the local value, then the base value is returned. This method requires the field elements to implementComparable.- Type Parameters:
T- field and result type- Parameters:
target- the field to be reducedbase- the base value- Returns:
- the maximum value among the field values and base.
-
foldMean
public static double foldMean(Field<? extends java.lang.Number> target)
Folds a field of numbers by computing the mathematical mean. Includes the local value.- Parameters:
target- the field to be reduced- Returns:
- a
Doublewith the arithmetic mean of the values
-
foldMin
public static <T extends java.lang.Comparable<T>> T foldMin(Field<T> target)
Folds the field, including the local value, by picking the minimum value. This method requires the field elements to implementComparable.- Type Parameters:
T- field and result type- Parameters:
target- target field- Returns:
- the minimum value among the field values
-
foldMin
public static <T extends java.lang.Comparable<T>> T foldMin(T base, Field<T> target)Folds a field by picking the minimum of its values, excluding the local value. This method requires a base value to begin the computation with. The base value is used as initial element. If the field only contains the local value, then the base value is returned. This method requires the field elements to implementComparable.- Type Parameters:
T- field and result type- Parameters:
target- the field to be reducedbase- the base value- Returns:
- the minimum value among the field values and base.
-
foldSum
public static <T> T foldSum(Field<T> target)
Folds the field, including the local value, by computing the sum. The sum operation must be well defined for the field type.- Type Parameters:
T- field and result type- Parameters:
target- target field- Returns:
- the sum of the field values
-
foldSum
public static <T> T foldSum(T base, Field<T> target)Folds a field by computing the sum of its values, excluding the local value. This method requires a base value to begin the computation with. The base value is used as initial element. If the field only contains the local value, then the base value is returned. The sum operation must be well defined for the field type.- Type Parameters:
T- field and result type- Parameters:
target- the field to be reducedbase- the base value- Returns:
- the sum of the field values and base
-
foldUnion
public static <T> T foldUnion(Field<T> target)
Folds the field, including the local value, by computing the union. The union operation must be well defined for the field type, e.g., this operation can work on a field of tuples.- Type Parameters:
T- field and result type- Parameters:
target- target field- Returns:
- the union of the field values
-
foldUnion
public static <T> T foldUnion(T base, Field<T> target)Folds a field by computing the union, excluding the local value. This method requires a base value to begin the computation with. The base value is used as initial element. If the field only contains the local value, then the base value is returned. The union operation must be well defined for the field type, e.g., this operation can work on a field of tuples.- Type Parameters:
T- field and result type- Parameters:
target- the field to be reducedbase- the base value- Returns:
- the sum of the field values and base
-
local
public static <T> T local(Field<T> target)
Picks the local field value (same operation of the previously available "localHood" and "pickHood").- Type Parameters:
T- field and result type- Parameters:
target- the field to be reduced- Returns:
- the local field value
-
maybe
public static <T> Option<T> maybe(@Nullable T object)
Given a nullable reference, builds anOption.
-
min
public static <T extends java.lang.Comparable<T>> T min(T a, T b)Compares two arbitraryComparables and returns the smaller.- Type Parameters:
T- the type of objects being compared- Parameters:
a- a comparableb- another comparable- Returns:
- the smallest between the two parameters
-
none
public static boolean none(Field<java.lang.Boolean> target)
Returns true if all the elements of the field are false, including the local value.- Parameters:
target- the field- Returns:
- true if all the elements of the field are false
-
noneButSelf
public static boolean noneButSelf(Field<java.lang.Boolean> target)
Returns true if all the elements of the field are false, not considering the local value.- Parameters:
target- the field- Returns:
- true if any of the elements of the field are false. The local value is not considered.
-
reduceHood
public static <T> Option<T> reduceHood(@Nonnull ExecutionContext context, @Nonnull Field<T> target, @Nonnull FunctionDefinition reductionFunction)
Reduces a field, excluding the local value. This method wraps the result in anOption. If the field only contains the local value, then an emptyOptionis returned.- Type Parameters:
T- field and result type- Parameters:
context-ExecutionContexttarget- the field to be reducedreductionFunction- the reduction function- Returns:
- an
Optionwith the result of the field reduction, or an empty option.
-
optionally
public static <T> Option<T> optionally(@Nullable T object)
Produces an Option value. If the passed object is null, then an empty option is returned. Otherwise, an Option enclosing the value is returned. Recommended way to interact with Java method that may return null.- Type Parameters:
T- Object type- Parameters:
object- the nullable object- Returns:
- If the passed object is null, then an empty option is returned. Otherwise, an Option enclosing the value is returned.
-
reduceMax
public static <T extends java.lang.Comparable<T>> Option<T> reduceMax(Field<T> target)
Reduces a field, excluding the local value, by picking the maximum value. This method wraps the result in anOption. If the field only contains the local value, then an emptyOptionis returned.- Type Parameters:
T- field and result type- Parameters:
target- the field to be reduced- Returns:
- an
Optionwith the result of the field reduction, or an empty option.
-
reduceMean
public static Option<java.lang.Double> reduceMean(Field<? extends java.lang.Number> target)
Reduces a field, excluding the local value, by computing the arithmetic mean of the values. This method wraps the result in anOption. If the field only contains the local value, then an emptyOptionis returned.- Parameters:
target- the field to be reduced- Returns:
- an
Optionwith the result of the field reduction, or an empty option.
-
reduceMin
public static <T extends java.lang.Comparable<T>> Option<T> reduceMin(Field<T> target)
Reduces a field by picking the minimum of its values, excluding the local value. This method wraps the result in anOption. If the field only contains the local value, then an emptyOptionis returned.- Type Parameters:
T- field and result type- Parameters:
target- the field to be reduced- Returns:
- an
Optionwith the result of the field reduction, or an empty option.
-
reduceSum
public static <T> Option<T> reduceSum(Field<T> target)
Reduces a field, excluding the local value, by computing the sum of the values. This method wraps the result in anOption. If the field only contains the local value, then an emptyOptionis returned.- Type Parameters:
T- field and result type- Parameters:
target- the field to be reduced- Returns:
- an
Optionwith the result of the field reduction, or an empty option.
-
reduceUnion
public static <T> Option<T> reduceUnion(Field<T> target)
Reduces a field, excluding the local value, by computing the union of the values. This method wraps the result in anOption. If the field only contains the local value, then an emptyOptionis returned.- Type Parameters:
T- field and result type- Parameters:
target- the field to be reduced- Returns:
- an
Optionwith the result of the field reduction, or an empty option.
-
-