Skip to content

Commit 5d0ea3a

Browse files
committed
Improve the source code
1 parent 26a4ccd commit 5d0ea3a

1 file changed

Lines changed: 33 additions & 30 deletions

File tree

src/main/java/at/tugraz/ist/ase/hiconfit/KBStatistics.java

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import static com.google.common.base.Preconditions.checkArgument;
3232

3333
/**
34-
* The class that calculates the statistics of knowledge bases.
34+
* The class calculates the statistics of given knowledge bases.
3535
* Supports the following knowledge bases:
3636
* - Feature Models from SPLOT, FeatureIDE, Glencoe, and other tools
3737
* - PC and Renault from <a href="https://www.itu.dk/research/cla/externals/clib/">https://www.itu.dk/research/cla/externals/clib/</a>
@@ -120,15 +120,19 @@ public void calculate() throws IOException, FeatureModelParserException {
120120
if (options.getKb() != null) {
121121
for (String nameKb : options.getKb()) {
122122
KB kb = null;
123-
if (nameKb.equals("PC")) { // if pc, then calculate the statistics of pc
124-
System.out.println("\nCalculating statistics for PC...");
125-
kb = new PCKB(false);
126-
} else if (nameKb.equals("Renault")) { // if Renault, then calculate the statistics of Renault
127-
System.out.println("\nCalculating statistics for Renault...");
128-
kb = new RenaultKB(false);
129-
} else if (nameKb.equals("Camera")) { // if Camera, then calculate the statistics of Camera
130-
System.out.println("\nCalculating statistics for Camera...");
131-
kb = new CameraKB(false);
123+
switch (nameKb) {
124+
case "PC" -> { // if pc, then calculate the statistics of pc
125+
System.out.println("\nCalculating statistics for PC...");
126+
kb = new PCKB(false);
127+
}
128+
case "Renault" -> { // if Renault, then calculate the statistics of Renault
129+
System.out.println("\nCalculating statistics for Renault...");
130+
kb = new RenaultKB(false);
131+
}
132+
case "Camera" -> { // if Camera, then calculate the statistics of Camera
133+
System.out.println("\nCalculating statistics for Camera...");
134+
kb = new CameraKB(false);
135+
}
132136
}
133137

134138
checkArgument(kb != null, "The knowledge base is not supported.");
@@ -176,15 +180,14 @@ private void processFM(BufferedWriter writer, int counter, File file) throws IOE
176180
private void saveStatistics(BufferedWriter writer, int counter, KB kb) throws IOException {
177181
boolean consistent = kb.getModelKB().getSolver().solve();
178182

179-
// TODO - use writer.newLine();
180-
writer.write(counter + "\n");
181-
writer.write("Name: " + kb.getName() + "\n");
182-
writer.write("Source: " + kb.getSource() + "\n");
183-
writer.write("#variables: " + kb.getNumVariables() + "\n");
184-
writer.write("#constraints: " + kb.getNumConstraints() + "\n");
185-
writer.write("#Choco variables: " + kb.getNumChocoVars() + "\n");
186-
writer.write("#Choco constraints: " + kb.getNumChocoConstraints() + "\n");
187-
writer.write("Consistency: " + consistent + "\n");
183+
writer.write(String.valueOf(counter)); writer.newLine();
184+
writer.write("Name: " + kb.getName()); writer.newLine();
185+
writer.write("Source: " + kb.getSource()); writer.newLine();
186+
writer.write("#variables: " + kb.getNumVariables()); writer.newLine();
187+
writer.write("#constraints: " + kb.getNumConstraints()); writer.newLine();
188+
writer.write("#Choco variables: " + kb.getNumChocoVars()); writer.newLine();
189+
writer.write("#Choco constraints: " + kb.getNumChocoConstraints()); writer.newLine();
190+
writer.write("Consistency: " + consistent); writer.newLine();
188191

189192
writer.flush();
190193
}
@@ -196,17 +199,17 @@ private void saveFMStatistics(BufferedWriter writer, int counter, KB kb,
196199

197200
saveStatistics(writer, counter, kb);
198201

199-
writer.write("\n");
200-
writer.write("CTC ratio: " + ctc + "\n");
201-
writer.write("#features: " + fm.getNumOfFeatures() + "\n");
202-
writer.write("#relationships: " + fm.getNumOfRelationships() + "\n");
203-
writer.write("#constraints: " + fm.getNumOfConstraints() + "\n");
204-
writer.write("#MANDATORY: " + fm.getNumOfRelationships(MandatoryRelationship.class) + "\n");
205-
writer.write("#OPTIONAL: " + fm.getNumOfRelationships(OptionalRelationship.class) + "\n");
206-
writer.write("#ALTERNATIVE: " + fm.getNumOfRelationships(AlternativeRelationship.class) + "\n");
207-
writer.write("#OR: " + fm.getNumOfRelationships(OrRelationship.class) + "\n");
208-
writer.write("#REQUIRES: " + fm.getNumOfRequires() + "\n");
209-
writer.write("#EXCLUDES: " + fm.getNumOfExcludes() + "\n");
202+
writer.newLine();
203+
writer.write("CTC ratio: " + ctc); writer.newLine();
204+
writer.write("#features: " + fm.getNumOfFeatures()); writer.newLine();
205+
writer.write("#relationships: " + fm.getNumOfRelationships()); writer.newLine();
206+
writer.write("#constraints: " + fm.getNumOfConstraints()); writer.newLine();
207+
writer.write("#MANDATORY: " + fm.getNumOfRelationships(MandatoryRelationship.class)); writer.newLine();
208+
writer.write("#OPTIONAL: " + fm.getNumOfRelationships(OptionalRelationship.class)); writer.newLine();
209+
writer.write("#ALTERNATIVE: " + fm.getNumOfRelationships(AlternativeRelationship.class)); writer.newLine();
210+
writer.write("#OR: " + fm.getNumOfRelationships(OrRelationship.class)); writer.newLine();
211+
writer.write("#REQUIRES: " + fm.getNumOfRequires()); writer.newLine();
212+
writer.write("#EXCLUDES: " + fm.getNumOfExcludes()); writer.newLine();
210213

211214
writer.flush();
212215
}

0 commit comments

Comments
 (0)