forked from vmware-tanzu-learning/pal-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInMemoryTimeEntryRepository.java
More file actions
38 lines (31 loc) · 929 Bytes
/
InMemoryTimeEntryRepository.java
File metadata and controls
38 lines (31 loc) · 929 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 io.pivotal.pal.tracker;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class InMemoryTimeEntryRepository implements TimeEntryRepository {
private HashMap<Long, TimeEntry> timeEntries = new HashMap<>();
@Override
public TimeEntry create(TimeEntry timeEntry) {
timeEntry.setId(timeEntries.size() + 1);
timeEntries.put(timeEntry.getId(), timeEntry);
return timeEntry;
}
@Override
public TimeEntry find(Long id) {
return timeEntries.get(id);
}
@Override
public List<TimeEntry> list() {
return new ArrayList<>(timeEntries.values());
}
@Override
public TimeEntry update(Long id, TimeEntry timeEntry) {
timeEntries.replace(id, timeEntry);
timeEntry.setId(id);
return timeEntry;
}
@Override
public void delete(Long id) {
timeEntries.remove(id);
}
}