Skip to content

Commit 9efe1a9

Browse files
committed
decrease non-determinism*
HashSet -> LinkedHashSet HashMap -> LinkedHashMap
1 parent 122d42b commit 9efe1a9

File tree

28 files changed

+106
-106
lines changed

28 files changed

+106
-106
lines changed

ocl2smt/src/main/java/de/monticore/ocl2smt/gradle/OCLSemDiffTask.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.io.File;
1515
import java.io.IOException;
1616
import java.nio.charset.Charset;
17-
import java.util.HashSet;
17+
import java.util.LinkedHashSet;
1818
import java.util.Set;
1919
import org.apache.commons.io.FileUtils;
2020
import org.gradle.api.DefaultTask;
@@ -51,7 +51,7 @@ public abstract class OCLSemDiffTask extends DefaultTask {
5151
public abstract RegularFileProperty getTraceOD();
5252

5353
protected Set<ASTOCLCompilationUnit> loadOCL(File cdFile, Set<File> oclFiles) throws IOException {
54-
Set<ASTOCLCompilationUnit> result = new HashSet<>();
54+
Set<ASTOCLCompilationUnit> result = new LinkedHashSet<>();
5555
for (File f : oclFiles) {
5656
result.add(OCL_Loader.loadAndCheckOCL(f, cdFile));
5757
}
@@ -78,14 +78,14 @@ public void run() throws IOException {
7878
ASTODArtifact trace;
7979
// Compute Diff
8080
if (negativeOCL.isEmpty()) {
81-
witnesses = new HashSet<>();
81+
witnesses = new LinkedHashSet<>();
8282
witnesses.add(
83-
OCLDiffGenerator.oclWitness(cd, positiveOCL, new HashSet<>(), new HashSet<>(), false));
83+
OCLDiffGenerator.oclWitness(cd, positiveOCL, new LinkedHashSet<>(), new LinkedHashSet<>(), false));
8484
} else {
8585

8686
diff =
8787
OCLDiffGenerator.oclDiff(
88-
cd, positiveOCL, negativeOCL, new HashSet<>(), new HashSet<>(), false);
88+
cd, positiveOCL, negativeOCL, new LinkedHashSet<>(), new LinkedHashSet<>(), false);
8989
witnesses = diff.getDiffWitness();
9090
if (getTraceOD().isPresent()) {
9191
trace = diff.getUnSatCore();

ocl2smt/src/main/java/de/monticore/ocl2smt/helpers/IOHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
import java.nio.charset.Charset;
2121
import java.nio.file.Path;
2222
import java.nio.file.Paths;
23-
import java.util.HashSet;
23+
import java.util.LinkedHashSet;
2424
import java.util.Set;
2525
import org.apache.commons.io.FileUtils;
2626

2727
public class IOHelper {
2828
public static Set<ASTOCLCompilationUnit> parseOCl(File cdFile, Set<File> oclFiles) {
29-
Set<ASTOCLCompilationUnit> res = new HashSet<>();
29+
Set<ASTOCLCompilationUnit> res = new LinkedHashSet<>();
3030
for (File oclFile : oclFiles) {
3131

3232
try {

ocl2smt/src/main/java/de/monticore/ocl2smt/ocl2smt/oclExpr2smt/OCLExprConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class OCLExprConverter<EXPR extends ExprAdapter<?>> {
3636
public OCLExprConverter(CDExprFactory<EXPR> eFactory, TypeFactory typeFactory) {
3737
this.tFactory = typeFactory;
3838
this.eFactory = eFactory;
39-
varNames = new HashMap<>();
39+
varNames = new LinkedHashMap<>();
4040
}
4141

4242
public EXPR convertExpr(ASTExpression node) {
@@ -335,7 +335,7 @@ private Set<String> openSetCompScope(ASTSetComprehension node) {
335335
mkConst(gen.getName(), type);
336336
}
337337

338-
Set<String> setCompScopeVar = new HashSet<>(varCollector.getAllVariableNames());
338+
Set<String> setCompScopeVar = new LinkedHashSet<>(varCollector.getAllVariableNames());
339339
setCompScopeVar.addAll(generatorCollector.getAllVariableNames());
340340

341341
return setCompScopeVar;

ocl2smt/src/main/java/de/monticore/ocl2smt/ocldiff/OCLDiffGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ public static OCLOPDiffResult oclOPDiffV1(
504504

505505
private static Set<IdentifiableBoolExpr> od2constraints(
506506
Set<ASTODArtifact> ods, ASTCDCompilationUnit cd, Context ctx) {
507-
Set<IdentifiableBoolExpr> constraint = new HashSet<>();
507+
Set<IdentifiableBoolExpr> constraint = new LinkedHashSet<>();
508508
for (ASTODArtifact od : ods) {
509509
OD2SMTGenerator od2SMTGenerator = new OD2SMTGenerator();
510510
od2SMTGenerator.od2smt(od, cd, ctx);
@@ -522,7 +522,7 @@ private static Set<IdentifiableBoolExpr> negativeOd2smt(
522522

523523
private static Set<IdentifiableBoolExpr> negativOd2smt(
524524
Set<ASTODArtifact> ods, ASTCDCompilationUnit cd, Context ctx) {
525-
Set<IdentifiableBoolExpr> res = new HashSet<>();
525+
Set<IdentifiableBoolExpr> res = new LinkedHashSet<>();
526526
for (ASTODArtifact od : ods) {
527527
OD2SMTGenerator od2SMTGenerator = new OD2SMTGenerator();
528528
od2SMTGenerator.od2smt(od, cd, ctx);
@@ -558,7 +558,7 @@ private static Set<IdentifiableBoolExpr> od2Constraints(
558558
}
559559

560560
private static Context buildContext() {
561-
Map<String, String> cfg = new HashMap<>();
561+
Map<String, String> cfg = new LinkedHashMap<>();
562562
cfg.put("model", "true");
563563
return new Context(cfg);
564564
}

ocl2smt/src/main/java/de/monticore/ocl2smt/ocldiff/invariantDiff/OCLInvDiffStrategy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ default OCLInvDiffResult oclDiff(
7575
List<ASTOCLInvariant> invariantList = OCLHelper.collectInv(oldOcl);
7676

7777
// compute diff witness for each invariant
78-
Set<OCLInvDiffResult> diffs = new HashSet<>();
78+
Set<OCLInvDiffResult> diffs = new LinkedHashSet<>();
7979
invariantList.forEach(
8080
inv -> diffs.add(oclInvDiff(cd, newOcl, inv, addConstr, ctx, timeout, partial)));
8181

8282
// merge different diff
8383
List<ASTODLink> traces = new ArrayList<>();
84-
Set<ASTODArtifact> witnesses = new HashSet<>();
84+
Set<ASTODArtifact> witnesses = new LinkedHashSet<>();
8585
ASTODArtifact unSatCore = null;
8686

8787
for (OCLInvDiffResult diff : diffs) {
@@ -155,7 +155,7 @@ default OCLInvDiffResult computeDiff(
155155
int timeout,
156156
boolean partial) {
157157

158-
Set<ASTODArtifact> satOdList = new HashSet<>();
158+
Set<ASTODArtifact> satOdList = new LinkedHashSet<>();
159159
List<ASTODLink> traceUnSat = new ArrayList<>();
160160

161161
// add one by one all Constraints to the Solver and check if it can always produce a Model
@@ -175,7 +175,7 @@ default OCLInvDiffResult computeDiff(
175175
assert witness.isPresent();
176176
satOdList.add(witness.get());
177177
} else if (status == Status.UNKNOWN) {
178-
return new OCLInvDiffResult(null, new HashSet<>());
178+
return new OCLInvDiffResult(null, new LinkedHashSet<>());
179179
} else {
180180
OD4ReportMill.init();
181181
Log.info("[UNSAT]The invariant is refined by the new model", this.getClass().getName());

ocl2smt/src/main/java/de/monticore/ocl2smt/ocldiff/invariantDiff/OCLInvariantDiff.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import de.monticore.odbasis._ast.ASTODArtifact;
1919
import de.se_rwth.commons.logging.Log;
2020
import java.util.ArrayList;
21-
import java.util.HashSet;
21+
import java.util.LinkedHashSet;
2222
import java.util.List;
2323
import java.util.Set;
2424

@@ -67,7 +67,7 @@ public OCLInvDiffResult oclInvDiff(
6767
return computeDiff(ocl2SMTGenerator, newConstraints, negConstraints, timeout, partial);
6868
}
6969

70-
return new OCLInvDiffResult(null, new HashSet<>());
70+
return new OCLInvDiffResult(null, new LinkedHashSet<>());
7171
}
7272

7373
public OCLInvDiffResult CDOCLDiff(
@@ -105,7 +105,7 @@ public OCLInvDiffResult CDOCLDiff(
105105
1,
106106
CDSemantics.SIMPLE_CLOSED_WORLD);
107107
if (!res.isEmpty()) {
108-
return new OCLInvDiffResult(null, new HashSet<>(res));
108+
return new OCLInvDiffResult(null, new LinkedHashSet<>(res));
109109
}
110110

111111
// build positive constraint List

ocl2smt/src/main/java/de/monticore/ocl2smt/ocldiff/operationDiff/OCLOperationDiff.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public Set<OCLOPWitness> oclWitness(
3838
ctx = buildContext();
3939
OCLHelper.buildPreCD(ast);
4040
FullOCL2SMTGenerator fullOCL2SMTGenerator = new FullOCL2SMTGenerator(ast, ctx);
41-
Set<OCLOPWitness> res = new HashSet<>();
41+
Set<OCLOPWitness> res = new LinkedHashSet<>();
4242

4343
for (ASTOCLMethodSignature method : getMethodList(ocl)) {
4444
res.addAll(oclWitnessHelper(ocl, fullOCL2SMTGenerator, method, partial));
@@ -64,7 +64,7 @@ private Set<OCLOPWitness> oclWitnessHelper(
6464
// add invariants
6565
solverConstraints.addAll(invConstraints);
6666

67-
Set<OCLOPWitness> res = new HashSet<>();
67+
Set<OCLOPWitness> res = new LinkedHashSet<>();
6868
Solver solver;
6969

7070
for (OPConstraint constraint : opConstraints) {
@@ -110,7 +110,7 @@ public OCLOPDiffResult oclDiffHelper(
110110

111111
// setup
112112
ctx = buildContext();
113-
Set<OCLOPWitness> opDiffWitness = new HashSet<>();
113+
Set<OCLOPWitness> opDiffWitness = new LinkedHashSet<>();
114114
List<ASTODLink> trace = new ArrayList<>();
115115
OCLHelper.buildPreCD(ast);
116116
FullOCL2SMTGenerator fullOcl2smt = new FullOCL2SMTGenerator(ast, ctx);
@@ -186,7 +186,7 @@ private List<ASTOCLOperationConstraint> getOperationsConstraints(
186186
private Map<ASTOCLMethodSignature, List<ASTOCLOperationConstraint>> sortOPConstraint(
187187
Set<ASTOCLCompilationUnit> oclSet) {
188188

189-
Map<ASTOCLMethodSignature, List<ASTOCLOperationConstraint>> res = new HashMap<>();
189+
Map<ASTOCLMethodSignature, List<ASTOCLOperationConstraint>> res = new LinkedHashMap<>();
190190
for (ASTOCLOperationConstraint opConstraint : getOperationsConstraints(oclSet)) {
191191

192192
ASTOCLOperationSignature opSignature = opConstraint.getOCLOperationSignature();
@@ -270,7 +270,7 @@ public String buildInvName(IdentifiableBoolExpr constr) {
270270
}
271271

272272
public Context buildContext() {
273-
Map<String, String> cfg = new HashMap<>();
273+
Map<String, String> cfg = new LinkedHashMap<>();
274274
cfg.put("model", "true");
275275
return new Context(cfg);
276276
}

ocl2smt/src/main/java/de/monticore/ocl2smt/visitors/SetGeneratorCollector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import de.monticore.ocl.setexpressions._ast.ASTGeneratorDeclaration;
44
import de.monticore.ocl.setexpressions._visitor.SetExpressionsVisitor2;
5-
import java.util.HashSet;
5+
import java.util.LinkedHashSet;
66
import java.util.Set;
77
import java.util.stream.Collectors;
88

99
public class SetGeneratorCollector implements SetExpressionsVisitor2 {
10-
Set<ASTGeneratorDeclaration> variableSet = new HashSet<>();
10+
Set<ASTGeneratorDeclaration> variableSet = new LinkedHashSet<>();
1111

1212
public void visit(ASTGeneratorDeclaration node) {
1313
variableSet.add(node);

ocl2smt/src/main/java/de/monticore/ocl2smt/visitors/SetVariableCollector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import de.monticore.ocl.setexpressions._ast.ASTSetVariableDeclaration;
44
import de.monticore.ocl.setexpressions._visitor.SetExpressionsVisitor2;
5-
import java.util.HashSet;
5+
import java.util.LinkedHashSet;
66
import java.util.Set;
77
import java.util.stream.Collectors;
88

99
public class SetVariableCollector implements SetExpressionsVisitor2 {
10-
Set<ASTSetVariableDeclaration> variableSet = new HashSet<>();
10+
Set<ASTSetVariableDeclaration> variableSet = new LinkedHashSet<>();
1111

1212
@Override
1313
public void visit(ASTSetVariableDeclaration node) {

ocl2smt/src/main/java/de/monticore/od2smt/OD2SMTGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public class OD2SMTGenerator implements IOD2SMTGenerator {
4242
protected Context ctx;
4343
protected OCLExprConverter<Z3ExprAdapter> exprConv;
4444

45-
protected Map<ASTODObject, Expr<?>> objectsMap = new HashMap<>();
46-
protected Map<ASTODObject, Set<IdentifiableBoolExpr>> objectConstraint = new HashMap<>();
47-
protected Map<ASTODLink, IdentifiableBoolExpr> linksConstraints = new HashMap<>();
45+
protected Map<ASTODObject, Expr<?>> objectsMap = new LinkedHashMap<>();
46+
protected Map<ASTODObject, Set<IdentifiableBoolExpr>> objectConstraint = new LinkedHashMap<>();
47+
protected Map<ASTODLink, IdentifiableBoolExpr> linksConstraints = new LinkedHashMap<>();
4848

4949
public void od2smt(ASTODArtifact od, ASTCDCompilationUnit cd, Context ctx) {
5050
if (!match(od, cd)) {
@@ -103,7 +103,7 @@ public void closeCtx() {
103103
}
104104

105105
private void convert(ASTODObject node) {
106-
Set<IdentifiableBoolExpr> objectConstr = new HashSet<>();
106+
Set<IdentifiableBoolExpr> objectConstr = new LinkedHashSet<>();
107107
String objectName = "object_" + count_object;
108108
count_object++;
109109

0 commit comments

Comments
 (0)