public final class Tuple extends java.lang.Object implements HeadTail<java.lang.Object>, java.lang.Comparable<Tuple>
A tuple essentially behaves like an immutable array. In Golo, tuples can be created as follows:
# Short syntax
let t1 = [1, 2, 3]
# Complete collection literal syntax
let t2 = tuple[1, 2, 3]
Constructor and Description |
---|
Tuple(java.lang.Object... values)
Creates a new tuple from values.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Tuple other)
Compares this tuple with the specified tuple for order.
|
Tuple |
destruct()
Helper for destructuring.
|
boolean |
equals(java.lang.Object o) |
Tuple |
extend(java.lang.Object... values)
Returns a new Tuple extended with the given values.
|
Tuple |
extend(Tuple tuple)
Returns a new Tuple extended with the given Tuple.
|
static Tuple |
fromArray(java.lang.Object[] values)
Helper factory method.
|
java.lang.Object |
get(int index)
Gets the element at a specified index.
|
int |
hashCode() |
java.lang.Object |
head()
Returns the first element of the tuple.
|
boolean |
isEmpty()
Checks whether the tuple is empty or not.
|
java.util.Iterator<java.lang.Object> |
iterator()
Creates an iterator over the tuple.
|
int |
size()
Gives the number of elements in this tuple.
|
Tuple |
subTuple(int start)
Extract a sub-tuple.
|
Tuple |
subTuple(int start,
int end)
Extract a sub-tuple.
|
Tuple |
tail()
Returns a new tuple containg the remaining elements.
|
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this tuple.
|
java.lang.String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
toIterable
public Tuple(java.lang.Object... values)
values
- the tuple values.public static Tuple fromArray(java.lang.Object[] values)
values
- the values as an array.public int size()
public boolean isEmpty()
public java.lang.Object get(int index)
index
- the element index.index
.java.lang.IndexOutOfBoundsException
- if the specified index
is not valid (negative value or above the size).public java.util.Iterator<java.lang.Object> iterator()
The iterator does not support removal.
iterator
in interface java.lang.Iterable<java.lang.Object>
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int compareTo(Tuple other)
Returns a negative integer, zero, or a positive integer as this tuple is less than, equal to, or greater than the specified tuple.
Two tuples are compared using the lexicographical (dictionary) order, that is:
[1, 2] < [1, 3]
and [2, 5] < [3, 1]
.
Two tuples are comparable if they have the same size and their elements are pairwise comparable.
compareTo
in interface java.lang.Comparable<Tuple>
other
- the tuple to be compared.java.lang.NullPointerException
- if the specified tuple is null.java.lang.ClassCastException
- if the type of the elements in the specified tuple prevent them from being compared to this tuple elements.java.lang.IllegalArgumentException
- if the specified tuple has a different size than this tuple.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object head()
public Tuple subTuple(int start)
start
- the index of the first element.start
to the end.public Tuple subTuple(int start, int end)
start
- the index of the first element (inclusive).end
- the index of the last element (exclusive).start
inclusive and end
exclusive.public java.lang.Object[] toArray()
public Tuple extend(java.lang.Object... values)
Tuple
, or this one if no values are given.