1
1
package fr .adrienbrault .idea .symfony2plugin .profiler ;
2
2
3
3
import fr .adrienbrault .idea .symfony2plugin .profiler .dict .ProfilerRequest ;
4
+ import fr .adrienbrault .idea .symfony2plugin .profiler .dict .ProfilerRequestInterface ;
5
+ import org .jetbrains .annotations .NotNull ;
4
6
import org .jetbrains .annotations .Nullable ;
5
7
6
8
import java .io .BufferedReader ;
7
9
import java .io .File ;
8
10
import java .io .FileReader ;
9
11
import java .io .IOException ;
10
12
import java .util .ArrayList ;
13
+ import java .util .List ;
11
14
12
- public class ProfilerIndex {
13
-
15
+ /**
16
+ * @author Daniel Espendiller <daniel@espendiller.net>
17
+ */
18
+ public class LocalProfilerIndex implements ProfilerIndexInterface {
19
+ @ NotNull
14
20
private File file ;
15
21
16
- public ProfilerIndex ( File file ) {
22
+ public LocalProfilerIndex ( @ NotNull File file ) {
17
23
this .file = file ;
18
24
}
19
25
20
- public ArrayList <ProfilerRequest > getRequests () {
21
- ArrayList <ProfilerRequest > list = new ArrayList <>();
22
-
23
- String trennzeichen = "," ;
24
-
26
+ @ NotNull
27
+ public List <ProfilerRequestInterface > getRequests () {
28
+ List <ProfilerRequestInterface > list = new ArrayList <>();
25
29
try {
26
30
BufferedReader in = new BufferedReader (new FileReader (this .file ));
27
31
String readString ;
28
32
while ((readString = in .readLine ()) != null ) {
29
- list .add (new ProfilerRequest (readString .split (trennzeichen ), this ));
33
+ list .add (new ProfilerRequest (readString .split ("," ), this ));
30
34
}
31
35
32
36
in .close ();
33
37
} catch (IOException ignored ) {
34
-
35
38
}
36
39
37
-
38
40
return list ;
39
41
}
40
42
41
- public String getPath (ProfilerRequest profilerRequest ) {
43
+ @ NotNull
44
+ public String getPath (@ NotNull ProfilerRequestInterface profilerRequest ) {
42
45
String [] hash = profilerRequest .getHash ().split ("(?<=\\ G.{2})" );
43
-
44
46
return hash [2 ] + "/" + hash [1 ] + "/" + profilerRequest .getHash ();
45
-
46
47
}
47
48
48
49
@ Nullable
49
- public File getFile (ProfilerRequest profilerRequest ) {
50
+ public File getFile (@ NotNull ProfilerRequestInterface profilerRequest ) {
50
51
String path = this .getPath (profilerRequest );
51
52
52
53
File file = new File (this .file .getParentFile ().getAbsolutePath () + "/" + path );
@@ -59,8 +60,8 @@ public File getFile(ProfilerRequest profilerRequest) {
59
60
}
60
61
61
62
@ Nullable
62
- public ProfilerRequest getRequestOnHash (String hash ) {
63
- for (ProfilerRequest profilerRequest :this .getRequests ()) {
63
+ public ProfilerRequestInterface getRequestOnHash (@ NotNull String hash ) {
64
+ for (ProfilerRequestInterface profilerRequest :this .getRequests ()) {
64
65
if (profilerRequest .getHash ().equals (hash )) {
65
66
return profilerRequest ;
66
67
}
@@ -70,7 +71,7 @@ public ProfilerRequest getRequestOnHash(String hash) {
70
71
}
71
72
72
73
@ Nullable
73
- public String getContent (ProfilerRequest profilerRequest ) {
74
+ public String getContent (@ NotNull ProfilerRequestInterface profilerRequest ) {
74
75
File file = this .getFile (profilerRequest );
75
76
if (file == null ) {
76
77
return null ;
@@ -88,8 +89,6 @@ public String getContent(ProfilerRequest profilerRequest) {
88
89
} catch (IOException ignored ) {
89
90
}
90
91
91
-
92
92
return content .toString ();
93
93
}
94
-
95
94
}
0 commit comments