Skip to content

Commit 1c54dec

Browse files
committed
fix: review adjustments
1 parent c4ea78c commit 1c54dec

File tree

5 files changed

+20
-36
lines changed

5 files changed

+20
-36
lines changed

pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@
163163
<configuration>
164164
<!-- Sets the VM argument line used when unit tests are run. -->
165165
<!-- Suppress UnresolvedMavenProperty. -->
166-
<argLine>-Xms1g -Xmx2g --add-opens fr.insee.vtl.engine/fr.insee.vtl.engine.utils.dag=ALL-UNNAMED
167-
@{surefireArgLine}
168-
</argLine>
166+
<argLine>-Xms1g -Xmx2g @{surefireArgLine}</argLine>
169167
<useSystemClassLoader>false</useSystemClassLoader>
170168
<forkedProcessExitTimeoutInSeconds>180</forkedProcessExitTimeoutInSeconds>
171169
<forkCount>1</forkCount>

vtl-engine/src/main/java/fr/insee/vtl/engine/VtlSyntaxPreprocessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ public void checkForMultipleAssignments() throws VtlScriptException {
9393
.toList();
9494

9595
if (!multiProducedExceptions.isEmpty()) {
96-
throw VtlMultiErrorScriptException.usingTheFirstMainPositionExceptionAsCause(
97-
multiProducedExceptions);
96+
throw VtlMultiErrorScriptException.of(
97+
multiProducedExceptions.toArray(new VtlScriptException[] {}));
9898
}
9999
}
100100

vtl-engine/src/main/java/fr/insee/vtl/engine/utils/dag/DAGBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private VtlScriptException buildVTLScriptExceptionForCycles(List<Set<DAGStatemen
9696
startContext))
9797
.toList();
9898

99-
return VtlMultiErrorScriptException.usingTheFirstMainPositionExceptionAsCause(cycleExceptions);
99+
return VtlMultiErrorScriptException.of(cycleExceptions.toArray(new VtlScriptException[] {}));
100100
}
101101

102102
private String buildAssignmentChain(Set<DAGStatement> cycle) {
Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.insee.vtl.model;
22

33
import java.io.Serializable;
4+
import java.util.Comparator;
45

56
public interface Positioned {
67

@@ -10,26 +11,12 @@ record Position(Integer startLine, Integer endLine, Integer startColumn, Integer
1011
implements Serializable, Comparable<Position> {
1112
@Override
1213
public int compareTo(Position other) {
13-
if (this.startLine != null && other.startLine != null) {
14-
int cmp = this.startLine.compareTo(other.startLine);
15-
if (cmp != 0) return cmp;
16-
}
17-
18-
if (this.endLine != null && other.endLine != null) {
19-
int cmp = this.endLine.compareTo(other.endLine);
20-
if (cmp != 0) return cmp;
21-
}
22-
23-
if (this.startColumn != null && other.startColumn != null) {
24-
int cmp = this.startColumn.compareTo(other.startColumn);
25-
if (cmp != 0) return cmp;
26-
}
27-
28-
if (this.endColumn != null && other.endColumn != null) {
29-
return this.endColumn.compareTo(other.endColumn);
30-
}
31-
32-
return 0;
14+
return Comparator.nullsLast(
15+
Comparator.comparing(Position::startLine)
16+
.thenComparing(Position::endLine)
17+
.thenComparing(Position::startColumn)
18+
.thenComparing(Position::endColumn))
19+
.compare(this, other);
3320
}
3421
}
3522
}

vtl-model/src/main/java/fr/insee/vtl/model/exceptions/VtlMultiErrorScriptException.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ public class VtlMultiErrorScriptException extends VtlScriptException {
1919
* @param main The main-Exception that is getting the role of being the Exception cause.
2020
* @param others The other VtlScriptExceptions, that also occurred.
2121
*/
22-
public VtlMultiErrorScriptException(
23-
VtlScriptException main, Collection<? extends VtlScriptException> others) {
22+
public VtlMultiErrorScriptException(VtlScriptException main, VtlScriptException... others) {
2423
super(main, main.getPosition());
25-
this.others = others;
24+
this.others = List.of(others);
2625
}
2726

2827
/**
@@ -34,24 +33,24 @@ public VtlMultiErrorScriptException(
3433
* VtlMultiErrorScriptException using the one with first Position as cause
3534
* @throws IllegalArgumentException when the occurred Exceptions are empty
3635
*/
37-
public static VtlScriptException usingTheFirstMainPositionExceptionAsCause(
38-
List<? extends VtlScriptException> allOccurred) {
39-
if (allOccurred.size() == 1) {
40-
return allOccurred.get(0);
36+
public static VtlScriptException of(VtlScriptException... allOccurred) {
37+
if (allOccurred.length == 1) {
38+
return allOccurred[0];
4139
}
4240

4341
final VtlScriptException firstOccurred =
44-
allOccurred.stream()
42+
Arrays.stream(allOccurred)
4543
.min(Comparator.comparing(VtlScriptException::getPosition))
4644
.orElseThrow(
4745
() ->
4846
new IllegalArgumentException(
4947
"Can not build a VTLMultiErrorScriptException without any VTLScriptException as cause"));
5048

51-
Set<VtlScriptException> rest = new HashSet<>(allOccurred);
49+
Set<VtlScriptException> rest = new HashSet<>(Arrays.asList(allOccurred));
5250
rest.remove(firstOccurred);
5351

54-
return new VtlMultiErrorScriptException(firstOccurred, rest);
52+
return new VtlMultiErrorScriptException(
53+
firstOccurred, rest.toArray(new VtlScriptException[] {}));
5554
}
5655

5756
/**

0 commit comments

Comments
 (0)