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
50 lines (40 loc) · 1.34 KB
/
Copy pathInMemoryTimeEntryRepository.java
File metadata and controls
50 lines (40 loc) · 1.34 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
49
50
package io.pivotal.pal.tracker;
import java.util.ArrayList;
import java.util.HashMap;
public class InMemoryTimeEntryRepository implements TimeEntryRepository {
private HashMap<Long, TimeEntry> timeEntryList;
public InMemoryTimeEntryRepository() {
timeEntryList = new HashMap<Long, TimeEntry> ();
}
@Override
public TimeEntry create(TimeEntry timeEntry) {
long newId = (long)timeEntryList.size()+1;
TimeEntry newTimeEntry = new TimeEntry(newId, timeEntry.getProjectId(),timeEntry.getUserId(), timeEntry.getDate(), timeEntry.getHours());
timeEntryList.put(newId, newTimeEntry);
return find(newId);
}
@Override
public TimeEntry find(Long id) {
return timeEntryList.get(id);
}
@Override
public ArrayList<TimeEntry> list() {
return new ArrayList<TimeEntry>(timeEntryList.values());
}
@Override
public TimeEntry update(Long id, TimeEntry timeEntry) {
TimeEntry updatedEntry = new TimeEntry(
id,
timeEntry.getProjectId(),
timeEntry.getUserId(),
timeEntry.getDate(),
timeEntry.getHours()
);
timeEntryList.replace(id, updatedEntry);
return updatedEntry;
}
@Override
public void delete(Long id) {
timeEntryList.remove(id);
}
}