-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathTableNested.java
More file actions
50 lines (37 loc) · 1.22 KB
/
TableNested.java
File metadata and controls
50 lines (37 loc) · 1.22 KB
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
package TableNested;
import java.util.ArrayList;
/**
* All you need to do for this microlab is take the Table and Entry from the last one and make Entry a nested class.
* Think about how nested classes should work with generics.
*/
public class TableNested<K, V> {
private ArrayList<Table.Entry> entries;
public TableNested() {
this.entries = new ArrayList();
}
public V get(K key){
for(Table.Entry e : entries){
if(e.getKey().equals(key)){
return (V) e.getValue();
}
}
return null;
}
public void put(K key, V value){
int numberOfEntries = 0;
for(Table.Entry e : entries){
if(e.getKey().equals(key)){
entries.set(numberOfEntries, new Table.Entry(key, value));
}
numberOfEntries++;
}
entries.add(new Table.Entry(key, value));
}
public void remove(K key){
for(int i = 0; i < entries.size(); i++){
if(entries.get(i).getKey().equals(key)){
entries.remove(i);
}
}
}
}