-
Notifications
You must be signed in to change notification settings - Fork 65
/
Tuple.java
79 lines (71 loc) · 1.28 KB
/
Tuple.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Data-Structures-In-Java
* Tuple.java
*/
package com.deepak.data.structures.Arrays;
/**
* Tuple class is an extension of Pair
* NOTE : Tuple can have any number of elements.
* We are implementing this class as a Triplet for now
*
* @author Deepak
*
* @param <L>
* @param <M>
* @param <R>
*/
public class Tuple<L, M , R> {
/* Since Tuple as well is a immutable data structure,
* All the elements are marked as final */
private final L left;
private final M middle;
private final R right;
/**
* Constructor
*
* @param left
* @param middle
* @param right
*/
public Tuple(L left, M middle, R right) {
super();
this.left = left;
this.middle = middle;
this.right = right;
}
/**
* Method to create a new Tuple
*
* @param left
* @param middle
* @param right
* @return {@link Tuple<L, M, R>}
*/
public static <L, M, R> Tuple<L, M, R> of(final L left, final M middle, final R right) {
return new Tuple<L, M, R>(left, middle, right);
}
/**
* Method to get Left
*
* @return {@link L}
*/
public L getLeft() {
return left;
}
/**
* Method to get Middle
*
* @return {@link M}
*/
public M getMiddle() {
return middle;
}
/**
* Method to get Right
*
* @return {@link R}
*/
public R getRight() {
return right;
}
}