summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/data/Triple.java
blob: 296a1693da3245a5ddb1275fa5a696f89c511f40 (plain)
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
package bjc.data;

/**
 * Represents a tuple of three values
 * @author bjcul
 *
 * @param <Left> The type of the first value
 * @param <Middle> The type of the second value
 * @param <Right> The type of the third value
 */
public interface Triple<Left, Middle, Right> {
	// TODO: fill this out more; mapping and the like
	/**
	 * Get the left value for this triple.
	 * 
	 * @return The left value for this triple.
	 */
	public Left left();
	
	/**
	 * Get the right value for this triple.
	 * 
	 * @return The right value for this triple.
	 */
	public Right right();

	/**
	 * Get the middle value for this triple.
	 * 
	 * @return The middle value for this triple.
	 */
	public Middle middle();
	
	/**
	 * Create a new triple
	 * 
	 * @param <Left> The type for the left
	 * @param <Middle> The type for the middle
	 * @param <Right> The type for the right
	 * 
	 * @param l The left value
	 * @param m The middle value
	 * @param r The right value
	 * 
	 * @return A triple of the given values
	 */
	public static <Left, Middle, Right> Triple<Left, Middle, Right> of(Left l, Middle m, Right r) {
		return new SimpleTriple<>(r, m, l);
	}
}

final class SimpleTriple<Left, Middle, Right> implements Triple<Left, Middle, Right> {
	private final Right r;
	private final Middle m;
	private final Left l;

	SimpleTriple(Right r, Middle m, Left l) {
		this.r = r;
		this.m = m;
		this.l = l;
	}
	
	
	@Override
	public Left left() {
		return l;
	}

	@Override
	public Right right() {
		return r;
	}

	@Override
	public Middle middle() {
		return m;
	}
}