Skip to content

Commit 55e7ba7

Browse files
committed
chore: java 25
1 parent 6ad17a1 commit 55e7ba7

44 files changed

Lines changed: 2041 additions & 391 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/codacy-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ jobs:
2121
steps:
2222
# Checkout the repository to the GitHub Actions runner
2323
- name: Checkout code
24-
uses: actions/checkout@v2
24+
uses: actions/checkout@v5
2525

26-
- name: Set up JDK 24
27-
uses: actions/setup-java@v3
26+
- name: Set up JDK 25
27+
uses: actions/setup-java@v5
2828
with:
29-
java-version: '24'
29+
java-version: '25'
3030
distribution: 'zulu'
3131
cache: maven
3232
- name: Build with Maven

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ jobs:
2929
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
3030

3131
steps:
32-
- name: Setup Java JDK 24
33-
uses: actions/setup-java@v3
32+
- name: Setup Java JDK 25
33+
uses: actions/setup-java@v5
3434
with:
35-
java-version: 24
35+
java-version: 25
3636
distribution: 'zulu'
3737

3838
- name: Checkout repository
39-
uses: actions/checkout@v4
39+
uses: actions/checkout@v5
4040
with:
4141
# We must fetch at least the immediate parents so that if this is
4242
# a pull request then we can checkout the head.

.github/workflows/maven.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ jobs:
1919
runs-on: ubuntu-latest
2020

2121
steps:
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v5
2323
- name: Install libncurses5
2424
run: sudo apt-get install -y libncurses5
25-
- name: Set up JDK 24
26-
uses: actions/setup-java@v3
25+
- name: Set up JDK 25
26+
uses: actions/setup-java@v5
2727
with:
28-
java-version: '24'
28+
java-version: '25'
2929
distribution: 'zulu'
3030
cache: maven
3131
- name: Build with Maven

adventofcode/pom.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14-
<java.version>24</java.version>
15-
<compiler.version>3.11.0</compiler.version>
16-
<surefire.version>3.1.2</surefire.version>
17-
<spottless.version>2.43.0</spottless.version>
14+
<java.version>25</java.version>
15+
<compiler.version>3.14.1</compiler.version>
16+
<surefire.version>3.5.4</surefire.version>
17+
<spottless.version>3.0.0</spottless.version>
1818
</properties>
1919

2020
<build>
@@ -30,8 +30,7 @@
3030
org.ck.codechallengelib.annotation.ReadmeGenerator
3131
</annotationProcessor>
3232
</annotationProcessors>
33-
<source>${java.version}</source>
34-
<target>${java.version}</target>
33+
<release>${java.version}</release>
3534
</configuration>
3635
</plugin>
3736
<plugin>

adventofcode/src/main/java/org/ck/adventofcode/year2015/Day01.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.Scanner;
44
import java.util.function.IntPredicate;
55
import java.util.function.ToIntFunction;
6-
import java.util.stream.Gatherer;
6+
import java.util.stream.Collector;
77
import org.ck.adventofcode.util.AOCSolution;
88
import org.ck.codechallengelib.annotation.Solution;
99

@@ -30,22 +30,26 @@ protected void runPartTwo(final Scanner in) {
3030

3131
private void run(
3232
final Scanner in,
33-
final IntPredicate getBreakCondition,
33+
final IntPredicate continueCondition,
3434
final ToIntFunction<State> getResult) {
35-
in.nextLine()
36-
.chars()
37-
.boxed()
38-
.gather(
39-
Gatherer.ofSequential(
40-
() -> new State(0, 1),
41-
(state, element, _) -> {
42-
state.floor += element == '(' ? 1 : -1;
43-
state.position += 1;
44-
45-
return getBreakCondition.test(state.floor);
46-
},
47-
(state, downstream) -> downstream.push(getResult.applyAsInt(state))))
48-
.forEach(this::print);
35+
final State state = new State(0, 1);
36+
37+
print(
38+
in.nextLine()
39+
.chars()
40+
.boxed()
41+
.takeWhile(_ -> continueCondition.test(state.floor))
42+
.collect(
43+
Collector.of(
44+
() -> state,
45+
Day01::moveElevator,
46+
(_, _) -> null,
47+
_ -> getResult.applyAsInt(state))));
48+
}
49+
50+
private static void moveElevator(final State state, final int element) {
51+
state.floor += element == '(' ? 1 : -1;
52+
state.position += 1;
4953
}
5054

5155
private static final class State {

adventofcode/src/main/java/org/ck/adventofcode/year2015/Day02.java

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Collections;
55
import java.util.List;
66
import java.util.Scanner;
7+
import java.util.function.ToIntFunction;
78
import org.ck.adventofcode.util.AOCSolution;
89
import org.ck.codechallengelib.annotation.Solution;
910

@@ -20,48 +21,51 @@
2021
public class Day02 extends AOCSolution {
2122
@Override
2223
protected void runPartOne(final Scanner in) {
23-
run(
24-
in,
25-
(l, w, h) -> {
26-
final int lw = l * w;
27-
final int lh = l * h;
28-
final int wh = w * h;
29-
30-
final int min = Math.min(Math.min(lw, lh), wh);
31-
32-
return 2 * lw + 2 * lh + 2 * wh + min;
33-
});
24+
run(in, Day02::calculateWrappingNeeded);
3425
}
3526

3627
@Override
3728
protected void runPartTwo(final Scanner in) {
38-
run(
39-
in,
40-
(l, w, h) -> {
41-
final List<Integer> lengths = Arrays.asList(l, w, h);
42-
Collections.sort(lengths);
29+
run(in, Day02::calculateRibbonNeeded);
30+
}
4331

44-
final int s = lengths.get(0);
45-
final int m = lengths.get(1);
32+
private void run(final Scanner in, final MaterialNeedCalculator materialNeedCalculator) {
33+
int needed =
34+
in.tokens()
35+
.map(line -> line.split("x"))
36+
.mapToInt(calculateMaterialNeeded(materialNeedCalculator))
37+
.sum();
4638

47-
return 2 * s + 2 * m + l * w * h;
48-
});
39+
print(needed);
4940
}
5041

51-
private void run(final Scanner in, final MaterialNeedCalculator materialNeedCalculator) {
52-
int needed = 0;
42+
private static int calculateWrappingNeeded(final int l, final int w, final int h) {
43+
final int lw = l * w;
44+
final int lh = l * h;
45+
final int wh = w * h;
5346

54-
while (in.hasNextLine()) {
55-
final String[] dimensions = in.nextLine().split("x");
47+
final int min = Math.min(Math.min(lw, lh), wh);
5648

57-
final int l = Integer.parseInt(dimensions[0]);
58-
final int w = Integer.parseInt(dimensions[1]);
59-
final int h = Integer.parseInt(dimensions[2]);
49+
return 2 * lw + 2 * lh + 2 * wh + min;
50+
}
6051

61-
needed += materialNeedCalculator.get(l, w, h);
62-
}
52+
private static int calculateRibbonNeeded(final int l, final int w, final int h) {
53+
final List<Integer> lengths = Arrays.asList(l, w, h);
54+
Collections.sort(lengths);
6355

64-
print(needed);
56+
final int s = lengths.get(0);
57+
final int m = lengths.get(1);
58+
59+
return 2 * s + 2 * m + l * w * h;
60+
}
61+
62+
private static ToIntFunction<String[]> calculateMaterialNeeded(
63+
final MaterialNeedCalculator materialNeedCalculator) {
64+
return dimensions ->
65+
materialNeedCalculator.get(
66+
Integer.parseInt(dimensions[0]),
67+
Integer.parseInt(dimensions[1]),
68+
Integer.parseInt(dimensions[2]));
6569
}
6670

6771
private interface MaterialNeedCalculator {

adventofcode/src/main/java/org/ck/adventofcode/year2015/Day03.java

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

33
import java.util.*;
44
import java.util.function.Function;
5+
import java.util.stream.Gatherer;
56
import org.ck.adventofcode.util.AOCSolution;
67
import org.ck.codechallengelib.annotation.Solution;
78

@@ -18,48 +19,45 @@
1819
public class Day03 extends AOCSolution {
1920
@Override
2021
protected void runPartOne(final Scanner in) {
21-
run(in, List::of);
22+
run(in, line -> List.of(line.chars().boxed().toList()));
2223
}
2324

2425
@Override
2526
protected void runPartTwo(final Scanner in) {
2627
run(
2728
in,
28-
line -> {
29-
final List<String> commands = new ArrayList<>();
29+
line ->
30+
line.chars()
31+
.boxed()
32+
.<List<Integer>>gather(
33+
Gatherer.ofSequential(
34+
State::new,
35+
(state, element, _) -> {
36+
if (state.santa.size() == state.robo.size()) {
37+
state.santa.add(element);
38+
} else {
39+
state.robo.add(element);
40+
}
3041

31-
final StringBuilder santa = new StringBuilder();
32-
final StringBuilder robo = new StringBuilder();
33-
34-
int index = 0;
35-
for (char command : line.toCharArray()) {
36-
if (index % 2 == 0) {
37-
santa.append(command);
38-
} else {
39-
robo.append(command);
40-
}
41-
42-
++index;
43-
}
44-
45-
commands.add(santa.toString());
46-
commands.add(robo.toString());
47-
48-
return commands;
49-
});
42+
return true;
43+
},
44+
(state, downstream) -> {
45+
downstream.push(state.santa);
46+
downstream.push(state.robo);
47+
}))
48+
.toList());
5049
}
5150

52-
private void run(final Scanner in, final Function<String, List<String>> getCommands) {
53-
final List<String> commands = getCommands.apply(in.nextLine());
54-
51+
private void run(final Scanner in, final Function<String, List<List<Integer>>> getCommands) {
5552
final Set<Point> houses = new HashSet<>();
5653

57-
for (String commandLine : commands) {
54+
for (List<Integer> commandLine : getCommands.apply(in.nextLine())) {
5855
int x = 0;
5956
int y = 0;
6057

6158
houses.add(new Point(x, y));
62-
for (char command : commandLine.toCharArray()) {
59+
60+
for (int command : commandLine) {
6361
switch (command) {
6462
case '^' -> ++y;
6563
case '>' -> ++x;
@@ -75,5 +73,10 @@ private void run(final Scanner in, final Function<String, List<String>> getComma
7573
print(houses.size());
7674
}
7775

76+
private static final class State {
77+
private final List<Integer> santa = new ArrayList<>();
78+
private final List<Integer> robo = new ArrayList<>();
79+
}
80+
7881
private record Point(int x, int y) {}
7982
}

adventofcode/src/main/java/org/ck/adventofcode/year2021/day18/Part1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void main(String[] args) {
3030
checkAndApplyRules(root);
3131
}
3232

33-
System.err.println(root.toString());
33+
// System.err.println(root.toString());
3434
System.out.println(root.getMagnitude());
3535
}
3636
}

adventofcode/src/main/java/org/ck/adventofcode/year2023/Day20.java

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

33
import java.util.*;
44
import java.util.function.ToLongFunction;
5-
import java.util.stream.Collectors;
65
import org.ck.adventofcode.util.AOCSolution;
76
import org.ck.codechallengelib.annotation.Solution;
87

@@ -48,11 +47,11 @@ protected void runPartTwo(final Scanner in) {
4847
run(
4948
in,
5049
(modules, cycles, rxLow) -> {
51-
System.err.println(
52-
modules.stream()
53-
.filter(module -> !module.isDefault())
54-
.map(Module::getName)
55-
.collect(Collectors.joining(", ")));
50+
// System.err.println(
51+
// modules.stream()
52+
// .filter(module -> !module.isDefault())
53+
// .map(Module::getName)
54+
// .collect(Collectors.joining(", ")));
5655

5756
return rxLow != 1;
5857
},

adventofcode/src/test/java/org/ck/adventofcode/util/BaseAOCTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
public abstract class BaseAOCTest extends BaseTest {
99
@Test
10-
void testPartOne() throws Exception {
10+
protected void testPartOne() throws Exception {
1111
final AOCSolution solution = getSolution();
1212
runRealInputTest(solution, solution::partOne, "01");
1313
}
1414

1515
@Test
16-
void testPartTwo() throws Exception {
16+
protected void testPartTwo() throws Exception {
1717
final AOCSolution solution = getSolution();
1818
runRealInputTest(solution, solution::partTwo, "02");
1919
}

0 commit comments

Comments
 (0)