Skip to content

Commit 65a8987

Browse files
refactor 635
1 parent 55e7fe3 commit 65a8987

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

src/main/java/com/fishercoder/solutions/_635.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,45 @@ int[] Retrieve(String start, String end, String granularity):
3535
*/
3636
public class _635 {
3737

38-
/**credit: https://discuss.leetcode.com/topic/94449/concise-java-solution*/
39-
public static class LogSystem {
38+
public static class Solution1 {
39+
/**
40+
* credit: https://discuss.leetcode.com/topic/94449/concise-java-solution
41+
*/
42+
public static class LogSystem {
4043

41-
/**These indices denote and string endings of timestamps of different granularity, i.e.
42-
* timestamp[1] in timestamps: "2017:01:01:22:59:59"
43-
* -> 2017: 4, 01: 7, 01: 10, 22: 13, 59: 16, 59: 19*/
44+
/**
45+
* These indices denote and string endings of timestamps of different granularity, i.e.
46+
* timestamp[1] in timestamps: "2017:01:01:22:59:59"
47+
* -> 2017: 4, 01: 7, 01: 10, 22: 13, 59: 16, 59: 19
48+
*/
4449

45-
List<String[]> timestamps;
46-
List<String> units;
47-
int[] indices;
50+
List<String[]> timestamps;
51+
List<String> units;
52+
int[] indices;
4853

49-
public LogSystem() {
50-
timestamps = new LinkedList<>();
51-
units = Arrays.asList("Year", "Month", "Day", "Hour", "Minute", "Second");
52-
indices = new int[]{4, 7, 10, 13, 16, 19};
53-
}
54+
public LogSystem() {
55+
timestamps = new LinkedList<>();
56+
units = Arrays.asList("Year", "Month", "Day", "Hour", "Minute", "Second");
57+
indices = new int[]{4, 7, 10, 13, 16, 19};
58+
}
5459

55-
public void put(int id, String timestamp) {
56-
timestamps.add(new String[]{Integer.toString(id), timestamp});
57-
}
60+
public void put(int id, String timestamp) {
61+
timestamps.add(new String[]{Integer.toString(id), timestamp});
62+
}
5863

59-
public List<Integer> retrieve(String s, String e, String gra) {
60-
List<Integer> res = new LinkedList<>();
61-
int index = units.indexOf(gra);
62-
int stringEnd = indices[index];
63-
for (String[] timestamp : timestamps) {
64-
if (timestamp[1].substring(0, stringEnd).compareTo(s.substring(0, stringEnd)) >= 0
65-
&& timestamp[1].substring(0, stringEnd).compareTo(e.substring(0, stringEnd)) <= 0) {
66-
res.add(Integer.parseInt(timestamp[0]));
64+
public List<Integer> retrieve(String s, String e, String gra) {
65+
List<Integer> res = new LinkedList<>();
66+
int index = units.indexOf(gra);
67+
int stringEnd = indices[index];
68+
for (String[] timestamp : timestamps) {
69+
if (timestamp[1].substring(0, stringEnd).compareTo(s.substring(0, stringEnd)) >= 0
70+
&& timestamp[1].substring(0, stringEnd).compareTo(e.substring(0, stringEnd)) <= 0) {
71+
res.add(Integer.parseInt(timestamp[0]));
72+
}
6773
}
74+
return res;
6875
}
69-
return res;
7076
}
7177
}
7278

73-
7479
}

src/test/java/com/fishercoder/_635Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
* Created by fishercoder on 9/9/17.
1616
*/
1717
public class _635Test {
18-
private static _635.LogSystem logSystem;
18+
private static _635.Solution1.LogSystem logSystem;
1919
private static List<Integer> expected;
2020

2121
@BeforeClass
2222
public static void setup() {
23-
logSystem = new _635.LogSystem();
23+
logSystem = new _635.Solution1.LogSystem();
2424
}
2525

2626
@Before
2727
public void clear() {
28-
logSystem = new _635.LogSystem();
28+
logSystem = new _635.Solution1.LogSystem();
2929
expected = new ArrayList<>();
3030
}
3131

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy