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 |
|
package issrg.SAWS; |
47 |
|
|
48 |
|
import issrg.SAWS.util.SAWSLogWriter; |
49 |
|
|
50 |
|
import java.util.*; |
51 |
|
import java.io.*; |
52 |
|
import java.io.File; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@author |
57 |
|
|
|
|
| 69.4% |
Uncovered Elements: 26 (85) |
Complexity: 22 |
Complexity Density: 0.57 |
|
58 |
|
public class LogFilenameClass { |
59 |
|
|
60 |
|
private String latestLogFilename; |
61 |
|
private static int lastLogSequence = -1; |
62 |
|
private int debugLevel = 1; |
63 |
|
private java.text.SimpleDateFormat sDateFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH_mm_ssz", Locale.UK); |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
private static SAWSLogWriter sawsDebugLog = new SAWSLogWriter(LogFilenameClass.class.getName()); |
71 |
|
|
72 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
73 |
4
|
public LogFilenameClass() {... |
74 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0
|
public LogFilenameClass(int debugLevel) {... |
76 |
0
|
this.debugLevel = debugLevel; |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
@param |
84 |
|
|
85 |
|
@return |
86 |
|
|
|
|
| 70% |
Uncovered Elements: 3 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
87 |
11
|
public String generateNewLogFileName(){... |
88 |
11
|
Calendar today = new GregorianCalendar(TimeZone.getTimeZone("GMT+1")); |
89 |
|
|
90 |
11
|
StringBuffer tmp = sDateFormat.format(today.getTime(),new StringBuffer(), new java.text.FieldPosition(0)); |
91 |
11
|
lastLogSequence += 1; |
92 |
11
|
String newFileName = "saws" + tmp + getLastLogSequence() + ".dat"; |
93 |
|
|
94 |
11
|
if (debugLevel >= SAWSConstant.VerboseInfo){ |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
0
|
sawsDebugLog.write("Now the UTC time is : " + tmp ); |
99 |
0
|
sawsDebugLog.write("The new log file name is: " + newFileName ); |
100 |
|
} |
101 |
|
|
102 |
11
|
return (newFileName); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
@param |
110 |
|
|
111 |
|
@return |
112 |
|
|
|
|
| 67.3% |
Uncovered Elements: 17 (52) |
Complexity: 19 |
Complexity Density: 0.63 |
|
113 |
3
|
public String getPreviousLogFilename(String logFileRoot, String logFilename) {... |
114 |
|
|
115 |
3
|
File currentPath = new File(logFileRoot); |
116 |
3
|
String[] files = currentPath.list(new WildCardFilter("saws*-*-*.dat") ); |
117 |
3
|
int len = files.length; |
118 |
3
|
if (len == 0 ) { |
119 |
0
|
return (null); |
120 |
|
} |
121 |
|
|
122 |
3
|
Calendar currentDate = ( (logFilename==null) ? null : getDatestamp(logFilename) ); |
123 |
3
|
int currentSeq = ( (logFilename==null) ? 0 : getSequence(logFilename) ); |
124 |
3
|
if (logFilename!=null && getSequence(logFilename) == 0) { |
125 |
0
|
return null; |
126 |
|
} |
127 |
3
|
Calendar latestDate = null; |
128 |
3
|
Calendar nextDate = null; |
129 |
3
|
int latest = 0, latestSeq = 0, nextSeq=0; |
130 |
|
|
131 |
20
|
for (int i = 0; i<len; i++){ |
132 |
17
|
if (files[i].endsWith(".dat") && files[i].substring(0,4).compareTo("saws")==0 ) { |
133 |
14
|
nextDate = getDatestamp(files[i]); |
134 |
14
|
nextSeq = getSequence(files[i] ); |
135 |
14
|
if ( currentDate ==null ){ |
136 |
14
|
if( latestDate==null || (latestDate.before(nextDate)) |
137 |
|
|| ( (latestSeq < nextSeq) && ( !latestDate.after(nextDate)) ) ) { |
138 |
14
|
latestDate = nextDate; |
139 |
14
|
latestSeq = nextSeq; |
140 |
14
|
latest = i; |
141 |
|
} |
142 |
|
} else { |
143 |
0
|
if( latestDate==null |
144 |
|
|| ( (latestDate.before(nextDate)) && (nextDate.before(currentDate)) ) |
145 |
|
|| ( (latestSeq < nextSeq) && ( nextSeq < currentSeq ) ) ) { |
146 |
0
|
latestDate = nextDate; |
147 |
0
|
latestSeq = nextSeq; |
148 |
0
|
latest = i; |
149 |
|
} |
150 |
|
|
151 |
|
} |
152 |
|
} |
153 |
|
} |
154 |
3
|
if (logFilename == null) { |
155 |
3
|
lastLogSequence = latestSeq; |
156 |
|
} |
157 |
|
|
158 |
0
|
if (latestDate == currentDate) return null; |
159 |
3
|
return(files[latest]); |
160 |
|
|
161 |
|
} |
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
163 |
14
|
private int getSequence(String sawsLogFilename){... |
164 |
14
|
String sequenceStr = sawsLogFilename.substring(26, sawsLogFilename.indexOf('.')); |
165 |
14
|
return Integer.parseInt(sequenceStr); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
@param |
174 |
|
|
175 |
|
@return |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
3
|
public String findLatestLogFileName(String logFileRoot){... |
178 |
|
|
179 |
3
|
return(getPreviousLogFilename(logFileRoot, null)); |
180 |
|
} |
181 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
182 |
14
|
private Calendar getDatestamp(String sawsLogFilename){ ... |
183 |
|
|
184 |
14
|
Calendar thisDate = new GregorianCalendar(); |
185 |
14
|
sDateFormat.setCalendar(thisDate); |
186 |
|
|
187 |
14
|
try { |
188 |
14
|
Date d1 = sDateFormat.parse(sawsLogFilename, new java.text.ParsePosition(4) ); |
189 |
14
|
thisDate.setTime(d1); |
190 |
|
|
191 |
|
} catch (Exception e){ |
192 |
0
|
if (debugLevel >= SAWSConstant.ErrorInfo){ |
193 |
0
|
sawsDebugLog.write(e.getMessage()); |
194 |
|
} |
195 |
|
} |
196 |
|
|
197 |
14
|
return thisDate; |
198 |
|
|
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
@param |
206 |
|
|
207 |
|
@return |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
209 |
11
|
public int getLastLogSequence(){ ... |
210 |
11
|
return lastLogSequence; |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
|
} |