Skip to content

Commit d244446

Browse files
Merge pull request #9 from VariantSync/next-release
VEVOS Simulation V1.1.1
2 parents 9050939 + d0d4469 commit d244446

5 files changed

Lines changed: 65 additions & 14 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<!-- Adjust group id for anonymous projects -->
88
<groupId>org.variantsync.vevos</groupId>
99
<!-- Adjust the generateVariant name -->
10-
<artifactId>Simulation</artifactId>
11-
<version>1.0.0</version>
10+
<artifactId>simulation</artifactId>
11+
<version>1.1.1</version>
1212

1313
<properties>
1414
<!-- Adjust your java version here -->

src/main/java/org/variantsync/vevos/simulation/io/kernelhaven/VariabilityModelLoader.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ public boolean canLoad(Path p) {
3030
return FeatureModelUtils.FromVariabilityModel(cache.readFixed(p.toFile()));
3131
} else {
3232
List<String> variables = Files.readAllLines(p).stream().map(String::trim).collect(Collectors.toList());
33-
final IFeatureModel featureModel = DefaultFeatureModelFactory.getInstance().create();
34-
IFeature root = DefaultFeatureModelFactory.getInstance().createFeature(featureModel, "ROOT");
35-
FeatureUtils.setRoot(featureModel, root);
36-
return FeatureModelUtils.FillFeatureModel(featureModel, variables);
33+
return FeatureModelUtils.FromOptionalFeatures(variables);
3734
}
3835
});
3936
}

src/main/java/org/variantsync/vevos/simulation/util/fide/FormulaUtils.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.ArrayList;
77
import java.util.Arrays;
88
import java.util.List;
9+
import java.util.function.Function;
10+
import java.util.function.Predicate;
911

1012
public class FormulaUtils {
1113
public static Node negate(final Node node) {
@@ -60,7 +62,51 @@ public static void flatten(final And and) {
6062
} while (!redundantChildren.isEmpty());
6163
}
6264

63-
public static String toString(final Node formula, final String[] symbols) {
65+
/**
66+
* Replaces all nodes within the given formula's tree that match the given predicate.
67+
* Matching nodes (i.e., nodes for which the predicate who returns true) will be replaced by the value returned
68+
* by the replacement function, invoked on the matching node.
69+
* @param root The root of the formula in which occurences of formulas should be replaced. The object remains unaltered.
70+
* @param who A replacement is made whenever this predicate evaluates to true on a given node.
71+
* @param replacement Whenever a node should be replaced, this function is invoked with that node as argument.
72+
* The node will be replaced with the node returned.
73+
* @return A new formula in which all nodes matching the given predicate are replaced.
74+
*/
75+
public static Node replaceAll(final Node root, final Predicate<Node> who, final Function<Node, Node> replacement) {
76+
if (root == null) {
77+
return null;
78+
}
79+
80+
return replaceAllInplace(root.clone(), who, replacement);
81+
}
82+
83+
/**
84+
* Inplace variant of the {@link #replaceAll(Node, Predicate, Function)} function.
85+
* This means the given formula (root parameter) will be altered.
86+
*/
87+
public static Node replaceAllInplace(final Node root, final Predicate<Node> who, final Function<Node, Node> replacement) {
88+
if (root == null) {
89+
return null;
90+
}
91+
92+
if (who.test(root)) {
93+
return replacement.apply(root);
94+
} else {
95+
final Node[] children = root.getChildren();
96+
if (children != null) {
97+
for (int i = 0; i < children.length; ++i) {
98+
children[i] = replaceAllInplace(children[i], who, replacement);
99+
}
100+
root.setChildren(children);
101+
}
102+
return root;
103+
}
104+
}
105+
106+
public static String toString(Node formula, final String[] symbols) {
107+
formula = replaceAll(formula, FixTrueFalse::isTrue, n -> FixTrueFalse.TrueAs1);
108+
formula = replaceAllInplace(formula, FixTrueFalse::isFalse, n -> FixTrueFalse.FalseAs0);
109+
64110
final NodeWriter writer = new NodeWriter(formula);
65111
writer.setNotation(NodeWriter.Notation.INFIX);
66112
writer.setEnquoteWhitespace(false);

src/main/java/org/variantsync/vevos/simulation/util/fide/bugfix/FixTrueFalse.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@
1717
* as well as a conversion method for parsing certain feature names to true and false, respectively.
1818
*/
1919
public class FixTrueFalse {
20-
/// Names of variables that we want to interpret as atomic values true or false, respectively.
21-
public final static List<String> TrueNames = Arrays.asList("true", "1");
22-
public final static List<String> FalseNames = Arrays.asList("false", "0");
23-
2420
/*
2521
Constant literals representing the true and false value
2622
*/
2723
public final static Literal True = new org.prop4j.True();
2824
public final static Literal False = new org.prop4j.False();
2925

26+
/*
27+
Constant literals representing the true and false values only for serialization.
28+
True and False are represented by the numeric values 0 and 1.
29+
*/
30+
public final static Literal TrueAs1 = new Literal("1");
31+
public final static Literal FalseAs0 = new Literal("0");
32+
33+
/// Names of variables that we want to interpret as atomic values true or false, respectively.
34+
public final static List<String> TrueNames = Arrays.asList("true", (String) TrueAs1.var);
35+
public final static List<String> FalseNames = Arrays.asList("false", (String) FalseAs0.var);
36+
3037
/**
3138
* @return True iff the given formula is a true literal.
3239
* @see FixTrueFalse::isTrueLiteral
@@ -47,14 +54,14 @@ public static boolean isFalse(final Node n) {
4754
* @return True iff the given name represents the atomic value true w.r.t. the constant TrueNames.
4855
*/
4956
public static boolean isTrueLiteral(final Literal l) {
50-
return TrueNames.stream().anyMatch(t -> t.equals(l.var.toString().toLowerCase()));
57+
return TrueNames.stream().anyMatch(t -> t.equalsIgnoreCase(l.var.toString()));
5158
}
5259

5360
/**
5461
* @return True iff the given name represents the atomic value false w.r.t. the constant FalseNames.
5562
*/
5663
public static boolean isFalseLiteral(final Literal l) {
57-
return FalseNames.stream().anyMatch(f -> f.equals(l.var.toString().toLowerCase()));
64+
return FalseNames.stream().anyMatch(f -> f.equalsIgnoreCase(l.var.toString()));
5865
}
5966

6067
private static Node[] filterMatches(final Node[] nodes, Predicate<Node> filter) {

src/main/java/org/variantsync/vevos/simulation/variability/pc/variantlines/VariantAnnotation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.prop4j.Node;
44
import org.prop4j.NodeWriter;
5+
import org.variantsync.vevos.simulation.util.fide.FormulaUtils;
56
import org.variantsync.vevos.simulation.variability.pc.options.VariantGenerationOptions;
67

78
import java.util.ArrayList;
@@ -16,7 +17,7 @@ public List<String> project(final VariantGenerationOptions projectionOptions, fi
1617
final List<String> result = new ArrayList<>();
1718

1819
if (projectionOptions.withMacros()) {
19-
result.add("#if " + condition.toString(NodeWriter.javaSymbols));
20+
result.add("#if " + FormulaUtils.toString(condition, NodeWriter.javaSymbols));
2021
}
2122

2223
for (final VariantLineChunk child : lines) {

0 commit comments

Comments
 (0)