-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogSystem.java
More file actions
44 lines (37 loc) · 1.03 KB
/
Copy pathLogSystem.java
File metadata and controls
44 lines (37 loc) · 1.03 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
import java.util.*;
public class LogSystem
{
Map<String, List<Integer>> logs;
Map<String, Integer> indices;
{
indices = new HashMap<>();
indices.put("Year", 4);
indices.put("Month", 7);
indices.put("Day", 10);
indices.put("Hour", 13);
indices.put("Minute", 16);
indices.put("Second", 19);
}
public LogSystem()
{
logs = new HashMap<>();
}
public void put(int id, String timestamp)
{
logs.putIfAbsent(timestamp, new ArrayList<>());
logs.get(timestamp).add(id);
}
public List<Integer> retrieve(String s, String e, String gra)
{
int idx = indices.get(gra);
List<Integer> result = new ArrayList<Integer>();
for (String time : logs.keySet())
{
if (time.substring(0, idx).compareTo(s.substring(0, idx)) >= 0 && time.substring(0, idx).compareTo(e.substring(0, idx)) <= 0)
{
result.addAll(logs.get(time));
}
}
return result;
}
}