-
Notifications
You must be signed in to change notification settings - Fork 0
/
KVPair.java
74 lines (66 loc) · 1.6 KB
/
KVPair.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
/**
* KVPair class definition: Pretty specific for Project 2
* @author CS3114 Instructor and TAs
* @version 9/22/2014
*/
public class KVPair<T extends Comparable<? super T>> implements Comparable<KVPair<T>>
{
private T value;
private T value2 = null;
/**
* Constructor
* @param k the key (first Handle)
* @param v the value (second Handle)
*/
public KVPair(T value)
{
this.value = value;
}
public KVPair(T handle, T handle2) {
this.value = handle;
this.value2 = handle2;
}
/**
* The magic that lets us compare two KVPairs.
* KVPairs are all that this knows how to compare against
* First compare the key field. If they are identical,
* then break the tie with the value field.
* @return the usual for a comparable (+, 0, -)
* @param it the KVPair to compare "this" against
*/
public int compareTo(KVPair<T> it)
{
int firstComp = value.compareTo(it.getValue());
if (firstComp == 0 && value2 != null) {
return value2.compareTo(it.getValue2());
}
return firstComp;
}
/**
* Getter for "vertLine"
* @return the vertLine
*/
public T getValue()
{
return value;
}
public T getValue2()
{
return value2;
}
/**
* Standard toString method
* @return the printable string
*/
public String toString()
{
if (value2 != null) {
return value.toString() + " " + value2.toString();
}
return value.toString();
}
public int getX()
{
return ((VerticalLine) value).getX();
}
}