-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKey.java
More file actions
33 lines (27 loc) · 833 Bytes
/
Key.java
File metadata and controls
33 lines (27 loc) · 833 Bytes
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
public class Key {
private String label;
private int type;
// Constructor: Initializes a Key with a label and type
public Key(String theLabel, int theType) {
this.label = theLabel.toLowerCase();
this.type = theType;
}
// Returns the label of the Key
public String getLabel() {
return label;
}
// Returns the type of the Key
public int getType() {
return type;
}
// Compares this Key to another Key
public int compareTo(Key k) {
if (this.label.equals(k.getLabel()) && this.type == k.getType()) {
return 0;
} else if (this.label.compareTo(k.getLabel()) < 0 || (this.label.equals(k.getLabel()) && this.type < k.getType())) {
return -1;
} else {
return 1;
}
}
}