-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAO.java
More file actions
38 lines (30 loc) · 731 Bytes
/
Copy pathDAO.java
File metadata and controls
38 lines (30 loc) · 731 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
34
35
36
37
38
package exer1;
import java.util.*;
public class DAO<T> {
private Map<String, T> map = new HashMap<>();
public void save(String id, T entity){
map.put(id, entity);
}
public void update(String id, T entity){
if(map.containsKey(id)){
map.put(id, entity);
}
}
public T get(String id){
return map.get(id);
}
public List<T> list (){
List<T> list = new ArrayList<>();
Collection<T> values = map.values();
for(T t : values){
list.add(t);
}
return list;
}
public void add(String id, T entity){
map.put(id, entity);
}
public void remove(String id){
map.remove(id);
}
}