Javatuples 简明教程
JavaTuples - Septet Class
Introduction
org.javatuples.Septet 类表示一个具有七个元素的元组。
The org.javatuples.Septet class represents a Tuple with seven elements.
Class Declaration
以下是 org.javatuples.Septet 类的声明 −
Following is the declaration for org.javatuples.Septet class −
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>
Class Constructor
Sr.No. |
Constructor & Description |
1 |
Septet(A value0, B value1, C value2, D value3, E value4, F value5, G value6) This creates a Septet Tuple. |
Class Methods
Sr.No. |
Method & Description |
1 |
Octet add(Unit tuple) This method returns a Octet tuple. Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Ennead and upto add(Triplet tuple) returns Decade tuple. |
2 |
Octet add(X0 value) This method add a value to the tuple and returns a Octet tuple. Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Ennead and so on upto add() with three parameters. |
3 |
Octet addAt0(Unit value) This method add a Unit tuple at index 0 and returns a Octet tuple. Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Ennead and so on upto addAt0(Triplet). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt6(Triplet). |
4 |
Octet addAt0(X0 value) This method add a value at index 0 and returns a Octet tuple. Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Ennead and so on upto addAt0() with three parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt6() with three parameters. |
5 |
static <X> Septet<X,X,X,X,X,X,X> fromArray(X[] array) Create tuple from array. |
6 |
static <X> Septet<X,X,X,X,X,X,X> fromCollection(Collection<X> collection) Create tuple from collection. |
7 |
static <X> Septet<X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable) Create tuple from iterable. |
8 |
static <X> Septet<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 getValue6() returns the value at index 1 and so on. |
11 |
Sextet<B,C,D,E,F,G> removeFrom0() Return the tuple after removing value of the tuple at index 0. Similarly removeFrom1() upto removeFrom6() returns the tuple after removing value of the tuple at index 1 and so on. |
12 |
<X> Septet<X,B,C,D,E,F,G> setAt0(X value) Set the value of the tuple at index 0. |
13 |
static <A> Septet<A,B,C,D,E,F,G> with(A value0, B value1, C value2, D value3, E value4, F value5, G value6) Create the tuple using given value. |
Methods inherite
此类从以下类中继承方法:
This class inherits methods from the following classes −
-
org.javatuples.Tuple
-
Object
Example
让我们看看 Septet 类如何运作。在此,我们将看到如何使用各种方法。
Let’s see Septet Class in action. Here we’ll see how to use various methods.
在 C:>JavaTuples 中创建一个名为 TupleTester 的 Java 类文件。
Create a java class file named TupleTester in C:\>JavaTuples.
文件:TupleTester.java
File: TupleTester.java
package com.tutorialspoint;
import java.util.ArrayList;
import java.util.List;
import org.javatuples.Septet;
import org.javatuples.Sextet;
import org.javatuples.Octet;
public class TupleTester {
public static void main(String args[]){
Septet<Integer, Integer, Integer, Integer, Integer,Integer,Integer> septet
= Septet.with(5, 6, 7,8,9,10,11);
System.out.println(septet);
boolean isPresent = septet.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);
Octet<Integer, Integer, Integer, Integer, Integer, Integer, Integer, String> octet
= septet.add("Test");
System.out.println(octet);
Integer value = septet.getValue0();
System.out.println(value);
Sextet<Integer, Integer, Integer, Integer,Integer, Integer> sextet
= septet.removeFrom0();
System.out.println(sextet);
Septet<Integer, Integer, Integer, Integer, Integer,Integer, Integer> septet1
= Septet.fromCollection(list);
System.out.println(septet1);
}
}
Verify the result
Verify the result
使用以下 javac 编译器编译类:
Compile the classes using javac compiler as follows −
C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
现在运行 TupleTester 查看结果:
Now run the TupleTester to see the result −
C:\JavaTuples>java -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester