| 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 |
|
package org.sat4j; |
| 27 |
|
|
| 28 |
|
import java.io.BufferedReader; |
| 29 |
|
import java.io.FileReader; |
| 30 |
|
import java.io.FileWriter; |
| 31 |
|
import java.io.IOException; |
| 32 |
|
import java.io.InputStreamReader; |
| 33 |
|
import java.io.Reader; |
| 34 |
|
import java.net.MalformedURLException; |
| 35 |
|
import java.net.URL; |
| 36 |
|
import java.util.Calendar; |
| 37 |
|
import java.util.HashMap; |
| 38 |
|
import java.util.Map; |
| 39 |
|
import java.util.StringTokenizer; |
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 98 (98) |
Complexity: 25 |
Complexity Density: 0,56 |
|
| 41 |
|
public class ResultsManager { |
| 42 |
|
|
| 43 |
|
public static final String SEPARATOR = "="; |
| 44 |
|
|
| 45 |
|
public static final String EXT_JU = "WXP"; |
| 46 |
|
|
| 47 |
|
public static final String COMMENT = "#"; |
| 48 |
|
|
| 49 |
|
private final String wxpFileName; |
| 50 |
|
|
| 51 |
|
private final Map<String, ExitCode> files; |
| 52 |
|
|
| 53 |
|
private final boolean save; |
| 54 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 55 |
0
|
public ResultsManager(final String wxpFileName, final boolean save)... |
| 56 |
|
throws MalformedURLException, IOException { |
| 57 |
|
|
| 58 |
0
|
this.wxpFileName = wxpFileName; |
| 59 |
0
|
this.save = save; |
| 60 |
0
|
files = getInformations(wxpFileName); |
| 61 |
|
} |
| 62 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
| 63 |
0
|
public final ResultCode compare(final String fileName,... |
| 64 |
|
final ExitCode newCode) { |
| 65 |
|
|
| 66 |
0
|
final ExitCode tmp = files.get(fileName); |
| 67 |
0
|
final ExitCode oldCode = tmp == null ? ExitCode.UNKNOWN : tmp; |
| 68 |
0
|
final ResultCode resultCode = computeResultCode(oldCode, newCode); |
| 69 |
|
|
| 70 |
0
|
if (save && resultCode.equals(ResultCode.UPDATED)) { |
| 71 |
0
|
files.put(fileName, newCode); |
| 72 |
|
} |
| 73 |
|
|
| 74 |
0
|
return resultCode; |
| 75 |
|
} |
| 76 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 77 |
0
|
public final void save() {... |
| 78 |
|
|
| 79 |
0
|
save(wxpFileName); |
| 80 |
|
} |
| 81 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
0
|
public String[] getFiles() {... |
| 83 |
0
|
return files.keySet().toArray(new String[files.keySet().size()]); |
| 84 |
|
} |
| 85 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0,44 |
|
| 86 |
0
|
public final void save(final String wxpFileName) {... |
| 87 |
0
|
FileWriter fw = null; |
| 88 |
0
|
try { |
| 89 |
0
|
fw = new FileWriter(wxpFileName); |
| 90 |
0
|
fw.write(getFileDescription()); |
| 91 |
|
|
| 92 |
|
} catch (IOException e) { |
| 93 |
0
|
e.printStackTrace(); |
| 94 |
|
} finally { |
| 95 |
0
|
if (fw!=null) { |
| 96 |
0
|
try { |
| 97 |
0
|
fw.close(); |
| 98 |
|
} catch (IOException e) { |
| 99 |
0
|
e.printStackTrace(); |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
} |
| 103 |
|
} |
| 104 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0,22 |
|
| 105 |
0
|
private final String getFileDescription() {... |
| 106 |
0
|
final StringBuffer sb = new StringBuffer("#Evaluation : "); |
| 107 |
|
|
| 108 |
0
|
sb.append("\n\n"); |
| 109 |
|
|
| 110 |
0
|
for (String file : files.keySet()) { |
| 111 |
0
|
sb.append(file); |
| 112 |
0
|
sb.append(ResultsManager.SEPARATOR); |
| 113 |
0
|
sb.append(files.get(file)); |
| 114 |
0
|
sb.append('\n'); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
0
|
sb.append("\n\n#Evaluation END"); |
| 118 |
0
|
return sb.toString(); |
| 119 |
|
} |
| 120 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 12 |
Complexity Density: 1,33 |
|
| 121 |
0
|
private final ResultCode computeResultCode(final ExitCode oldS,... |
| 122 |
|
final ExitCode newS) { |
| 123 |
0
|
if (oldS.equals(newS)) { |
| 124 |
0
|
return ResultCode.OK; |
| 125 |
|
} |
| 126 |
|
|
| 127 |
0
|
if ((ExitCode.UNKNOWN.equals(oldS)) |
| 128 |
|
&& ((ExitCode.UNSATISFIABLE.equals(newS) || (ExitCode.SATISFIABLE |
| 129 |
|
.equals(newS))))) { |
| 130 |
0
|
return ResultCode.UPDATED; |
| 131 |
|
} |
| 132 |
|
|
| 133 |
0
|
if (((ExitCode.UNSATISFIABLE.equals(oldS) || (ExitCode.SATISFIABLE |
| 134 |
|
.equals(oldS)))) |
| 135 |
|
&& (ExitCode.UNKNOWN.equals(newS))) { |
| 136 |
0
|
return ResultCode.WARNING; |
| 137 |
|
} |
| 138 |
|
|
| 139 |
0
|
if (((ExitCode.SATISFIABLE.equals(oldS)) && (ExitCode.UNSATISFIABLE |
| 140 |
|
.equals(newS))) |
| 141 |
|
|| ((ExitCode.UNSATISFIABLE.equals(oldS)) && (ExitCode.SATISFIABLE |
| 142 |
|
.equals(newS)))) { |
| 143 |
0
|
return ResultCode.KO; |
| 144 |
|
} |
| 145 |
|
|
| 146 |
0
|
return ResultCode.UNKNOWN; |
| 147 |
|
} |
| 148 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 149 |
0
|
public static final Map<String, ExitCode> getInformations(final URL path)... |
| 150 |
|
throws IOException { |
| 151 |
|
|
| 152 |
0
|
return getInformations(new InputStreamReader(path.openStream())); |
| 153 |
|
} |
| 154 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
| 155 |
0
|
public static final Map<String, ExitCode> getInformations(final String path)... |
| 156 |
|
throws MalformedURLException, IOException { |
| 157 |
|
|
| 158 |
0
|
if (path.startsWith("http://")) { |
| 159 |
0
|
return getInformations(new URL(path)); |
| 160 |
|
} |
| 161 |
0
|
return getInformations(new FileReader(path)); |
| 162 |
|
} |
| 163 |
|
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 7 |
Complexity Density: 0,39 |
|
| 164 |
0
|
public static final Map<String, ExitCode> getInformations(final Reader in) {... |
| 165 |
0
|
final BufferedReader br = new BufferedReader(in); |
| 166 |
|
|
| 167 |
0
|
final Map<String, ExitCode> ci = new HashMap<String, ExitCode>(); |
| 168 |
0
|
StringTokenizer tokens; |
| 169 |
0
|
String line = null; |
| 170 |
0
|
int cpt = 1; |
| 171 |
|
|
| 172 |
0
|
try { |
| 173 |
|
|
| 174 |
0
|
line = br.readLine(); |
| 175 |
0
|
for (; line != null; cpt++) { |
| 176 |
|
|
| 177 |
0
|
if ((!"".equals(line.trim())) |
| 178 |
|
&& (!(line.trim()).startsWith(COMMENT))) { |
| 179 |
0
|
tokens = new StringTokenizer(line, SEPARATOR); |
| 180 |
|
|
| 181 |
0
|
if (tokens.countTokens() == 2) { |
| 182 |
0
|
ci.put(tokens.nextToken(), ExitCode.valueOf(tokens |
| 183 |
|
.nextToken())); |
| 184 |
|
} else { |
| 185 |
0
|
throw new IllegalArgumentException(); |
| 186 |
|
} |
| 187 |
|
|
| 188 |
|
} |
| 189 |
0
|
line = br.readLine(); |
| 190 |
|
} |
| 191 |
|
} catch (IllegalArgumentException i) { |
| 192 |
0
|
System.err.println("File Parsing Error in line " + cpt |
| 193 |
|
+ "\nError caused by : " + line); |
| 194 |
|
} catch (IOException e) { |
| 195 |
0
|
e.printStackTrace(); |
| 196 |
0
|
return null; |
| 197 |
|
} |
| 198 |
|
|
| 199 |
0
|
return ci; |
| 200 |
|
} |
| 201 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 202 |
0
|
public static final String printLine(final String fileName,... |
| 203 |
|
final ExitCode exitCode, final ResultCode resultCode) { |
| 204 |
0
|
return fileName + SEPARATOR + exitCode.toString() + " [" |
| 205 |
|
+ resultCode.toString() + "]"; |
| 206 |
|
} |
| 207 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 208 |
0
|
public static final String createPath() {... |
| 209 |
0
|
final StringBuffer sb = new StringBuffer("Eval_"); |
| 210 |
0
|
sb.append(Calendar.getInstance().getTime().toString().replace(" ", "_") |
| 211 |
|
.replace(":", "_")); |
| 212 |
|
|
| 213 |
|
|
| 214 |
0
|
return sb.toString(); |
| 215 |
|
} |
| 216 |
|
|
| 217 |
|
} |