English 中文(简体)
JavaTuples - Sextet Class
  • 时间:2024-11-03

JavaTuples - Sextet Class


Previous Page Next Page  

Introduction

The org.javatuples.Sextet class represents a Tuple with six elements.

Class Declaration

Following is the declaration for org.javatuples.Sextet class −

pubpc final class Sextet<A, B, C, D, E, F>
   extends Tuple
      implements IValue0<A>, IValue1<B>, 
         IValue2<C>, IValue3<D>, IValue4<E>,
            IValue5<F>

Class Constructor

Sr.No. Constructor & Description
1

Sextet(A value0, B value1, C value2, D value3, E value4, F value5)

This creates a Sextet Tuple.

Class Methods

Similarly setAt1() upto setAt5() set the value at index 1, and so on.

Sr.No. Method & Description
1

Septet add(Unit tuple)

This method returns a Septet tuple.

Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Octet and upto add(Quartet tuple) returns Decade tuple.

2

Septet add(X0 value)

This method add a value to the tuple and returns a Septet tuple.

Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Octet and so on upto add() with four parameters.

3

Septet addAt0(Unit value)

This method add a Unit tuple at index 0 and returns a Septet tuple.

Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Octet and so on upto addAt0(Quartet). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt5(Quartet).

4

Septet addAt0(X0 value)

This method add a value at index 0 and returns a Septet tuple.

Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Octet and so on upto addAt0() with four parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt5() with four parameters.

5

static <X> Sextet<X,X,X,X,X,X> fromArray(X[] array)

Create tuple from array.

6

static <X> Sextet<X,X,X,X,X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

7

static <X> Sextet<X,X,X,X,X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

8

static <X> Sextet<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 getValue5() returns the value at index 1 and so on.

11

Quintet<B,C,D,E,F> removeFrom0()

Return the tuple after removing value of the tuple at index 0.

Similarly removeFrom1() upto removeFrom5() returns the tuple after removing value of the tuple at index 1 and so on.

12

<X> Sextet<X,B,C,D,E,F> setAt0(X value)

Set the value of the tuple at index 0.

13

static <A> Sextet<A,B,C,D,E,F> with(A value0, B value1, C value2, D value3, E value4, F value5)

Create the tuple using given value.

Methods inherite

This class inherits methods from the following classes −

    org.javatuples.Tuple

    Object

Example

Let s see Sextet 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.tutorialspoint;
import java.util.ArrayList;
import java.util.List;
import org.javatuples.Quartet;
import org.javatuples.Quintet;
import org.javatuples.Sextet;
import org.javatuples.Septet;
pubpc class TupleTester {
   pubpc static void main(String args[]){
      Sextet<Integer, Integer, Integer, Integer, Integer,Integer> sextet 
         = Sextet.with(5, 6, 7,8,9,10);
      System.out.println(sextet);
      boolean isPresent = sextet.contains(5);
      System.out.println("5 is present: " + isPresent);
      List<Integer> pst = new ArrayList<>();
      pst.add(1);
      pst.add(2);
      pst.add(3);
      pst.add(4);
      pst.add(5);
      pst.add(6);
      Septet<Integer, Integer, Integer, Integer, Integer, Integer, String> septet 
         = sextet.add("Test");
      System.out.println(septet);
      Integer value = sextet.getValue0();
      System.out.println(value);
      Quintet<Integer, Integer, Integer, Integer,Integer> quintet 
         = sextet.removeFrom0();
      System.out.println(quintet);
      Sextet<Integer, Integer, Integer, Integer, Integer,Integer> sextet1 
         = Sextet.fromCollection(pst);   
      System.out.println(sextet1);
   }
}

Verify the result

Compile the classes using javac compiler as follows −

C:JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java

Now run the TupleTester to see the result −

C:JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester

Output

Verify the Output

[5, 6, 7, 8, 9, 10]
5 is present: true
[5, 6, 7, 8, 9, 10, Test]
5
[6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6]
Advertisements