Package com.gengoai.tuple
Class Tuple
- java.lang.Object
-
- com.gengoai.tuple.Tuple
-
- All Implemented Interfaces:
Copyable<Tuple>
,Serializable
,Comparable<Tuple>
,Iterable<Object>
public abstract class Tuple extends Object implements Iterable<Object>, Comparable<Tuple>, Copyable<Tuple>, Serializable
A tuple is a finite sequence of items. Mango provides specific implementations for degree 0-4 tuples, which all each element's type to be defined via generics. For tuples with degree 5 or more, a generic NTuple is provided.
- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Tuple()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T> Tuple
appendLeft(T object)
Appends an item the beginning of the tuple resulting in a new tuple of degree + 1<T> Tuple
appendRight(T object)
Appends an item the end of the tuple resulting in a new tuple of degree + 1abstract Object[]
array()
The tuple as an array of objectsint
compareTo(Tuple o)
abstract int
degree()
The number of items in the tupleboolean
equals(Object obj)
<T> T
get(int i)
Gets the ith item of the tuple.int
hashCode()
Iterator<Object>
iterator()
<R> R
map(@NonNull Function<Tuple,R> function)
Maps the tuple to another a data type.Tuple
mapValues(@NonNull Function<Object,?> function)
Maps the values of the tuple to another data typeTuple
shiftLeft()
Shifts the first element of the tuple resulting in a tuple of degree - 1.Tuple
shiftRight()
Shifts the last element of the tuple resulting in a tuple of degree - 1.Tuple
slice(int start, int end)
Takes a slice of the tuple from an inclusive start to an exclusive end index.Stream<Object>
stream()
Gets a stream over the objects in the tupleString
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
appendLeft
public <T> Tuple appendLeft(T object)
Appends an item the beginning of the tuple resulting in a new tuple of degree + 1- Type Parameters:
T
- the type parameter- Parameters:
object
- the object being appended- Returns:
- A new tuple of degree + 1 containing the object at the beginning
-
appendRight
public <T> Tuple appendRight(T object)
Appends an item the end of the tuple resulting in a new tuple of degree + 1- Type Parameters:
T
- the type parameter- Parameters:
object
- the object being appended- Returns:
- A new tuple of degree + 1 containing the object at the end
-
array
public abstract Object[] array()
The tuple as an array of objects- Returns:
- an array representing the items in the tuple
-
compareTo
public final int compareTo(Tuple o)
- Specified by:
compareTo
in interfaceComparable<Tuple>
-
degree
public abstract int degree()
The number of items in the tuple- Returns:
- the number of items in the tuple
-
get
public <T> T get(int i)
Gets the ith item of the tuple.- Type Parameters:
T
- the type parameter- Parameters:
i
- the index of the item- Returns:
- the item at the ith index
-
map
public <R> R map(@NonNull @NonNull Function<Tuple,R> function)
Maps the tuple to another a data type.- Type Parameters:
R
- the type being mapped to- Parameters:
function
- the mapping function- Returns:
- the result of the mapping function
-
mapValues
public Tuple mapValues(@NonNull @NonNull Function<Object,?> function)
Maps the values of the tuple to another data type- Parameters:
function
- the mapping function- Returns:
- A new tuple of same degree whose values are the result of the mapping function applied to the this tuple's elements.
-
shiftLeft
public Tuple shiftLeft()
Shifts the first element of the tuple resulting in a tuple of degree - 1.- Returns:
- A new tuple without the shifted element;
-
shiftRight
public Tuple shiftRight()
Shifts the last element of the tuple resulting in a tuple of degree - 1.- Returns:
- A new tuple without the shifted element;
-
slice
public Tuple slice(int start, int end)
Takes a slice of the tuple from an inclusive start to an exclusive end index.- Parameters:
start
- Where to start the slice from (inclusive)end
- Where to end the slice at (exclusive)- Returns:
- A new tuple of degree (end - start) with the elements of this tuple from start to end
-
stream
public Stream<Object> stream()
Gets a stream over the objects in the tuple- Returns:
- A Stream of the objects in the tuple
-
-