![]() |
VOOZH | about |
A Ennead is a Tuple from JavaTuples library that deals with 9 elements. Since this Ennead is a generic class, it can hold any type of value in it.
Since Ennead is a Tuple, hence it also has all the characteristics of JavaTuples:
public final class Ennead<A, B, C, D, E, F, G, H, I> extends Tuple implements IValue0<A>, IValue1<B>, IValue2<C>, IValue3<D>, IValue4<E>, IValue5<F, IValue6<G, IValue7<H>, IValue8<I>
Object ↳ org.javatuples.Tuple ↳ org.javatuples.Ennead<A, B, C, D, E, F, G, H, I>
Ennead<A, B, C, D, E, F, G, H, I> ennead = new Ennead<A, B, C, D, E, F, G, H, I> (value1, value2, value3, value4, value5, value6, value7, value8, value9);
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Ennead<type1, type2, type3, type4, type5, type6, type7, type8> ennead = Ennead.with(value1, value2, value3, value4, value5, value6, value7, value8, value9);
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Ennead<type1, type2, type3, type4, type5, type6, type7, type8> ennead = Ennead.fromCollection(collectionWith_9_value); Ennead<type1, type2, type3, type4, type5, type6, type7, type8> ennead = Ennead.fromArray(arrayWith_9_value);
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9] [1, 2, 3, 4, 5, 6, 7, 8, 9]
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:
Ennead<type1, type2, type3, type4, type5, type6, type7, type8> ennead = new Ennead<type1, type2, type3, type4, type5, type6, type7, type8> (value1, value2, value3, value4, value5, value6, value7, value8, value9); type1 val1 = ennead.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:
Ennead<type1, type2, type3, type4, type5, type6, type7, type8> ennead = new Ennead<type1, type2, type3, type4, type5, type6, type7, type8> (value1, value2, value3, value4, value5, value6, value7, value8, value9); Ennead<type1, type2, type3, type4, type5, type6, type7, type8> otherEnnead = ennead.setAtX(value);
Example:
Output:
[1, 2, 3, 40, 5, 6, 7, 8, 9]
Adding a value can be done with the help of addAtX() method, where X represents the index at which the value is to be added. This method returns a Tuple of element one more than the called Tuple.
Syntax:
Ennead<type1, type2, type3, type4, type5, type6, type7, type8> ennead = new Ennead<type1, type2, type3, type4, type5, type6, type7, type8> (value1, value2, value3, value4, value5, value6, value7, value8, value9); Ennead<type 1, type 2, type 3, type 4, type 5, type 6, type 7, type 8> ennead = ennead.addAtx(value);
Example:
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
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:
Ennead<type1, type2, type3, type4, type5, type6, type7, type8> ennead = new Ennead<type1, type2, type3, type4, type5, type6, type7, type8> (value1, value2, value3, value4, value5, value6, value7, value8, value9); boolean res = ennead.contains(value2);
Example:
Output:
true false
Since Ennead implement the Iterable<Object> interface. It means that they can be iterated in the same way as collections or arrays.
Syntax:
Ennead<type1, type2, type3, type4, type5, type6, type7, type8> ennead =
new Ennead<type1, type2, type3, type4, type5, type6, type7, type8>
(value1, value2, value3, value4, value5, value6, value7, value8, value9);
for (Object item : ennead) {
...
}
Example:
Output:
1 2 3 4 5 6 7 8 9