Skip to content

Commit ccd4b14

Browse files
author
Julia Pham
committed
fix: throw ParseError in getLeft/getRight, also added setLeft/setRight for backwards compatibility and deleted the .DS files
1 parent d5155b7 commit ccd4b14

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

.DS_Store

-6 KB
Binary file not shown.

src/.DS_Store

-6 KB
Binary file not shown.

src/main/.DS_Store

-6 KB
Binary file not shown.

src/main/java/.DS_Store

-6 KB
Binary file not shown.

src/main/java/de/.DS_Store

-6 KB
Binary file not shown.

src/main/java/de/vill/model/constraint/AndConstraint.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package de.vill.model.constraint;
22

3+
import de.vill.model.building.AutomaticBrackets;
34
import de.vill.model.building.VariableReference;
45

6+
import de.vill.exception.ParseError;
7+
58
import java.util.ArrayList;
69
import java.util.Arrays;
710
import java.util.List;
@@ -10,7 +13,6 @@
1013

1114
public class AndConstraint extends Constraint {
1215

13-
//List of children
1416
private final List<Constraint> children = new ArrayList<>();
1517

1618
public AndConstraint(Constraint... constraints) {
@@ -28,7 +30,7 @@ public AndConstraint(Constraint left, Constraint right) {
2830

2931
public Constraint getLeft() {
3032
if (children.isEmpty()){
31-
return null;
33+
throw new ParseError("Left child can not be returned because there are no children.");
3234
}
3335
else{
3436
return children.get(0);
@@ -37,7 +39,7 @@ public Constraint getLeft() {
3739

3840
public Constraint getRight() {
3941
if (children.isEmpty() || children.size() < 2){
40-
return null;
42+
throw new ParseError("Right child can not be returned because there are less than two children.");;
4143
}
4244
else{
4345
return children.get(children.size() - 1);
@@ -48,13 +50,32 @@ public List<Constraint> getChildren() {
4850
return children;
4951
}
5052

53+
public void setLeft(Constraint left) {
54+
if (children.isEmpty()) {
55+
children.add(left);
56+
}
57+
else {
58+
children.set(0, left);
59+
}
60+
}
61+
62+
public void setRight(Constraint right){
63+
if (children.size() < 2) {
64+
if (children.size() < 1) {
65+
children.add(null);
66+
}
67+
children.add(right);
68+
}
69+
else {
70+
children.set(children.size() - 1, right);
71+
}
72+
}
73+
5174
@Override
5275
public String toString(boolean withSubmodels, String currentAlias) {
53-
return
54-
// Constraint-Stream - jeder constraint in einen String umgewandelt und mit einem & verknüpft
55-
children.stream()
56-
.map(c -> c.toString(withSubmodels, currentAlias))
57-
.collect(Collectors.joining(" & "));
76+
return children.stream()
77+
.map(c -> AutomaticBrackets.enforceConstraintBracketsIfNecessary(this, c, withSubmodels, currentAlias))
78+
.collect(Collectors.joining(" & "));
5879
}
5980

6081
@Override

src/main/java/de/vill/model/constraint/OrConstraint.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.vill.model.constraint;
22

3+
import de.vill.exception.ParseError;
4+
import de.vill.model.building.AutomaticBrackets;
35
import de.vill.model.building.VariableReference;
46

57
import java.util.ArrayList;
@@ -27,7 +29,7 @@ public OrConstraint(Constraint left, Constraint right) {
2729

2830
public Constraint getLeft() {
2931
if (children.isEmpty()){
30-
return null;
32+
throw new ParseError("Left child can not be returned because there are no children.");
3133
}
3234
else{
3335
return children.get(0);
@@ -36,7 +38,7 @@ public Constraint getLeft() {
3638

3739
public Constraint getRight() {
3840
if (children.isEmpty() || children.size() < 2){
39-
return null;
41+
throw new ParseError("RIght child can not be returned because there are less than two children.");
4042
}
4143
else{
4244
return children.get(children.size() - 1);
@@ -47,13 +49,32 @@ public List<Constraint> getChildren() {
4749
return children;
4850
}
4951

52+
public void setLeft(Constraint left) {
53+
if (children.isEmpty()) {
54+
children.add(left);
55+
}
56+
else {
57+
children.set(0, left);
58+
}
59+
}
60+
61+
public void setRight(Constraint right){
62+
if (children.size() < 2) {
63+
if (children.size() < 1) {
64+
children.add(null);
65+
}
66+
children.add(right);
67+
}
68+
else {
69+
children.set(children.size() - 1, right);
70+
}
71+
}
72+
5073
@Override
5174
public String toString(boolean withSubmodels, String currentAlias) {
52-
return
53-
// Constraint-Stream - jeder constraint in einen String umgewandelt und mit einem & verknüpft
54-
children.stream()
55-
.map(c -> c.toString(withSubmodels, currentAlias))
56-
.collect(Collectors.joining(" | "));
75+
return children.stream()
76+
.map(c -> AutomaticBrackets.enforceConstraintBracketsIfNecessary(this, c, withSubmodels, currentAlias))
77+
.collect(Collectors.joining(" | "));
5778
}
5879

5980
@Override

0 commit comments

Comments
 (0)