Skip to content

Commit af12dd3

Browse files
committed
make jdk8 compatible
1 parent 8032650 commit af12dd3

File tree

5 files changed

+99
-24
lines changed

5 files changed

+99
-24
lines changed

dlx/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group 'de.famiru.dlx'
10-
version '0.6.1'
10+
version '0.6.1-jdk8-SNAPSHOT'
1111

1212
repositories {
1313
mavenCentral()
@@ -32,7 +32,7 @@ dependencies {
3232

3333
java {
3434
toolchain {
35-
languageVersion = JavaLanguageVersion.of(17)
35+
languageVersion = JavaLanguageVersion.of(8)
3636
}
3737

3838
withJavadocJar()

dlx/src/main/java/de/famiru/dlx/Dlx.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ solutionsFound, mapToList(updates), mapToList(visitedNodes)
257257
}
258258

259259
private List<Long> mapToList(long[] array) {
260-
return Arrays.stream(array).boxed().toList();
260+
return Arrays.stream(array).boxed().collect(Collectors.toList());
261261
}
262262

263263
private enum State {

dlx/src/main/java/de/famiru/dlx/MatrixEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public T getData() {
7171

7272
@Override
7373
public String toString() {
74-
return Objects.requireNonNullElse(data, "Head").toString();
74+
return data != null ? data.toString() : "Head";
7575
}
7676

7777
int coverColumn() {
Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,76 @@
11
package de.famiru.dlx;
22

33
import java.util.List;
4+
import java.util.Objects;
45

5-
public record Stats(int numberOfChoices, int numberOfConstraints, int numberOfElements,
6-
int numberOfSolutions, List<Long> numberOfUpdates, List<Long> numberOfVisitedNodes) {
6+
public final class Stats {
7+
private final int numberOfChoices;
8+
private final int numberOfConstraints;
9+
private final int numberOfElements;
10+
private final int numberOfSolutions;
11+
private final List<Long> numberOfUpdates;
12+
private final List<Long> numberOfVisitedNodes;
13+
14+
public Stats(int numberOfChoices, int numberOfConstraints, int numberOfElements,
15+
int numberOfSolutions, List<Long> numberOfUpdates, List<Long> numberOfVisitedNodes) {
16+
this.numberOfChoices = numberOfChoices;
17+
this.numberOfConstraints = numberOfConstraints;
18+
this.numberOfElements = numberOfElements;
19+
this.numberOfSolutions = numberOfSolutions;
20+
this.numberOfUpdates = numberOfUpdates;
21+
this.numberOfVisitedNodes = numberOfVisitedNodes;
22+
}
23+
24+
public int numberOfChoices() {
25+
return numberOfChoices;
26+
}
27+
28+
public int numberOfConstraints() {
29+
return numberOfConstraints;
30+
}
31+
32+
public int numberOfElements() {
33+
return numberOfElements;
34+
}
35+
36+
public int numberOfSolutions() {
37+
return numberOfSolutions;
38+
}
39+
40+
public List<Long> numberOfUpdates() {
41+
return numberOfUpdates;
42+
}
43+
44+
public List<Long> numberOfVisitedNodes() {
45+
return numberOfVisitedNodes;
46+
}
47+
48+
@Override
49+
public boolean equals(Object obj) {
50+
if (obj == this) return true;
51+
if (obj == null || obj.getClass() != this.getClass()) return false;
52+
Stats that = (Stats) obj;
53+
return this.numberOfChoices == that.numberOfChoices &&
54+
this.numberOfConstraints == that.numberOfConstraints &&
55+
this.numberOfElements == that.numberOfElements &&
56+
this.numberOfSolutions == that.numberOfSolutions &&
57+
Objects.equals(this.numberOfUpdates, that.numberOfUpdates) &&
58+
Objects.equals(this.numberOfVisitedNodes, that.numberOfVisitedNodes);
59+
}
60+
61+
@Override
62+
public int hashCode() {
63+
return Objects.hash(numberOfChoices, numberOfConstraints, numberOfElements, numberOfSolutions, numberOfUpdates, numberOfVisitedNodes);
64+
}
65+
66+
@Override
67+
public String toString() {
68+
return "Stats[" +
69+
"numberOfChoices=" + numberOfChoices + ", " +
70+
"numberOfConstraints=" + numberOfConstraints + ", " +
71+
"numberOfElements=" + numberOfElements + ", " +
72+
"numberOfSolutions=" + numberOfSolutions + ", " +
73+
"numberOfUpdates=" + numberOfUpdates + ", " +
74+
"numberOfVisitedNodes=" + numberOfVisitedNodes + ']';
75+
}
776
}

dlx/src/test/java/de/famiru/dlx/DlxTest.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
import org.assertj.core.api.InstanceOfAssertFactories;
44
import org.junit.jupiter.api.Test;
55

6+
import java.util.Arrays;
67
import java.util.List;
8+
import java.util.stream.Collectors;
79

810
import static org.assertj.core.api.Assertions.assertThat;
911

1012
class DlxTest {
1113
@Test
1214
void matrixFromFigure3ofPaper_solvedCorrectly() {
1315
Dlx<String> dlx = new Dlx<>(7, 0, 10, false, Integer.MAX_VALUE);
14-
dlx.addChoice("C E F", List.of(2, 4, 5));
15-
dlx.addChoice("A D G", List.of(0, 3, 6));
16-
dlx.addChoice("B C F", List.of(1, 2, 5));
17-
dlx.addChoice("A D", List.of(0, 3));
18-
dlx.addChoice("B G", List.of(1, 6));
19-
dlx.addChoice("D E G", List.of(3, 4, 6));
16+
dlx.addChoice("C E F", listOf(2, 4, 5));
17+
dlx.addChoice("A D G", listOf(0, 3, 6));
18+
dlx.addChoice("B C F", listOf(1, 2, 5));
19+
dlx.addChoice("A D", listOf(0, 3));
20+
dlx.addChoice("B G", listOf(1, 6));
21+
dlx.addChoice("D E G", listOf(3, 4, 6));
2022

2123
List<List<String>> solutions = dlx.solve();
2224

@@ -29,12 +31,12 @@ void matrixFromFigure3ofPaper_solvedCorrectly() {
2931
@Test
3032
void matrixWithSecondaryConstraint_constraintNotFulfillable_solvedCorrectly() {
3133
Dlx<String> dlx = new Dlx<>(7, 1, 10, false, Integer.MAX_VALUE);
32-
dlx.addChoice("C E F", List.of(2, 4, 5));
33-
dlx.addChoice("A D G H", List.of(0, 3, 6, 7));
34-
dlx.addChoice("B C F", List.of(1, 2, 5));
35-
dlx.addChoice("A D", List.of(0, 3));
36-
dlx.addChoice("B G", List.of(1, 6));
37-
dlx.addChoice("D E G", List.of(3, 4, 6));
34+
dlx.addChoice("C E F", listOf(2, 4, 5));
35+
dlx.addChoice("A D G H", listOf(0, 3, 6, 7));
36+
dlx.addChoice("B C F", listOf(1, 2, 5));
37+
dlx.addChoice("A D", listOf(0, 3));
38+
dlx.addChoice("B G", listOf(1, 6));
39+
dlx.addChoice("D E G", listOf(3, 4, 6));
3840

3941
List<List<String>> solutions = dlx.solve();
4042

@@ -47,12 +49,12 @@ void matrixWithSecondaryConstraint_constraintNotFulfillable_solvedCorrectly() {
4749
@Test
4850
void matrixWithSecondaryConstraint_constraintFulfillable_solvedCorrectly() {
4951
Dlx<String> dlx = new Dlx<>(7, 1, 10, false, Integer.MAX_VALUE);
50-
dlx.addChoice("C E F", List.of(2, 4, 5));
51-
dlx.addChoice("A D G", List.of(0, 3, 6));
52-
dlx.addChoice("B C F", List.of(1, 2, 5));
53-
dlx.addChoice("A D H", List.of(0, 3, 7));
54-
dlx.addChoice("B G", List.of(1, 6));
55-
dlx.addChoice("D E G", List.of(3, 4, 6));
52+
dlx.addChoice("C E F", listOf(2, 4, 5));
53+
dlx.addChoice("A D G", listOf(0, 3, 6));
54+
dlx.addChoice("B C F", listOf(1, 2, 5));
55+
dlx.addChoice("A D H", listOf(0, 3, 7));
56+
dlx.addChoice("B G", listOf(1, 6));
57+
dlx.addChoice("D E G", listOf(3, 4, 6));
5658

5759
List<List<String>> solutions = dlx.solve();
5860

@@ -61,4 +63,8 @@ void matrixWithSecondaryConstraint_constraintFulfillable_solvedCorrectly() {
6163
.first(InstanceOfAssertFactories.list(String.class))
6264
.containsExactlyInAnyOrder("A D H", "C E F", "B G");
6365
}
66+
67+
private static List<Integer> listOf(int... args) {
68+
return Arrays.stream(args).boxed().collect(Collectors.toList());
69+
}
6470
}

0 commit comments

Comments
 (0)