Skip to content

Commit 0ad5e14

Browse files
author
Julia Pham
committed
fix: replace hard-coded constructors with factory in FMBuilder
1 parent f380c5d commit 0ad5e14

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/main/java/de/vill/model/building/AbstractUVLElementFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import de.vill.exception.ParseError;
44
import de.vill.model.*;
5+
import de.vill.model.constraint.LiteralConstraint;
56

67
public abstract class AbstractUVLElementFactory {
78

@@ -11,4 +12,6 @@ public abstract class AbstractUVLElementFactory {
1112

1213
public abstract GlobalAttribute createGlobalAttribute(String identifier, FeatureModel featureModel);
1314

15+
// public abstract LiteralConstraint createFeatureLiteral(String name);
16+
1417
}

src/main/java/de/vill/model/building/DefaultUVLElementFactory.java

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

33
import de.vill.exception.ParseError;
44
import de.vill.model.*;
5+
import de.vill.model.constraint.LiteralConstraint;
56

67
public class DefaultUVLElementFactory extends AbstractUVLElementFactory{
78

@@ -19,4 +20,9 @@ public <T> Attribute<T> createAttribute(String name, T value, Feature correspond
1920
public GlobalAttribute createGlobalAttribute(String identifier, FeatureModel featureModel){
2021
return new GlobalAttribute(identifier, featureModel);
2122
}
23+
24+
// @Override
25+
// public LiteralConstraint createFeatureLiteral(String name){
26+
// return new LiteralConstraint(fmInConstruction.getFeatureMap().get(name));
27+
// }
2228
}

src/main/java/de/vill/model/building/FeatureModelBuilder.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@
1919
public class FeatureModelBuilder {
2020

2121
private Function<String, Feature> featureFactory = Feature::new;
22+
2223
private FeatureModel fmInConstruction;
2324

25+
private AbstractUVLElementFactory elementFactory;
26+
2427
public void setFeatureFactory(Function<String, Feature> featureFactory){
2528
this.featureFactory = featureFactory;
2629
}
2730

2831
public FeatureModelBuilder() {
29-
fmInConstruction = new FeatureModel();
32+
this(new DefaultUVLElementFactory());
33+
}
34+
35+
public FeatureModelBuilder(AbstractUVLElementFactory factory) {
36+
this.elementFactory = factory;
37+
this.fmInConstruction = new FeatureModel();
3038
}
3139

3240
public FeatureModelBuilder(FeatureModel old) {
@@ -197,7 +205,7 @@ public LiteralConstraint createFeatureLiteral(String name) {
197205
}
198206

199207
public GlobalAttribute createGlobalAttribute(String name) {
200-
GlobalAttribute toCreate = new GlobalAttribute(name, fmInConstruction);
208+
GlobalAttribute toCreate = elementFactory.createGlobalAttribute(name, fmInConstruction);
201209
if (toCreate.getType() == null) {
202210
System.err.println("Tried to reference " + name + " but attribute with that name does not exist");
203211
return null;

0 commit comments

Comments
 (0)