Skip to content

Commit

Permalink
Updating to use SNAPSHOT version of PMD plugin to build with Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
zodac committed Oct 5, 2023
1 parent b0167b1 commit dd59bb6
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 111 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "advent-of-code-inputs"]
path = advent-of-code-inputs
url = https://github.com/zodac/advent-of-code-inputs.git
path = advent-of-code-inputs
url = https://github.com/zodac/advent-of-code-inputs.git
2 changes: 0 additions & 2 deletions 2015/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<!-- Does not support JDK 21
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>
-->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
Expand Down
12 changes: 3 additions & 9 deletions 2015/src/main/java/me/zodac/advent/Day05.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,9 @@ public static long countValidStringsPartOne(final Collection<String> strings) {
}

private static boolean isValidForPartOne(final String input) {
if (StringUtils.containsAny(input, INVALID_SUBSTRINGS)) {
return false;
}

if (StringUtils.countVowels(input) < MINIMUM_NUMBER_OF_VOWELS_REQUIRED) {
return false;
}

return StringUtils.hasRepeatedCharacterInOrder(input);
return !StringUtils.containsAny(input, INVALID_SUBSTRINGS)
&& StringUtils.countVowels(input) >= MINIMUM_NUMBER_OF_VOWELS_REQUIRED
&& StringUtils.hasRepeatedCharacterInOrder(input);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private BattleRound(final MagePlayer player, final MageBoss boss, final List<Act
continue;
}

if (activeSpells.stream().anyMatch(activeSpell -> activeSpell.spell() == spell)) {
if (activeSpells.stream().anyMatch(activeSpell -> spell.equals(activeSpell.spell()))) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public boolean equals(final Object obj) {
return true;
}

if (!(obj instanceof Equipment equipment)) {
if (!(obj instanceof final Equipment equipment)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion 2015/src/test/java/me/zodac/advent/Day15Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Day15Test {

@Disabled("Solution only works with 4 inputs, will fail with 2 from the example")
void example() {
// TODO
// TODO: Build this some day
}

@Test
Expand Down
2 changes: 0 additions & 2 deletions 2018/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<!-- Does not support JDK 21
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>
-->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
Expand Down
2 changes: 0 additions & 2 deletions 2021/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<!-- Does not support JDK 21
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>
-->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
Expand Down
2 changes: 0 additions & 2 deletions 2022/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<!-- Does not support JDK 21
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>
-->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
Expand Down
2 changes: 0 additions & 2 deletions common-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<!-- Does not support JDK 21
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>
-->
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
Expand Down
38 changes: 8 additions & 30 deletions common-utils/src/main/java/me/zodac/advent/json/JsonInteger.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,24 @@

/**
* Implementation of {@link JsonElement} defining a single {@code int} value.
*
* @param value the input {@link String}
*/
public final class JsonInteger implements JsonElement {

private final int value;

private JsonInteger(final int value) {
this.value = value;
}
public record JsonInteger(int value) implements JsonElement {

/**
* Parses the input {@link String} as an {@code int} and creates a {@link JsonInteger}.
*
* @param input the input {@link String}
* @param value the input {@link String}
* @return the created {@link JsonInteger}
* @throws IllegalArgumentException thrown if the input {@link String} cannot be parses as an {@code int}
*/
public static JsonInteger create(final String input) {
if (!StringUtils.isInteger(input)) {
throw new IllegalArgumentException(String.format("Cannot parse input '%s' as %s", input, JsonInteger.class.getSimpleName()));
public static JsonInteger create(final String value) {
if (!StringUtils.isInteger(value)) {
throw new IllegalArgumentException(String.format("Cannot parse input '%s' as %s", value, JsonInteger.class.getSimpleName()));
}

return new JsonInteger(Integer.parseInt(input));
return new JsonInteger(Integer.parseInt(value));
}

@Override
Expand All @@ -58,22 +54,4 @@ public int compareTo(final JsonElement o) {

throw new IllegalArgumentException(String.format("Cannot compare %s to %s", JsonInteger.class.getSimpleName(), o.getClass().getSimpleName()));
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}

if (!(obj instanceof JsonInteger other)) {
return false;
}

return value == other.value;
}

@Override
public int hashCode() {
return value;
}
}
33 changes: 4 additions & 29 deletions common-utils/src/main/java/me/zodac/advent/json/JsonList.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,14 @@

package me.zodac.advent.json;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
* Implementation of {@link JsonElement} defining a {@link List} of {@link JsonElement}s.
*
* @param elements the {@link JsonElement}s
*/
public final class JsonList implements JsonElement {

private final List<JsonElement> elements;

private JsonList(final Collection<JsonElement> elements) {
this.elements = new ArrayList<>(elements);
}
public record JsonList(List<JsonElement> elements) implements JsonElement {

/**
* Creates a {@link JsonList} from the provided {@link JsonElement}s.
Expand All @@ -55,7 +48,7 @@ public static JsonList create(final JsonElement element) {

@Override
public int compareTo(final JsonElement o) {
if (o instanceof JsonList other) {
if (o instanceof final JsonList other) {
final int thisSize = elements.size();
final int otherSize = other.elements.size();
final int maxSize = Math.max(thisSize, otherSize);
Expand Down Expand Up @@ -85,22 +78,4 @@ public int compareTo(final JsonElement o) {

throw new IllegalArgumentException(String.format("Cannot compare %s to %s", JsonList.class.getSimpleName(), o.getClass().getSimpleName()));
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}

if (!(obj instanceof JsonList other)) {
return false;
}

return Objects.equals(elements, other.elements);
}

@Override
public int hashCode() {
return Objects.hash(elements);
}
}
18 changes: 9 additions & 9 deletions common-utils/src/main/java/me/zodac/advent/pojo/tuple/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@
*
* @param first the first object
* @param second the second object
* @param <E1> type of first value
* @param <E2> type of second value
* @param <A> type of first value
* @param <B> type of second value
*/
public record Pair<E1, E2>(E1 first, E2 second) {
public record Pair<A, B>(A first, B second) {

/**
* Create a {@link Pair} with two values.
*
* @param first the first value
* @param second the second value
* @param <E1> type of first value
* @param <E2> type of second value
* @param <A> type of first value
* @param <B> type of second value
* @return the created {@link Pair}
*/
public static <E1, E2> Pair<E1, E2> of(final E1 first, final E2 second) {
public static <A, B> Pair<A, B> of(final A first, final B second) {
return new Pair<>(first, second);
}

/**
* Create a {@link Pair} with one values, with the second value set to {@code null}.
*
* @param first the first value
* @param <E1> type of first value
* @param <E2> type of second value
* @param <A> type of first value
* @param <B> type of second value
* @return the created {@link Pair}
*/
public static <E1, E2> Pair<E1, E2> withNull(final E1 first) {
public static <A, B> Pair<A, B> withNull(final A first) {
return of(first, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@
* @param first the first object
* @param second the second object
* @param third the third object
* @param <E1> type of first value
* @param <E2> type of second value
* @param <E3> type of second value
* @param <A> type of first value
* @param <B> type of second value
* @param <C> type of second value
*/
public record Triple<E1, E2, E3>(E1 first, E2 second, E3 third) {
public record Triple<A, B, C>(A first, B second, C third) {

/**
* Create a {@link Triple} with three values.
*
* @param first the first value
* @param second the second value
* @param third the third value
* @param <E1> type of first value
* @param <E2> type of second value
* @param <E3> type of third value
* @param <A> type of first value
* @param <B> type of second value
* @param <C> type of third value
* @return the created {@link Triple}
*/
public static <E1, E2, E3> Triple<E1, E2, E3> of(final E1 first, final E2 second, final E3 third) {
public static <A, B, C> Triple<A, B, C> of(final A first, final B second, final C third) {
return new Triple<>(first, second, third);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
Expand Down Expand Up @@ -58,7 +59,7 @@ public static long findShortestDistance(
final Map<Point, Long> distanceByNeighbourNode = new HashMap<>();
distanceByNeighbourNode.put(startPoint, START_NODE_DISTANCE);

final LinkedList<Point> neighbourNodes = new LinkedList<>();
final Deque<Point> neighbourNodes = new LinkedList<>();
neighbourNodes.add(startPoint);

final Map<Point, Point> neighbourNodeByParentNode = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,12 @@ public static boolean[][] deepFill(final boolean[][] input, final boolean value)
}

final boolean[][] array = deepCopy(input);
for (int i = 0; i < array.length; i++) {
for (final boolean[] innerArray : array) {
for (int j = 0; j < array[0].length; j++) {
array[i][j] = value;
innerArray[j] = value;
}
}

return array;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public enum Option {
LOOPS_TO_START,

/**
* The distance from a -> b != b -> a, so we cannot simply find the reverse direction when calculating distance.
* The distance from (a -> b) != (b -> a), so we cannot simply find the reverse direction when calculating distance.
*/
UNI_DIRECTIONAL_DISTANCES
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ public static String lookAndSay(final String input) {
count++;
}

output.append(count);
output.append(c);
output.append(count).append(c);
}
return output.toString();
}
Expand Down Expand Up @@ -430,7 +429,7 @@ public static String replaceAtIndex(final String input, final CharSequence subSt
public static String sort(final String input) {
final char[] chars = input.toCharArray();
Arrays.sort(chars);
return new String(chars);
return String.copyValueOf(chars);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lint/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<exclude name="ShortMethodName"/>
<exclude name="ShortVariable"/>
<exclude name="TooManyStaticImports"/>
<exclude name="UnnecessaryCast"/>
<exclude name="UselessParentheses"/>
</rule>
<!-- I don't want to stick to the convention for unit tests, reasonable for production methods though -->
Expand Down
Loading

0 comments on commit dd59bb6

Please sign in to comment.