English 中文(简体)
JavaTuples - Decade Class
  • 时间:2024-12-22

JavaTuples - Decade Class


Previous Page Next Page  

Introduction

The org.javatuples.Decade class represents a Tuple with ten elements.

Class Declaration

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

pubpc final class Decade<A, B, C, D, E, F, G, H, I, J>
   extends Tuple
      implements IValue0<A>, IValue1<B>, 
         IValue2<C>, IValue3<D>, IValue4<E>,
            IValue5<F>, IValue6<G>, IValue7<H>,
               IValue8<I>, IValue9<J>

Class Constructor

Sr.No. Constructor & Description
1

Decade(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7, I value8, I value9 )

This creates a Decade Tuple.

Class Methods

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

Sr.No. Method & Description
1

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

Create tuple from array.

2

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

Create tuple from collection.

3

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

Create tuple from iterable.

4

static <X> Decade<X,X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable, int index)

Create tuple from iterable, starting from the specified index.

5

int getSize()

Return the size of the tuple.

6

A getValue0()

Returns the value of the tuple at index 0.

Similarly getValue1() upto getValue9() returns the value at index 1 and so on.

7

Ennead<B,C,D,E,F,G,H,I,J> removeFrom0()

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

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

8

<X> Decade<X,B,C,D,E,F,G,H,I,J> setAt0(X value)

Set the value of the tuple at index 0.

9

static <A> Decade<A,B,C,D,E,F,G,H,I,J> with(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7, I value8, I value9)

Create the tuple using given value.

Methods inherite

This class inherits methods from the following classes −

    org.javatuples.Tuple

    Object

Example

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.tutorialspoint;
import java.util.ArrayList;
import java.util.List;
import org.javatuples.Decade;
import org.javatuples.Ennead;
pubpc class TupleTester {
   pubpc static void main(String args[]){
      Decade<Integer, Integer, Integer, Integer, 
         Integer,Integer,Integer,Integer, Integer, Integer> 
      decade = Decade.with(5, 6, 7,8,9,10,11,12,13,14);
      System.out.println(decade);
      boolean isPresent = decade.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);
      pst.add(7);
      pst.add(8);
      pst.add(9);
      pst.add(10);
      Integer value = decade.getValue0();
      System.out.println(value);
      Ennead<Integer, Integer, Integer, Integer,Integer, 
         Integer,Integer, Integer, Integer> ennead = decade.removeFrom0();
      System.out.println(ennead);
      Decade<Integer, Integer, Integer, Integer, Integer,
         Integer, Integer, Integer,Integer, Integer> 
         decade1 = Decade.fromCollection(pst);   
      System.out.println(decade1);
   }
}

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, 11, 12, 13, 14]
5 is present: true
5
[6, 7, 8, 9, 10, 11, 12, 13, 14]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Advertisements