![]() |
VOOZH | about |
A Septet is a Tuple from JavaTuples library that deals with 3 elements. Since this Septet is a generic class, it can hold any type of value in it.
Since Septet is a Tuple, hence it also has all the characteristics of JavaTuples:
public final class Septet<A, B, C, D, E, F, G> extends Tuple implements IValue0<A>, IValue1<B>, IValue2<C>, IValue3<D>, IValue4<E>, IValue5<F, IValue6<G>
Object ↳ org.javatuples.Tuple ↳ org.javatuples.Septet<A, B, C, D, E, F, G>
Septet<A, B, C, D, E, F, G> septet = new Septet<A, B, C, D, E, F, G> (value1, value2, value3, value4, value5, value6, value7);
[1, 2, 3, 4, 5, 6, 7]
Septet<type1, type2, type3, type4, type5, type6, type7> septet = Septet.with(value1, value2, value3, value4, value5, value6, value7);
[1, 2, 3, 4, 5, 6, 7]
Septet<type1, type2, type3, type4, type5, type6, type7> septet = Septet.fromCollection(collectionWith_7_value); Septet<type1, type2, type3, type4, type5, type6, type7> septet = Septet.fromArray(arrayWith_7_value);
[1, 2, 3, 4, 5, 6, 7] [1, 2, 3, 4, 5, 6, 7]
The getValueX() method can be used to fetch the value in a Tuple at index X. The indexing in Tuples start with 0. Hence the value at index X represents the value at position X+1.
Syntax:
Septet<type1, type2, type3, type4, type5, type6, type7> septet = new Septet<type1, type2, type3, type4, type5, type6, type7> (value1, value2, value3, value4, value5, value6, value7); type1 val1 = septet.getValue0();
Example:
Output:
1 3
Since the Tuples are immutable, it means that modifying a value at any index is not possible. Hence JavaTuples offer setAtX(value) which creates a copy of the Tuple with a new value at index X, and returns that Tuple.
Syntax:
Septet<type1, type2, type3, type4, type5, type6, type7> septet = new Septet<type1, type2, type3, type4, type5, type6, type7> (value1, value2, value3, value4, value5, value6, value7); Septet<type1, type2, type3, type4, type5, type6, type7> otherSeptet = septet.setAtX(value);
Example:
Output:
[1, 2, 3, 40, 5, 6, 7]
Adding a value can be done with the help of addAtX() method, where X represent the index at which the value is to be added. This method returns a Tuple of element one more than the called Tuple.
Syntax:
Septet<type1, type2, type3, type4, type5, type6, type7> septet = new Septet<type1, type2, type3, type4, type5, type6, type7> (value1, value2, value3, value4, value5, value6, value7); Septet<type 1, type 2, type 3, type 4, type 5, type 6, type 7> septet = septet.addAtx(value);
Example:
Output:
[1, 2, 3, 4, 5, 6, 7, 8]
An element can be searched in a tuple with the pre-defined method contains(). It returns a boolean value whether the value is present or not.
Syntax:
Septet<type1, type2, type3, type4, type5, type6, type7> septet = new Septet<type1, type2, type3, type4, type5, type6, type7> (value1, value2, value3, value4, value5, value6, value7); boolean res = septet.contains(value2);
Example:
Output:
true false
Since Septet implement the Iterable<Object> interface. It means that they can be iterated in the same way as collections or arrays.
Syntax:
Septet<type1, type2, type3, type4, type5, type6, type7> septet =
new Septet<type1, type2, type3, type4, type5, type6, type7>
(value1, value2, value3, value4, value5, value6, value7);
for (Object item : septet) {
...
}
Example:
Output:
1 2 3 4 5 6 7