{{theTime}}

Search This Blog

Total Pageviews

Java Tuples

- Java tuples is one of the simplest data structure.
- Java tuple data structure supports heterogenious objects.

javatuples offers you tuple classes from one to ten elements:

- Unit<A> (1 element)
- Pair<A,B> (2 elements)
- Triplet<A,B,C> (3 elements)
- Quartet<A,B,C,D> (4 elements)
- Quintet<A,B,C,D,E> (5 elements)
- Sextet<A,B,C,D,E,F> (6 elements)
- Septet<A,B,C,D,E,F,G> (7 elements)
- Octet<A,B,C,D,E,F,G,H> (8 elements)
- Ennead<A,B,C,D,E,F,G,H,I> (9 elements)
- Decade<A,B,C,D,E,F,G,H,I,J> (10 elements)

A couple of very common 2-element tuple classes equivalent to Pair, just for the sake of code semantics:

 - KeyValue<A,B>
 - LabelValue<A,B>

Java Tuple class are:

- Typesafe
- Immutable
- Iterable
- Serializable
- Comparable (implements Comparable<Tuple>)
- Implements equals(...) and hashCode()
- Implements toString()

Examples:

- Triplet<String,Integer,Double[]> triplet = Triplet.with(str, integ, doubleArray); 
- Quartet<String,Integer,Double[],Boolean> quartet = triplet.add(myBoolean);
- LabelValue<String,Operator> operatorLabelValue = new LabelValue<String,Operator>("<=", Operator.LESS_OR_EQUAL_TO);

No comments:

Kafka Consumer Parallelism

Kafka Parallel Consumer Options: Key-level parallelism:  Multiple threads process the messages from a single partition in parallel while ma...