-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExternalChainingMapEntry.java
111 lines (99 loc) · 2.55 KB
/
ExternalChainingMapEntry.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Map entry class used for implementing the ExternalChainingHashMap.
*
* DO NOT MODIFY THIS FILE!!
*
* @author CS 1332 TAs
* @version 1.0
*/
public class ExternalChainingMapEntry<K, V> {
private K key;
private V value;
private ExternalChainingMapEntry<K, V> next;
/**
* Constructs a new ExternalChainingMapEntry with only the given key and value.
*
* @param key The key in the new entry.
* @param value The value in the new entry.
*/
public ExternalChainingMapEntry(K key, V value) {
this(key, value, null);
}
/**
* Constructs a new ExternalChainingMapEntry with the given key, value, and next reference.
*
* @param key The key in the new entry.
* @param value The value in the new entry.
* @param next The next entry in the external chain.
*/
public ExternalChainingMapEntry(K key, V value, ExternalChainingMapEntry<K, V> next) {
this.key = key;
this.value = value;
this.next = next;
}
/**
* Gets the key.
*
* @return The key.
*/
public K getKey() {
return key;
}
/**
* Gets the value.
*
* @return The value.
*/
public V getValue() {
return value;
}
/**
* Gets the next entry.
*
* @return The next entry.
*/
public ExternalChainingMapEntry<K, V> getNext() {
return next;
}
/**
* Sets the key.
*
* @param key The new key.
*/
public void setKey(K key) {
this.key = key;
}
/**
* Sets the value.
*
* @param value The new value.
*/
public void setValue(V value) {
this.value = value;
}
/**
* Sets the next entry.
*
* @param next The new next entry.
*/
public void setNext(ExternalChainingMapEntry<K, V> next) {
this.next = next;
}
@Override
public String toString() {
String key = this.key == null ? "null" : this.key.toString();
String value = this.value == null ? "null" : this.value.toString();
return String.format("(%s, %s)", key, value);
}
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object o) {
// DO NOT USE THIS METHOD IN YOUR CODE! This is for testing ONLY!
if (!(o instanceof ExternalChainingMapEntry)) {
return false;
} else {
ExternalChainingMapEntry<K, V> that = (ExternalChainingMapEntry<K, V>) o;
return that.getKey().equals(key) && that.getValue().equals(value);
}
}
}