forked from rmtracey/pal-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInMemoryTimeEntryRepository.java
More file actions
40 lines (32 loc) · 1.04 KB
/
InMemoryTimeEntryRepository.java
File metadata and controls
40 lines (32 loc) · 1.04 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
package io.pivotal.pal.tracker;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
public class InMemoryTimeEntryRepository implements TimeEntryRepository {
Map<Long, TimeEntry> timeEntryMap = new HashMap<Long, TimeEntry>();
Long maxId = 0L;
public TimeEntry create(TimeEntry timeEntry) {
timeEntry.setId(++maxId);
timeEntryMap.put(timeEntry.getId(), timeEntry);
return timeEntry;
}
public TimeEntry find(Long id) {
return timeEntryMap.get(id);
}
public List<TimeEntry> list() {
List<TimeEntry> listToReturn = new ArrayList<TimeEntry>();
for (Long i = 1L; i <= timeEntryMap.size(); i++) {
listToReturn.add(timeEntryMap.get(i));
}
return listToReturn;
}
public TimeEntry update(Long id, TimeEntry timeEntry) {
timeEntry.setId(id);
timeEntryMap.replace(id, timeEntry);
return timeEntryMap.get(id);
}
public void delete(Long id) {
timeEntryMap.remove(id);
}
}