The org.javatuples.Ennead class represents a Tuple with nine elements.
Following is the declaration for org.javatuples.Ennead class −
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>
Sr.No. | Constructor & Description |
---|---|
1 | Ennead(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7, I value8) This creates a Ennead Tuple. |
Sr.No. | Method & Description |
---|---|
1 | Decade add(Unit tuple) This method returns a Decade tuple. |
2 | Decade add(X0 value) This method add a value to the tuple and returns a Decade tuple. |
3 | Decade addAt0(Unit value) This method add a Unit tuple at index 0 and returns a Decade tuple. Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt8(Unit). |
4 | Decade addAt0(X0 value) This method add a value at index 0 and returns a Decade tuple. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt8() with one parameter. |
5 | static <X> Ennead<X,X,X,X,X,X,X,X,X > fromArray(X[] array) Create tuple from array. |
6 | static <X> Ennead<X,X,X,X,X,X,X,X,X> fromCollection(Collection<X> collection) Create tuple from collection. |
7 | static <X> Ennead<X,X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable) Create tuple from iterable. |
8 | static <X> Ennead<X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable, int index) Create tuple from iterable, starting from the specified index. |
9 | int getSize() Return the size of the tuple. |
10 | A getValue0() Returns the value of the tuple at index 0. Similarly getValue1() upto getValue8() returns the value at index 1 and so on. |
11 | Octet<B,C,D,E,F,G,H,I> removeFrom0() Return the tuple after removing value of the tuple at index 0. Similarly removeFrom1() upto removeFrom8() returns the tuple after removing value of the tuple at index 1 and so on. |
12 | <X> Ennead<X,B,C,D,E,F,G,H,I> setAt0(X value) Set the value of the tuple at index 0. |
13 | static <A> Ennead<A,B,C,D,E,F,G,H,I> with(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7, I value8) Create the tuple using given value. |
This class inherits methods from the following classes −
org.javatuples.Tuple
Object
Let's see Ennead Class in action. Here we'll see how to use various methods.
Create a java class file named TupleTester in C:\>JavaTuples.
File: TupleTester.java
package com.howcodex; import java.util.ArrayList; import java.util.List; import org.javatuples.Decade; import org.javatuples.Ennead; import org.javatuples.Octet; public class TupleTester { public static void main(String args[]){ Ennead<Integer, Integer, Integer, Integer, Integer, Integer,Integer,Integer, Integer> ennead = Ennead.with(5, 6, 7,8,9,10,11,12,13); System.out.println(ennead); boolean isPresent = ennead.contains(5); System.out.println("5 is present: " + isPresent); List<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); list.add(4); list.add(5); list.add(6); list.add(7); list.add(8); list.add(9); Decade<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, String> decade = ennead.add("Test"); System.out.println(decade); Integer value = ennead.getValue0(); System.out.println(value); Octet<Integer, Integer, Integer, Integer,Integer, Integer,Integer, Integer> octet = ennead.removeFrom0(); System.out.println(octet); Ennead<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer,Integer> ennead1 = Ennead.fromCollection(list); System.out.println(ennead1); } }
Verify the result
Compile the classes using javac compiler as follows −
C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/howcodex/TupleTester.java
Now run the TupleTester to see the result −
C:\JavaTuples>java -cp .;javatuples-1.2.jar com.howcodex.TupleTester
Verify the Output
[5, 6, 7, 8, 9, 10, 11, 12, 13] 5 is present: true [5, 6, 7, 8, 9, 10, 11, 12, 13, Test] 5 [6, 7, 8, 9, 10, 11, 12, 13] [1, 2, 3, 4, 5, 6, 7, 8, 9]