Skip to content
This repository was archived by the owner on May 23, 2022. It is now read-only.

Commit 8f2621c

Browse files
committed
Uses checkElementIndex
1 parent f5cf2df commit 8f2621c

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

.idea/misc.xml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/main/java/at/tugraz/ist/ase/knowledgebases/core/Constraint.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import java.util.List;
1919
import java.util.Objects;
2020

21+
import static com.google.common.base.Preconditions.checkArgument;
22+
import static com.google.common.base.Preconditions.checkElementIndex;
23+
2124
@Getter
2225
@Slf4j
2326
public class Constraint {
@@ -33,9 +36,13 @@ public Constraint(@NonNull String constraint) {
3336
log.trace("{}Created Constraint [cstr={}]", LoggerUtils.tab, constraint);
3437
}
3538

36-
public void addChocoConstraints(Model model, int startIdx, int endIdx, boolean hasNegativeConstraints) {
39+
public void addChocoConstraints(@NonNull Model model, int startIdx, int endIdx, boolean hasNegativeConstraints) {
3740
org.chocosolver.solver.constraints.Constraint[] constraints = model.getCstrs();
3841

42+
checkElementIndex(startIdx, constraints.length, "startIdx must be within the range of constraints");
43+
checkElementIndex(endIdx, constraints.length, "endIdx must be within the range of constraints");
44+
checkArgument(startIdx <= endIdx, "startIdx must be <= endIdx");
45+
3946
if (hasNegativeConstraints) {
4047
endIdx = endIdx - 2;
4148
} else {

src/main/java/at/tugraz/ist/ase/knowledgebases/core/KB.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.stream.IntStream;
2020

2121
import static com.google.common.base.Preconditions.checkArgument;
22+
import static com.google.common.base.Preconditions.checkElementIndex;
2223

2324
@Getter
2425
@ToString
@@ -75,7 +76,7 @@ public int getNumVariables() {
7576
}
7677

7778
public Variable getVariable(int index) {
78-
checkArgument(index >= 0 && index < variableList.size(), "Index out of bounds");
79+
checkElementIndex(index, variableList.size(), "Index out of bounds");
7980

8081
return variableList.get(index);
8182
}
@@ -116,7 +117,7 @@ public int getNumConstraints() {
116117
}
117118

118119
public Constraint getConstraint(int index) {
119-
checkArgument(index >= 0 && index < constraintList.size(), "Index out of bounds");
120+
checkElementIndex(index, constraintList.size(), "Index out of bounds");
120121

121122
return constraintList.get(index);
122123
}

0 commit comments

Comments
 (0)