-
Notifications
You must be signed in to change notification settings - Fork 3
/
Pair.java
53 lines (45 loc) · 999 Bytes
/
Pair.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
/*
* File: Pair.java
* Description: A light-weight class storing a pair of elements
* Author: Benjamin David Mayes <bdm8233@rit.edu>
*/
/**
* A Pair class
*/
public class Pair<L,R> {
public L left;
public R right;
/**
* Constructs a pair with null references for its data.
*/
public Pair() {
left = null;
right = null;
}
/**
* Constructs a pair from the given data.
*/
public Pair( L l, R r ) {
left = l;
right = r;
}
/**
* Obtains data that is of type A.
*
* @return The data of type A or null if there if it is storing data of type B.
*/
public L left() {
return left;
}
/**
* Obtains data that is of type A.
*
* @return The data of type A or null if there if it is storing data of type B.
*/
public R right() {
return right;
}
public String toString() {
return "(" + left + ", " + right + ")";
}
}