Package org.protelis.lang.datatype
Class Tuples
- java.lang.Object
-
- org.protelis.lang.datatype.Tuples
-
public final class Tuples extends java.lang.ObjectUtility class forTuple.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Tuplefill(java.lang.Object value, int length)Create a Tuple with all elements initialized to the same value.static Tupleintersection(Tuple t1, Tuple t2)Set arithmetic: compute intersection of set of tuple elements in t1 and t2.static TuplepairOperation(Tuple t1, Tuple t2, java.util.function.BinaryOperator<java.lang.Object> fun)Apply fun to pairs of elements from t1 and t2.static Tuplesubtract(Tuple t1, Tuple t2)Set arithmetic: compute subtraction of set of tuple elements in t2 from elements in t1.static Tupleunion(Tuple t1, Tuple t2)Set arithmetic: compute union of set of tuple elements in t1 and t2.
-
-
-
Method Detail
-
union
public static Tuple union(Tuple t1, Tuple t2)
Set arithmetic: compute union of set of tuple elements in t1 and t2.- Parameters:
t1- First tuple to uniont2- Second tuple to union- Returns:
- a new tuple containing elements appearing in either tuple, in arbitrary order
-
intersection
public static Tuple intersection(Tuple t1, Tuple t2)
Set arithmetic: compute intersection of set of tuple elements in t1 and t2.- Parameters:
t1- First tuple to intersectt2- Second tuple to intersect- Returns:
- a new tuple containing elements appearing in both tuples, in arbitrary order
-
subtract
public static Tuple subtract(Tuple t1, Tuple t2)
Set arithmetic: compute subtraction of set of tuple elements in t2 from elements in t1.- Parameters:
t1- Base tuplet2- Tuple to subtract- Returns:
- a new tuple containing elements appearing in t1 but not t2, in arbitrary order
-
pairOperation
public static Tuple pairOperation(Tuple t1, Tuple t2, java.util.function.BinaryOperator<java.lang.Object> fun)
Apply fun to pairs of elements from t1 and t2. If one tuple is longer, then its unmatched elements will be added to the output e.g., pairOperation([1,2,3],[4,5],max) -> [4,5,3]- Parameters:
t1- Tuple of first argumentst2- Tuple of second argumentsfun- The function to apply to pairs of arguments- Returns:
- a new tuple, such that the ith element is fun(t1.get(i),t2.get(i))
-
fill
public static Tuple fill(java.lang.Object value, int length)
Create a Tuple with all elements initialized to the same value.- Parameters:
value- Value to which all elements will be initializedlength- Size of the tuple- Returns:
- a new tuple
-
-