-
Notifications
You must be signed in to change notification settings - Fork 1
/
UserDaoDb.java
65 lines (46 loc) · 1.43 KB
/
UserDaoDb.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
import java.util.ArrayList;
import java.util.List;
public class UserDaoDb implements UserDao {
private List<User> users;
public UserDaoDb() {
users = new ArrayList<User>();
users.add(new User(1, "user1", "user1", "[email protected]", "0624141145"));
users.add(new User(2, "user2", "user2", "[email protected]", "0652200241"));
users.add(new User(3, "user3", "user3", "[email protected]", "0600000025"));
users.add(new User(4, "user4", "user4", "[email protected]", "0600000026"));
users.add(new User(5, "user5", "user5", "[email protected]", "0652000014"));
}
public List<User> select() {
return users;
}
public User select(int id) {
for (User user : users) {
if (user.getId() == id) {
return user;
}
}
return null;
}
public User select(String username, String password) {
for (User user : users) {
if (user.getUsername().equals(username) && user.getPassword().equals(password)) {
return user;
}
}
return null;
}
public void insert(User u) {
users.add(u);
}
public void delete(User u) {
users.remove(u);
}
public void update(User u) {
if (users.contains(u)) {
User user = select(u.getId());
user = u;
delete(user);
insert(u);
}
}
}