From 4b7f158dedc351575eff2133dcea8be8dd49ff9b Mon Sep 17 00:00:00 2001 From: Bernardo Date: Fri, 11 Jul 2025 12:09:09 +0200 Subject: [PATCH 1/5] Updated config --- .github/workflows/deployment.yml | 18 +++++---- .github/workflows/doc_deployment.yml | 44 ---------------------- .github/workflows/test.yml | 2 +- .gitignore | 12 +++++- pom.xml | 56 ++++++++-------------------- readme.md | 22 +---------- src/site/site.xml | 24 ++++++------ 7 files changed, 50 insertions(+), 128 deletions(-) delete mode 100644 .github/workflows/doc_deployment.yml diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 077f2981..71d6571e 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -11,7 +11,7 @@ jobs: concurrency: group: deploy-github-${{ github.ref }} cancel-in-progress: true - permissions: + permissions: contents: read packages: write @@ -20,20 +20,22 @@ jobs: uses: bernardo-mg/maven-github-deployment-action@v1 with: token: ${{ secrets.GITHUB_TOKEN }} + jdk: 17 - ossrh: - name: OSSRH deployment + central: + name: Central deployment runs-on: ubuntu-latest - environment: deployment_ossrh + environment: deployment_central concurrency: - group: deploy-ossrh-${{ github.ref }} + group: deploy-central-${{ github.ref }} cancel-in-progress: true steps: - name: Deploy uses: bernardo-mg/maven-signed-deployment-action@v1 with: - username: ${{ secrets.OSSRH_USERNAME }} - password: ${{ secrets.OSSRH_TOKEN }} + username: ${{ secrets.CENTRAL_USERNAME }} + password: ${{ secrets.CENTRAL_TOKEN }} gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} - gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} \ No newline at end of file + gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} + jdk: 17 diff --git a/.github/workflows/doc_deployment.yml b/.github/workflows/doc_deployment.yml deleted file mode 100644 index c41d0d36..00000000 --- a/.github/workflows/doc_deployment.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Doc deployment - -on: - push: - branches: - - master - - develop - -concurrency: - group: deploy-site-${{ github.ref }} - cancel-in-progress: true - -jobs: - deploy_develop_docs: - name: Deploy docs for develop - environment: deployment_site - if: ${{ github.ref == format('refs/heads/{0}', 'develop') }} - runs-on: ubuntu-latest - - steps: - - name: Deploy site - uses: bernardo-mg/maven-site-deployment-action@v1 - with: - host: docs.bernardomg.com - url: ${{ secrets.DEPLOY_DOCS_DEVELOP_SITE }} - username: ${{ secrets.DEPLOY_DOCS_DEVELOP_USER }} - password: ${{ secrets.DEPLOY_DOCS_DEVELOP_PASSWORD }} - jdk: 17 - - deploy_master_docs: - name: Deploy docs for master - environment: deployment_site - if: ${{ github.ref == format('refs/heads/{0}', 'master') }} - runs-on: ubuntu-latest - - steps: - - name: Deploy site - uses: bernardo-mg/maven-site-deployment-action@v1 - with: - host: docs.bernardomg.com - url: ${{ secrets.DEPLOY_DOCS_SITE }} - username: ${{ secrets.DEPLOY_DOCS_USER }} - password: ${{ secrets.DEPLOY_DOCS_PASSWORD }} - jdk: 17 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2e889ad4..70ea7681 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - jdk: [11, 17, 20] + jdk: [17, 21, 24] steps: - name: Check-out diff --git a/.gitignore b/.gitignore index 0e6fd957..43e11192 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,17 @@ local.properties /src/main/resources/rebel.xml .springBeans +# IntelliJ Idea files # +.idea +*.iml + +# Visual Studio # +.vscode/ +.factorypath + +# Docker +.env + # Windows files # Thumbs.db Desktop.ini @@ -54,4 +65,3 @@ Desktop.ini ._* .Spotlight-V100 .Trashes -/target/ diff --git a/pom.xml b/pom.xml index 8491616d..6991f044 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.bernardomg.maven base-pom - 1.5.6 + 1.5.11 @@ -67,23 +67,6 @@ - - - - deployment-site - - - true - - - - site - Project Documentation Site - - ${site.url} - - - deployment-github @@ -92,31 +75,17 @@ github GitHub Packages - https://maven.pkg.github.com/Bernardo-MG/dice-notation-java + https://maven.pkg.github.com/bernardo-mg/java-validation - - deployment-ossrh - - - - ossrh - Central Repository OSSRH - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - + + deployment-central - org.apache.maven.plugins maven-gpg-plugin @@ -136,6 +105,17 @@ + + + org.sonatype.central + central-publishing-maven-plugin + true + + central + true + published + + @@ -176,10 +156,6 @@ 3.8 - - - 11 - com/bernardomg/tabletop/dice @@ -210,7 +186,7 @@ - 2.3.2 + 2.4.1 http://mvnrepository.com/artifact/com.bernardomg.tabletop/dice diff --git a/readme.md b/readme.md index d1b3e8e1..ff5fd28c 100644 --- a/readme.md +++ b/readme.md @@ -10,12 +10,6 @@ Its usefulness is very clear, it allows working with specific random values dist [![Maven Central](https://img.shields.io/maven-central/v/com.bernardomg.tabletop/dice.svg)][maven-repo] -[![Release docs](https://img.shields.io/badge/docs-release-blue.svg)][site-release] -[![Development docs](https://img.shields.io/badge/docs-develop-blue.svg)][site-develop] - -[![Release javadocs](https://img.shields.io/badge/javadocs-release-blue.svg)][javadoc-release] -[![Development javadocs](https://img.shields.io/badge/javadocs-develop-blue.svg)][javadoc-develop] - ## Features - ANTLR4 grammar @@ -39,16 +33,6 @@ The grammar is included among the [ANTLR4 sample grammars][antrl-grammars]. ## Documentation -Documentation is always generated for the latest release, kept in the 'master' branch: - -- The [latest release documentation page][site-release]. -- The [the latest release Javadoc site][javadoc-release]. - -Documentation is also generated from the latest snapshot, taken from the 'develop' branch: - -- The [the latest snapshot documentation page][site-develop]. -- The [the latest snapshot Javadoc site][javadoc-develop]. - The documentation site sources come along the source code (as it is a Maven site), so it is always possible to generate them using the following Maven command: ``` @@ -95,7 +79,7 @@ rolls = parser.parse("1d6+12", roller); System.out.println(rolls.getTotalRoll()); ``` -For more examples and details check the [docs][site-release]. +For more examples and details check the documentation. ## Collaborate @@ -119,11 +103,7 @@ The project has been released under version 2.0 of the [Apache License][license] [antrl-grammars]: https://github.com/antlr/grammars-v4 [maven-repo]: http://mvnrepository.com/artifact/com.bernardomg.tabletop/dice [issues]: https://github.com/Bernardo-MG/dice-notation-java/issues -[javadoc-develop]: https://docs.bernardomg.com/development/maven/dice-notation-java/apidocs -[javadoc-release]: https://docs.bernardomg.com/maven/dice-notation-java/apidocs [license]: http://www.apache.org/licenses/LICENSE-2.0 [scm]: http://github.com/Bernardo-MG/dice-notation-java -[site-develop]: https://docs.bernardomg.com/development/maven/dice-notation-java -[site-release]: https://docs.bernardomg.com/maven/dice-notation-java [dice-notation-java-cli]: https://github.com/Bernardo-MG/dice-notation-java-cli diff --git a/src/site/site.xml b/src/site/site.xml index c0fae856..b09cb06a 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -1,7 +1,7 @@ - + xsi:schemaLocation="http://maven.apache.org/SITE/2.0.0 https://maven.apache.org/xsd/site-2.0.0.xsd"> com.bernardomg.maven.skins @@ -51,23 +51,21 @@ - - GitHub - - - ${project.ciManagement.system} - - - ${project.issueManagement.system} - + + + - + + + - \ No newline at end of file + \ No newline at end of file From f77daf336b5d007eb2df0a88889e0d0665bbfe12 Mon Sep 17 00:00:00 2001 From: Bernardo Date: Fri, 11 Jul 2025 12:22:55 +0200 Subject: [PATCH 2/5] Updated dependencies --- pom.xml | 12 ++++++------ src/config/pmd/pmd-rules.xml | 19 +++++-------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 6991f044..d3d0d1dd 100644 --- a/pom.xml +++ b/pom.xml @@ -162,13 +162,13 @@ - 4.13.1 - 3.25.1 - 5.10.1 + 4.13.2 + 3.27.3 + 5.13.3 1.18.30 - 5.8.0 - 2.20.0 - 2.0.9 + 5.18.0 + 2.25.0 + 2.0.17 diff --git a/src/config/pmd/pmd-rules.xml b/src/config/pmd/pmd-rules.xml index d3aaca5a..c19b03c3 100644 --- a/src/config/pmd/pmd-rules.xml +++ b/src/config/pmd/pmd-rules.xml @@ -1,5 +1,6 @@ - @@ -8,20 +9,10 @@ - - - - - - - - - - + + - - - + \ No newline at end of file From 722b3fbea90b8a347c31e5bfdcd0c368da477a05 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 12 Jul 2025 15:53:36 +0200 Subject: [PATCH 3/5] Moved to records --- .../bernardomg/tabletop/dice/DefaultDice.java | 33 ++++----- .../dice/history/DefaultRollHistory.java | 48 +++++------- .../dice/history/DefaultRollResult.java | 63 ++++++---------- .../tabletop/dice/interpreter/DiceRoller.java | 8 +- .../notation/operand/DefaultDiceOperand.java | 17 ++--- .../dice/notation/operand/IntegerOperand.java | 17 ++--- .../operation/AbstractBinaryOperation.java | 74 ------------------- .../notation/operation/AdditionOperation.java | 24 +++++- .../notation/operation/DivisionOperation.java | 24 +++++- .../operation/MultiplicationOperation.java | 24 +++++- .../operation/SubtractionOperation.java | 24 +++++- .../dice/parser/DefaultDiceParser.java | 4 +- .../DefaultDiceExpressionBuilder.java | 38 ++++++---- .../parser/listener/DefaultErrorListener.java | 6 +- 14 files changed, 185 insertions(+), 219 deletions(-) delete mode 100644 src/main/java/com/bernardomg/tabletop/dice/notation/operation/AbstractBinaryOperation.java diff --git a/src/main/java/com/bernardomg/tabletop/dice/DefaultDice.java b/src/main/java/com/bernardomg/tabletop/dice/DefaultDice.java index a0056771..e3809d57 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/DefaultDice.java +++ b/src/main/java/com/bernardomg/tabletop/dice/DefaultDice.java @@ -16,8 +16,7 @@ package com.bernardomg.tabletop.dice; -import lombok.Data; -import lombok.NonNull; +import java.util.Objects; /** * Immutable group of dice. @@ -27,23 +26,21 @@ * * @author Bernardo Martínez Garrido */ -@Data -public final class DefaultDice implements Dice { +public final record DefaultDice(Integer quantity, Integer sides) implements Dice { - /** - * Number of dice. - *

- * This is greater or equal to zero. - */ - @NonNull - private final Integer quantity; + public DefaultDice(final Integer quantity, final Integer sides) { + this.quantity = Objects.requireNonNull(quantity, "Received a null pointer as quantity"); + this.sides = Objects.requireNonNull(sides, "Received a null pointer as sides"); + } - /** - * Number of sides in each die. - *

- * This is greater than zero. - */ - @NonNull - private final Integer sides; + @Override + public final Integer getQuantity() { + return quantity; + } + + @Override + public final Integer getSides() { + return sides; + } } diff --git a/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollHistory.java b/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollHistory.java index f2355caf..9152102f 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollHistory.java +++ b/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollHistory.java @@ -18,9 +18,6 @@ import java.util.Objects; -import lombok.Data; -import lombok.NonNull; - /** * Immutable roll history. *

@@ -30,28 +27,8 @@ * @author Bernardo Martínez Garrido * */ -@Data -public final class DefaultRollHistory implements RollHistory { - - /** - * The text representation of the roll history. - *

- * Used as the string representation of the history. - */ - @NonNull - private final String historyText; - - /** - * The results of each expression. - */ - @NonNull - private final Iterable rollResults; - - /** - * Sum of all the generated values. - */ - @NonNull - private final Integer totalRoll; +public final record DefaultRollHistory(Iterable rollResults, String historyText, Integer totalRoll) + implements RollHistory { /** * Constructs a roll history with the specified data. @@ -65,13 +42,12 @@ public final class DefaultRollHistory implements RollHistory { * @param total * sum of all the values */ - public DefaultRollHistory(@NonNull final Iterable results, @NonNull final String text, - @NonNull final Integer total) { - super(); + public DefaultRollHistory(final Iterable rollResults, final String historyText, + final Integer totalRoll) { - rollResults = Objects.requireNonNull(results, "Received a null pointer as roll results"); - historyText = Objects.requireNonNull(text, "Received a null pointer as history text"); - totalRoll = Objects.requireNonNull(total, "Received a null pointer as total roll"); + this.rollResults = Objects.requireNonNull(rollResults, "Received a null pointer as roll results"); + this.historyText = Objects.requireNonNull(historyText, "Received a null pointer as history text"); + this.totalRoll = Objects.requireNonNull(totalRoll, "Received a null pointer as total roll"); } @Override @@ -79,4 +55,14 @@ public final String toString() { return historyText; } + @Override + public final Iterable getRollResults() { + return rollResults; + } + + @Override + public final Integer getTotalRoll() { + return totalRoll; + } + } diff --git a/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollResult.java b/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollResult.java index 6d5a7733..69886b9c 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollResult.java +++ b/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollResult.java @@ -22,68 +22,53 @@ import com.bernardomg.tabletop.dice.DefaultDice; import com.bernardomg.tabletop.dice.Dice; -import lombok.Data; -import lombok.NonNull; - /** * Immutable roll result. Contains all the values generated and the sum of them. * * @author Bernardo Martínez Garrido * */ -@Data -public final class DefaultRollResult implements RollResult { - - /** - * All the generated values. - */ - @NonNull - private final Iterable allRolls; - - /** - * Rolled dice. - */ - @NonNull - private final Dice dice; - - /** - * Sum of all the generated values. - */ - @NonNull - private final Integer totalRoll; +public final record DefaultRollResult(Dice dice, Iterable allRolls, Integer totalRoll) implements RollResult { /** * Constructs a roll result with the specified data. * - * @param d + * @param dice * dice which generated the result - * @param rolls + * @param allRolls * generated values - * @param total + * @param totalRoll * sum of all the values */ - public DefaultRollResult(@NonNull final Dice d, @NonNull final Iterable rolls, - @NonNull final Integer total) { - super(); - - dice = Objects.requireNonNull(d, "Received a null pointer as dice"); - allRolls = Objects.requireNonNull(rolls, "Received a null pointer as rolls"); - totalRoll = Objects.requireNonNull(total, "Received a null pointer as total roll"); + public DefaultRollResult(final Dice dice, final Iterable allRolls, final Integer totalRoll) { + this.dice = Objects.requireNonNull(dice, "Received a null pointer as dice"); + this.allRolls = Objects.requireNonNull(allRolls, "Received a null pointer as rolls"); + this.totalRoll = Objects.requireNonNull(totalRoll, "Received a null pointer as total roll"); } /** * Constructs a roll result with a single value. * - * @param total + * @param totalRoll * sum of all the values */ - public DefaultRollResult(@NonNull final Integer total) { - super(); + public DefaultRollResult(final Integer totalRoll) { + this(new DefaultDice(1, totalRoll), Arrays.asList(totalRoll), totalRoll); + } - dice = new DefaultDice(1, total); - totalRoll = Objects.requireNonNull(total, "Received a null pointer as total roll"); + @Override + public final Iterable getAllRolls() { + return allRolls; + } + + @Override + public final Dice getDice() { + return dice; + } - allRolls = Arrays.asList(total); + @Override + public final Integer getTotalRoll() { + return totalRoll; } } diff --git a/src/main/java/com/bernardomg/tabletop/dice/interpreter/DiceRoller.java b/src/main/java/com/bernardomg/tabletop/dice/interpreter/DiceRoller.java index e90c882d..59531ea2 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/interpreter/DiceRoller.java +++ b/src/main/java/com/bernardomg/tabletop/dice/interpreter/DiceRoller.java @@ -82,9 +82,7 @@ public DiceRoller(final Function roller) { public DiceRoller(final Function roller, final UnaryOperator transformer) { super(); - final Function finalRoller; - - finalRoller = roller.andThen(transformer); + final Function finalRoller = roller.andThen(transformer); wrapped = new ConfigurableInterpreter<>(new PostorderTraverser(), new DiceRollAccumulator(finalRoller)); } @@ -111,9 +109,7 @@ public DiceRoller(final NumberGenerator generator) { public DiceRoller(final NumberGenerator generator, final UnaryOperator transformer) { super(); - final Function finalRoller; - - finalRoller = new DiceToRollResult(generator).andThen(transformer); + final Function finalRoller = new DiceToRollResult(generator).andThen(transformer); wrapped = new ConfigurableInterpreter<>(new PostorderTraverser(), new DiceRollAccumulator(finalRoller)); } diff --git a/src/main/java/com/bernardomg/tabletop/dice/notation/operand/DefaultDiceOperand.java b/src/main/java/com/bernardomg/tabletop/dice/notation/operand/DefaultDiceOperand.java index d735f959..9c40592d 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/notation/operand/DefaultDiceOperand.java +++ b/src/main/java/com/bernardomg/tabletop/dice/notation/operand/DefaultDiceOperand.java @@ -18,26 +18,21 @@ import com.bernardomg.tabletop.dice.Dice; -import lombok.Data; -import lombok.NonNull; - /** * Default implementation of the dice operand. * * @author Bernardo Martínez Garrido */ -@Data -public final class DefaultDiceOperand implements DiceOperand { - - /** - * Operand dice value. - */ - @NonNull - private final Dice dice; +public final record DefaultDiceOperand(Dice dice) implements DiceOperand { @Override public final String getExpression() { return String.format("%dd%d", getDice().getQuantity(), getDice().getSides()); } + @Override + public final Dice getDice() { + return dice; + } + } diff --git a/src/main/java/com/bernardomg/tabletop/dice/notation/operand/IntegerOperand.java b/src/main/java/com/bernardomg/tabletop/dice/notation/operand/IntegerOperand.java index 205abf79..0113dbeb 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/notation/operand/IntegerOperand.java +++ b/src/main/java/com/bernardomg/tabletop/dice/notation/operand/IntegerOperand.java @@ -16,26 +16,21 @@ package com.bernardomg.tabletop.dice.notation.operand; -import lombok.Data; -import lombok.NonNull; - /** * Operand for an integer constant value. * * @author Bernardo Martínez Garrido */ -@Data -public final class IntegerOperand implements ConstantOperand { - - /** - * Operand value. - */ - @NonNull - private final Integer value; +public final record IntegerOperand(Integer value) implements ConstantOperand { @Override public final String getExpression() { return getValue().toString(); } + @Override + public final Integer getValue() { + return value; + } + } diff --git a/src/main/java/com/bernardomg/tabletop/dice/notation/operation/AbstractBinaryOperation.java b/src/main/java/com/bernardomg/tabletop/dice/notation/operation/AbstractBinaryOperation.java deleted file mode 100644 index 437c8ad0..00000000 --- a/src/main/java/com/bernardomg/tabletop/dice/notation/operation/AbstractBinaryOperation.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2014-2023 the original author or authors - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.bernardomg.tabletop.dice.notation.operation; - -import java.util.function.BiFunction; -import java.util.function.BinaryOperator; - -import com.bernardomg.tabletop.dice.notation.DiceNotationExpression; - -import lombok.Data; -import lombok.NonNull; - -/** - * Abstract class for binary operations, containing all the common fields. - *

- * These fields are the operands and the operation, stored as a {@link BiFunction}. - * - * @author Bernardo Martínez Garrido - */ -@Data -public abstract class AbstractBinaryOperation implements BinaryOperation { - - /** - * Left sided operand. - */ - @NonNull - private final DiceNotationExpression left; - - /** - * Operation to apply. - */ - @NonNull - private final BinaryOperator operation; - - /** - * Right sided operand. - */ - @NonNull - private final DiceNotationExpression right; - - /** - * Constructs a subtraction operation with the specified operands. - * - * @param leftOperand - * the left sided operand - * @param rightOperand - * the right sided operand - * @param func - * operation to apply - */ - protected AbstractBinaryOperation(@NonNull final DiceNotationExpression leftOperand, - @NonNull final DiceNotationExpression rightOperand, @NonNull final BinaryOperator func) { - super(); - - left = leftOperand; - right = rightOperand; - operation = func; - } - -} diff --git a/src/main/java/com/bernardomg/tabletop/dice/notation/operation/AdditionOperation.java b/src/main/java/com/bernardomg/tabletop/dice/notation/operation/AdditionOperation.java index 728aea7d..15c971a6 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/notation/operation/AdditionOperation.java +++ b/src/main/java/com/bernardomg/tabletop/dice/notation/operation/AdditionOperation.java @@ -16,6 +16,9 @@ package com.bernardomg.tabletop.dice.notation.operation; +import java.util.Objects; +import java.util.function.BinaryOperator; + import com.bernardomg.tabletop.dice.notation.DiceNotationExpression; /** @@ -23,7 +26,8 @@ * * @author Bernardo Martínez Garrido */ -public final class AdditionOperation extends AbstractBinaryOperation { +public final record AdditionOperation(DiceNotationExpression left, DiceNotationExpression right) + implements BinaryOperation { /** * Constructs an addition operation with the specified operands. @@ -34,7 +38,8 @@ public final class AdditionOperation extends AbstractBinaryOperation { * the right sided operand */ public AdditionOperation(final DiceNotationExpression left, final DiceNotationExpression right) { - super(left, right, (a, b) -> a + b); + this.left = Objects.requireNonNull(left, "Received a null pointer as left operand"); + this.right = Objects.requireNonNull(right, "Received a null pointer as right operand"); } /** @@ -53,4 +58,19 @@ public final String getExpression() { return String.format("%s+%s", left, right); } + @Override + public DiceNotationExpression getLeft() { + return left; + } + + @Override + public BinaryOperator getOperation() { + return (a, b) -> a + b; + } + + @Override + public DiceNotationExpression getRight() { + return right; + } + } diff --git a/src/main/java/com/bernardomg/tabletop/dice/notation/operation/DivisionOperation.java b/src/main/java/com/bernardomg/tabletop/dice/notation/operation/DivisionOperation.java index aec49c02..12f29eac 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/notation/operation/DivisionOperation.java +++ b/src/main/java/com/bernardomg/tabletop/dice/notation/operation/DivisionOperation.java @@ -16,6 +16,9 @@ package com.bernardomg.tabletop.dice.notation.operation; +import java.util.Objects; +import java.util.function.BinaryOperator; + import com.bernardomg.tabletop.dice.notation.DiceNotationExpression; /** @@ -23,7 +26,8 @@ * * @author Bernardo Martínez Garrido */ -public final class DivisionOperation extends AbstractBinaryOperation { +public final record DivisionOperation(DiceNotationExpression left, DiceNotationExpression right) + implements BinaryOperation { /** * Constructs a division operation with the specified operands. @@ -34,7 +38,8 @@ public final class DivisionOperation extends AbstractBinaryOperation { * the right sided operand */ public DivisionOperation(final DiceNotationExpression left, final DiceNotationExpression right) { - super(left, right, (a, b) -> a / b); + this.left = Objects.requireNonNull(left, "Received a null pointer as left operand"); + this.right = Objects.requireNonNull(right, "Received a null pointer as right operand"); } @Override @@ -48,4 +53,19 @@ public final String getExpression() { return String.format("%s/%s", left, right); } + @Override + public DiceNotationExpression getLeft() { + return left; + } + + @Override + public BinaryOperator getOperation() { + return (a, b) -> a / b; + } + + @Override + public DiceNotationExpression getRight() { + return right; + } + } diff --git a/src/main/java/com/bernardomg/tabletop/dice/notation/operation/MultiplicationOperation.java b/src/main/java/com/bernardomg/tabletop/dice/notation/operation/MultiplicationOperation.java index b038d2fe..2c1b1167 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/notation/operation/MultiplicationOperation.java +++ b/src/main/java/com/bernardomg/tabletop/dice/notation/operation/MultiplicationOperation.java @@ -16,6 +16,9 @@ package com.bernardomg.tabletop.dice.notation.operation; +import java.util.Objects; +import java.util.function.BinaryOperator; + import com.bernardomg.tabletop.dice.notation.DiceNotationExpression; /** @@ -23,7 +26,8 @@ * * @author Bernardo Martínez Garrido */ -public final class MultiplicationOperation extends AbstractBinaryOperation { +public final record MultiplicationOperation(DiceNotationExpression left, DiceNotationExpression right) + implements BinaryOperation { /** * Constructs a multiplication operation with the specified operands. @@ -34,7 +38,8 @@ public final class MultiplicationOperation extends AbstractBinaryOperation { * the right sided operand */ public MultiplicationOperation(final DiceNotationExpression left, final DiceNotationExpression right) { - super(left, right, (a, b) -> a * b); + this.left = Objects.requireNonNull(left, "Received a null pointer as left operand"); + this.right = Objects.requireNonNull(right, "Received a null pointer as right operand"); } @Override @@ -48,4 +53,19 @@ public final String getExpression() { return String.format("%s*%s", left, right); } + @Override + public DiceNotationExpression getLeft() { + return left; + } + + @Override + public BinaryOperator getOperation() { + return (a, b) -> a * b; + } + + @Override + public DiceNotationExpression getRight() { + return right; + } + } diff --git a/src/main/java/com/bernardomg/tabletop/dice/notation/operation/SubtractionOperation.java b/src/main/java/com/bernardomg/tabletop/dice/notation/operation/SubtractionOperation.java index f817709d..a7baec23 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/notation/operation/SubtractionOperation.java +++ b/src/main/java/com/bernardomg/tabletop/dice/notation/operation/SubtractionOperation.java @@ -16,6 +16,9 @@ package com.bernardomg.tabletop.dice.notation.operation; +import java.util.Objects; +import java.util.function.BinaryOperator; + import com.bernardomg.tabletop.dice.notation.DiceNotationExpression; /** @@ -23,7 +26,8 @@ * * @author Bernardo Martínez Garrido */ -public final class SubtractionOperation extends AbstractBinaryOperation { +public final record SubtractionOperation(DiceNotationExpression left, DiceNotationExpression right) + implements BinaryOperation { /** * Constructs a subtraction operation with the specified operands. @@ -34,7 +38,8 @@ public final class SubtractionOperation extends AbstractBinaryOperation { * the right sided operand */ public SubtractionOperation(final DiceNotationExpression left, final DiceNotationExpression right) { - super(left, right, (a, b) -> a - b); + this.left = Objects.requireNonNull(left, "Received a null pointer as left operand"); + this.right = Objects.requireNonNull(right, "Received a null pointer as right operand"); } @Override @@ -48,4 +53,19 @@ public final String getExpression() { return String.format("%s-%s", left, right); } + @Override + public DiceNotationExpression getLeft() { + return left; + } + + @Override + public BinaryOperator getOperation() { + return (a, b) -> a - b; + } + + @Override + public DiceNotationExpression getRight() { + return right; + } + } diff --git a/src/main/java/com/bernardomg/tabletop/dice/parser/DefaultDiceParser.java b/src/main/java/com/bernardomg/tabletop/dice/parser/DefaultDiceParser.java index b4d7e808..c7cd1613 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/parser/DefaultDiceParser.java +++ b/src/main/java/com/bernardomg/tabletop/dice/parser/DefaultDiceParser.java @@ -129,9 +129,7 @@ public final DiceNotationExpression parse(final String expression) { @Override public final V parse(final String expression, final DiceInterpreter interpreter) { - final DiceNotationExpression parsed; - - parsed = parse(expression); + final DiceNotationExpression parsed = parse(expression); return interpreter.transform(parsed); } diff --git a/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultDiceExpressionBuilder.java b/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultDiceExpressionBuilder.java index bf03bd21..7903fc53 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultDiceExpressionBuilder.java +++ b/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultDiceExpressionBuilder.java @@ -200,18 +200,28 @@ private final DiceNotationExpression getBinaryOperation(final Collection right = operands.pop(); // Checks which kind of operation this is and builds it - if (ADDITION_OPERATOR.equals(operator)) { - log.trace("Addition operation"); - operation = new AdditionOperation(left, right); - } else if (SUBTRACTION_OPERATOR.equals(operator)) { - log.trace("Subtraction operation"); - operation = new SubtractionOperation(left, right); - } else if (MULTIPLICATION_OPERATOR.equals(operator)) { - log.trace("Multiplication operation"); - operation = new MultiplicationOperation(left, right); - } else if (DIVISION_OPERATOR.equals(operator)) { - log.trace("Division operation"); - operation = new DivisionOperation(left, right); + if (operator != null) { + switch (operator) { + case ADDITION_OPERATOR: + log.trace("Addition operation"); + operation = new AdditionOperation(left, right); + break; + case SUBTRACTION_OPERATOR: + log.trace("Subtraction operation"); + operation = new SubtractionOperation(left, right); + break; + case MULTIPLICATION_OPERATOR: + log.trace("Multiplication operation"); + operation = new MultiplicationOperation(left, right); + break; + case DIVISION_OPERATOR: + log.trace("Division operation"); + operation = new DivisionOperation(left, right); + break; + default: + log.error("Unknown operator {}", operator); + throw new IllegalArgumentException(String.format("The %s operator is invalid", operator)); + } } else { log.error("Unknown operator {}", operator); throw new IllegalArgumentException(String.format("The %s operator is invalid", operator)); @@ -286,10 +296,10 @@ private final DiceOperand getDiceOperand(final DiceContext ctx) { * @return an integer operand */ private final IntegerOperand getIntegerOperand(final String expression) { - final Integer value; + // Parses the value - value = Integer.parseInt(expression); + final Integer value = Integer.parseInt(expression); return new IntegerOperand(value); } diff --git a/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultErrorListener.java b/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultErrorListener.java index 6c7feb30..563dbd17 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultErrorListener.java +++ b/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultErrorListener.java @@ -42,10 +42,8 @@ public DefaultErrorListener() { @Override public final void syntaxError(final Recognizer recognizer, final Object offendingSymbol, final int line, final int charPositionInLine, final String msg, final RecognitionException e) { - final String message; // Final exception message - - message = String.format("Failed to parse at line %1$d on char %2$d due to %3$s", line, charPositionInLine + 1, - msg); + final String message = String.format("Failed to parse at line %1$d on char %2$d due to %3$s", line, charPositionInLine + 1, + msg); log.error(message); From 67341209de49f8c79dfe2975075a4e44b46163b9 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 12 Jul 2025 16:02:11 +0200 Subject: [PATCH 4/5] Removed lombok --- pom.xml | 11 ---- .../interpreter/ConfigurableInterpreter.java | 12 +++- .../dice/interpreter/InorderTraverser.java | 11 +++- .../dice/interpreter/PostorderTraverser.java | 11 +++- .../dice/interpreter/PreorderTraverser.java | 11 +++- .../DefaultDiceExpressionBuilder.java | 57 ++++++++++--------- .../parser/listener/DefaultErrorListener.java | 14 +++-- .../dice/random/AbstractNumberGenerator.java | 11 +++- .../dice/random/DiceToRollResult.java | 11 +++- .../dice/random/RandomNumberGenerator.java | 9 ++- .../dice/visitor/DiceRollAccumulator.java | 11 +++- ...eAndDiceRollerAdditionDiceRollResults.java | 4 +- ...AndDiceRollerAdditionMixedRollResults.java | 4 +- ...eRollerBinaryOperationDiceRollResults.java | 4 +- .../ITParseAndDiceRollerDiceRollResults.java | 12 +--- ...ceRollerMultiplicationDiceRollResults.java | 4 +- ...dDiceRollerParenthesisDiceRollResults.java | 4 +- ...dDiceRollerSubtractionDiceRollResults.java | 4 +- .../value/ITParseAndDiceRollerTotalRoll.java | 4 +- .../ITDefaultDiceParserException.java | 4 +- .../notation/ITDefaultDiceParserNotation.java | 4 +- .../ITDefaultDiceParserComplexStructure.java | 4 +- .../ITDefaultDiceParserNumberStructure.java | 8 +-- ...TDefaultDiceParserSignedDiceStructure.java | 8 +-- ...efaultDiceParserSignedNumberStructure.java | 8 +-- .../unit/history/TestDefaultRollHistory.java | 4 +- .../notation/operand/TestIntegerOperand.java | 8 +-- .../unit/roll/TestDiceToRollResultCalls.java | 6 +- 28 files changed, 127 insertions(+), 136 deletions(-) diff --git a/pom.xml b/pom.xml index d3d0d1dd..aec64395 100644 --- a/pom.xml +++ b/pom.xml @@ -165,7 +165,6 @@ 4.13.2 3.27.3 5.13.3 - 1.18.30 5.18.0 2.25.0 2.0.17 @@ -216,16 +215,6 @@ ${antlr.version} - - - - - org.projectlombok - lombok - ${lombok.version} - provided - - diff --git a/src/main/java/com/bernardomg/tabletop/dice/interpreter/ConfigurableInterpreter.java b/src/main/java/com/bernardomg/tabletop/dice/interpreter/ConfigurableInterpreter.java index 7a7ddfce..66dd962c 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/interpreter/ConfigurableInterpreter.java +++ b/src/main/java/com/bernardomg/tabletop/dice/interpreter/ConfigurableInterpreter.java @@ -18,14 +18,15 @@ import java.util.Objects; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.bernardomg.tabletop.dice.notation.DiceNotationExpression; import com.bernardomg.tabletop.dice.notation.operand.ConstantOperand; import com.bernardomg.tabletop.dice.notation.operand.DiceOperand; import com.bernardomg.tabletop.dice.notation.operation.BinaryOperation; import com.bernardomg.tabletop.dice.visitor.NotationAccumulator; -import lombok.extern.slf4j.Slf4j; - /** * An interpreter which can be customized. *

@@ -38,9 +39,14 @@ * @param * type of the generated object */ -@Slf4j public final class ConfigurableInterpreter implements DiceInterpreter { + /** + * Logger for the class. + */ + private static final Logger log = LoggerFactory + .getLogger(ConfigurableInterpreter.class); + /** * Accumulator for generating the final result. */ diff --git a/src/main/java/com/bernardomg/tabletop/dice/interpreter/InorderTraverser.java b/src/main/java/com/bernardomg/tabletop/dice/interpreter/InorderTraverser.java index e1f7d938..569855ca 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/interpreter/InorderTraverser.java +++ b/src/main/java/com/bernardomg/tabletop/dice/interpreter/InorderTraverser.java @@ -21,11 +21,12 @@ import java.util.Objects; import java.util.Stack; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.bernardomg.tabletop.dice.notation.DiceNotationExpression; import com.bernardomg.tabletop.dice.notation.operation.BinaryOperation; -import lombok.extern.slf4j.Slf4j; - /** * Breaks down the received expression into an inorder list. *

@@ -34,9 +35,13 @@ * @author Bernardo Martínez Garrido * */ -@Slf4j public final class InorderTraverser implements DiceInterpreter> { + /** + * Logger for the class. + */ + private static final Logger log = LoggerFactory.getLogger(InorderTraverser.class); + /** * Default constructor. */ diff --git a/src/main/java/com/bernardomg/tabletop/dice/interpreter/PostorderTraverser.java b/src/main/java/com/bernardomg/tabletop/dice/interpreter/PostorderTraverser.java index 7ef992f5..0dacab3c 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/interpreter/PostorderTraverser.java +++ b/src/main/java/com/bernardomg/tabletop/dice/interpreter/PostorderTraverser.java @@ -22,11 +22,12 @@ import java.util.Stack; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.bernardomg.tabletop.dice.notation.DiceNotationExpression; import com.bernardomg.tabletop.dice.notation.operation.BinaryOperation; -import lombok.extern.slf4j.Slf4j; - /** * Breaks down the received expression into a postorder list. *

@@ -35,9 +36,13 @@ * @author Bernardo Martínez Garrido * */ -@Slf4j public final class PostorderTraverser implements DiceInterpreter> { + /** + * Logger for the class. + */ + private static final Logger log = LoggerFactory.getLogger(PostorderTraverser.class); + /** * Default constructor. */ diff --git a/src/main/java/com/bernardomg/tabletop/dice/interpreter/PreorderTraverser.java b/src/main/java/com/bernardomg/tabletop/dice/interpreter/PreorderTraverser.java index d85e6224..cc81a37b 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/interpreter/PreorderTraverser.java +++ b/src/main/java/com/bernardomg/tabletop/dice/interpreter/PreorderTraverser.java @@ -21,11 +21,12 @@ import java.util.Objects; import java.util.Stack; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.bernardomg.tabletop.dice.notation.DiceNotationExpression; import com.bernardomg.tabletop.dice.notation.operation.BinaryOperation; -import lombok.extern.slf4j.Slf4j; - /** * Breaks down the received expression into a preorder list. *

@@ -34,9 +35,13 @@ * @author Bernardo Martínez Garrido * */ -@Slf4j public final class PreorderTraverser implements DiceInterpreter> { + /** + * Logger for the class. + */ + private static final Logger log = LoggerFactory.getLogger(PreorderTraverser.class); + /** * Default constructor. */ diff --git a/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultDiceExpressionBuilder.java b/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultDiceExpressionBuilder.java index 7903fc53..3e88d3d3 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultDiceExpressionBuilder.java +++ b/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultDiceExpressionBuilder.java @@ -24,6 +24,8 @@ import java.util.stream.StreamSupport; import org.antlr.v4.runtime.tree.TerminalNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.bernardomg.tabletop.dice.DefaultDice; import com.bernardomg.tabletop.dice.Dice; @@ -42,8 +44,6 @@ import com.bernardomg.tabletop.dice.notation.operation.MultiplicationOperation; import com.bernardomg.tabletop.dice.notation.operation.SubtractionOperation; -import lombok.extern.slf4j.Slf4j; - /** * Visitor for an ANTLR4 parser tree. It can return the fully parsed {@link DiceNotationExpression}. *

@@ -53,7 +53,6 @@ * * @author Bernardo Martínez Garrido */ -@Slf4j public final class DefaultDiceExpressionBuilder extends DiceNotationParserBaseListener implements DiceExpressionBuilder { @@ -67,6 +66,12 @@ public final class DefaultDiceExpressionBuilder extends DiceNotationParserBaseLi */ private static final String DIVISION_OPERATOR = "/"; + /** + * Logger for the class. + */ + private static final Logger log = LoggerFactory + .getLogger(DefaultDiceExpressionBuilder.class); + /** * Operator which indicates the operation is a multiplication. */ @@ -200,32 +205,31 @@ private final DiceNotationExpression getBinaryOperation(final Collection right = operands.pop(); // Checks which kind of operation this is and builds it - if (operator != null) { - switch (operator) { - case ADDITION_OPERATOR: - log.trace("Addition operation"); - operation = new AdditionOperation(left, right); - break; - case SUBTRACTION_OPERATOR: - log.trace("Subtraction operation"); - operation = new SubtractionOperation(left, right); - break; - case MULTIPLICATION_OPERATOR: - log.trace("Multiplication operation"); - operation = new MultiplicationOperation(left, right); - break; - case DIVISION_OPERATOR: - log.trace("Division operation"); - operation = new DivisionOperation(left, right); - break; - default: - log.error("Unknown operator {}", operator); - throw new IllegalArgumentException(String.format("The %s operator is invalid", operator)); - } - } else { + if (operator == null) { log.error("Unknown operator {}", operator); throw new IllegalArgumentException(String.format("The %s operator is invalid", operator)); } + switch (operator) { + case ADDITION_OPERATOR: + log.trace("Addition operation"); + operation = new AdditionOperation(left, right); + break; + case SUBTRACTION_OPERATOR: + log.trace("Subtraction operation"); + operation = new SubtractionOperation(left, right); + break; + case MULTIPLICATION_OPERATOR: + log.trace("Multiplication operation"); + operation = new MultiplicationOperation(left, right); + break; + case DIVISION_OPERATOR: + log.trace("Division operation"); + operation = new DivisionOperation(left, right); + break; + default: + log.error("Unknown operator {}", operator); + throw new IllegalArgumentException(String.format("The %s operator is invalid", operator)); + } log.debug("Parsed operation {}", operation); @@ -296,7 +300,6 @@ private final DiceOperand getDiceOperand(final DiceContext ctx) { * @return an integer operand */ private final IntegerOperand getIntegerOperand(final String expression) { - // Parses the value final Integer value = Integer.parseInt(expression); diff --git a/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultErrorListener.java b/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultErrorListener.java index 563dbd17..fb0e63db 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultErrorListener.java +++ b/src/main/java/com/bernardomg/tabletop/dice/parser/listener/DefaultErrorListener.java @@ -19,8 +19,8 @@ import org.antlr.v4.runtime.BaseErrorListener; import org.antlr.v4.runtime.RecognitionException; import org.antlr.v4.runtime.Recognizer; - -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Basic error listener for an ANTLR4 parser. @@ -29,9 +29,13 @@ * * @author Bernardo Martínez Garrido */ -@Slf4j public final class DefaultErrorListener extends BaseErrorListener { + /** + * Logger for the class. + */ + private static final Logger log = LoggerFactory.getLogger(DefaultErrorListener.class); + /** * Default constructor. */ @@ -42,8 +46,8 @@ public DefaultErrorListener() { @Override public final void syntaxError(final Recognizer recognizer, final Object offendingSymbol, final int line, final int charPositionInLine, final String msg, final RecognitionException e) { - final String message = String.format("Failed to parse at line %1$d on char %2$d due to %3$s", line, charPositionInLine + 1, - msg); + final String message = String.format("Failed to parse at line %1$d on char %2$d due to %3$s", line, + charPositionInLine + 1, msg); log.error(message); diff --git a/src/main/java/com/bernardomg/tabletop/dice/random/AbstractNumberGenerator.java b/src/main/java/com/bernardomg/tabletop/dice/random/AbstractNumberGenerator.java index 361516a6..12bf6cb6 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/random/AbstractNumberGenerator.java +++ b/src/main/java/com/bernardomg/tabletop/dice/random/AbstractNumberGenerator.java @@ -21,9 +21,10 @@ import java.util.Objects; import java.util.function.Supplier; -import com.bernardomg.tabletop.dice.Dice; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import lombok.extern.slf4j.Slf4j; +import com.bernardomg.tabletop.dice.Dice; /** * Abstract number generator for facilitating extensions. @@ -34,9 +35,13 @@ * @author Bernardo Martínez Garrido * */ -@Slf4j public abstract class AbstractNumberGenerator implements NumberGenerator { + /** + * Logger for the class. + */ + private static final Logger log = LoggerFactory.getLogger(AbstractNumberGenerator.class); + /** * Default constructor. */ diff --git a/src/main/java/com/bernardomg/tabletop/dice/random/DiceToRollResult.java b/src/main/java/com/bernardomg/tabletop/dice/random/DiceToRollResult.java index dd8be10e..a7c7593f 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/random/DiceToRollResult.java +++ b/src/main/java/com/bernardomg/tabletop/dice/random/DiceToRollResult.java @@ -19,21 +19,26 @@ import java.util.Objects; import java.util.function.Function; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.bernardomg.tabletop.dice.Dice; import com.bernardomg.tabletop.dice.history.DefaultRollResult; import com.bernardomg.tabletop.dice.history.RollResult; -import lombok.extern.slf4j.Slf4j; - /** * Function for transforming a {@code Dice} to a {@code RollResult}, simulating rolls. * * @author Bernardo Martínez Garrido * */ -@Slf4j public final class DiceToRollResult implements Function { + /** + * Logger for the class. + */ + private static final Logger log = LoggerFactory.getLogger(DiceToRollResult.class); + /** * The random numbers generator. *

diff --git a/src/main/java/com/bernardomg/tabletop/dice/random/RandomNumberGenerator.java b/src/main/java/com/bernardomg/tabletop/dice/random/RandomNumberGenerator.java index e92f7c4f..c3fdc245 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/random/RandomNumberGenerator.java +++ b/src/main/java/com/bernardomg/tabletop/dice/random/RandomNumberGenerator.java @@ -18,7 +18,8 @@ import java.util.Random; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * {@link Random}-based number generator. @@ -27,9 +28,13 @@ * * @author Bernardo Martínez Garrido */ -@Slf4j public final class RandomNumberGenerator extends AbstractNumberGenerator { + /** + * Logger for the class. + */ + private static final Logger log = LoggerFactory.getLogger(RandomNumberGenerator.class); + /** * Lower limit for the number generation procedure. *

diff --git a/src/main/java/com/bernardomg/tabletop/dice/visitor/DiceRollAccumulator.java b/src/main/java/com/bernardomg/tabletop/dice/visitor/DiceRollAccumulator.java index d5b9d2cd..6be6291c 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/visitor/DiceRollAccumulator.java +++ b/src/main/java/com/bernardomg/tabletop/dice/visitor/DiceRollAccumulator.java @@ -22,6 +22,9 @@ import java.util.function.Function; import java.util.stream.StreamSupport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.bernardomg.tabletop.dice.Dice; import com.bernardomg.tabletop.dice.history.DefaultRollHistory; import com.bernardomg.tabletop.dice.history.DefaultRollResult; @@ -36,8 +39,6 @@ import com.bernardomg.tabletop.dice.notation.operation.MultiplicationOperation; import com.bernardomg.tabletop.dice.notation.operation.SubtractionOperation; -import lombok.extern.slf4j.Slf4j; - /** * Stores all the rolls generated from the expressions. *

@@ -46,9 +47,13 @@ * @author Bernardo Martínez Garrido * */ -@Slf4j public final class DiceRollAccumulator implements NotationAccumulator { + /** + * Logger for the class. + */ + private static final Logger log = LoggerFactory.getLogger(DiceRollAccumulator.class); + /** * The last expression received. */ diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerAdditionDiceRollResults.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerAdditionDiceRollResults.java index 0a00dc12..9d435639 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerAdditionDiceRollResults.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerAdditionDiceRollResults.java @@ -75,9 +75,7 @@ public final void testParse_Dice() { public final void testParse_Quantity() { final DiceNotationExpression expression; final Iterable rolled; - final String notation; - - notation = "1d1+2d1"; + final String notation = "1d1+2d1"; expression = new DefaultDiceParser().parse(notation); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerAdditionMixedRollResults.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerAdditionMixedRollResults.java index 7d6fe7dd..71c3e109 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerAdditionMixedRollResults.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerAdditionMixedRollResults.java @@ -86,9 +86,7 @@ public final void testParse_Dice() { public final void testParse_Quantity() { final DiceNotationExpression expression; final Iterable rolled; - final String notation; - - notation = "1d1+3+2d1"; + final String notation = "1d1+3+2d1"; expression = new DefaultDiceParser().parse(notation); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerBinaryOperationDiceRollResults.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerBinaryOperationDiceRollResults.java index 6b3d22d5..b707a4ac 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerBinaryOperationDiceRollResults.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerBinaryOperationDiceRollResults.java @@ -86,9 +86,7 @@ public final void testParse_Dice() { public final void testParse_Quantity() { final DiceNotationExpression expression; final Iterable rolled; - final String notation; - - notation = "1d1+2d1*3d1"; + final String notation = "1d1+2d1*3d1"; expression = new DefaultDiceParser().parse(notation); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerDiceRollResults.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerDiceRollResults.java index f7e1465f..5421960e 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerDiceRollResults.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerDiceRollResults.java @@ -64,9 +64,7 @@ public final void testParse_SmallestDice_Dice() { public final void testParse_SmallestDice_Quantity() { final DiceNotationExpression expression; final Iterable rolled; - final String notation; - - notation = "1d1"; + final String notation = "1d1"; expression = new DefaultDiceParser().parse(notation); @@ -84,9 +82,7 @@ public final void testParse_SmallestDice_Rolls() { final DiceNotationExpression expression; final RollResult result; final Iterable rolls; - final String notation; - - notation = "1d1"; + final String notation = "1d1"; expression = new DefaultDiceParser().parse(notation); @@ -109,9 +105,7 @@ public final void testParse_SmallestDice_Rolls() { public final void testParse_SmallestDice_TotalRolls() { final DiceNotationExpression expression; final RollResult result; - final String notation; - - notation = "1d1"; + final String notation = "1d1"; expression = new DefaultDiceParser().parse(notation); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerMultiplicationDiceRollResults.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerMultiplicationDiceRollResults.java index 0245222c..5522d778 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerMultiplicationDiceRollResults.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerMultiplicationDiceRollResults.java @@ -78,9 +78,7 @@ public final void testParse_Dice() { public final void testParse_Quantity() { final DiceNotationExpression expression; final Iterable rolled; - final String notation; - - notation = "1d1*2d1"; + final String notation = "1d1*2d1"; expression = new DefaultDiceParser().parse(notation); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerParenthesisDiceRollResults.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerParenthesisDiceRollResults.java index dec00d9d..9b7860a1 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerParenthesisDiceRollResults.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerParenthesisDiceRollResults.java @@ -83,9 +83,7 @@ public final void testParse_Dice() { public final void testParse_Quantity() { final DiceNotationExpression expression; final Iterable rolled; - final String notation; - - notation = "(1d1+2d1)*3d1"; + final String notation = "(1d1+2d1)*3d1"; expression = new DefaultDiceParser().parse(notation); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerSubtractionDiceRollResults.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerSubtractionDiceRollResults.java index e3baee2d..92e60d16 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerSubtractionDiceRollResults.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/results/ITParseAndDiceRollerSubtractionDiceRollResults.java @@ -75,9 +75,7 @@ public final void testParse_Dice() { public final void testParse_Quantity() { final DiceNotationExpression expression; final Iterable rolled; - final String notation; - - notation = "1d1-2d1"; + final String notation = "1d1-2d1"; expression = new DefaultDiceParser().parse(notation); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/value/ITParseAndDiceRollerTotalRoll.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/value/ITParseAndDiceRollerTotalRoll.java index 4946ea73..c3500401 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/value/ITParseAndDiceRollerTotalRoll.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/interpreter/roll/value/ITParseAndDiceRollerTotalRoll.java @@ -60,9 +60,7 @@ public final void testParse_Add_Dice_Value(final String notation, final Number e public final void testParse_Division_FloatValue() { final DiceNotationExpression parsed; // Parsed expression final Integer result; // Resulting value - final String notation; // Input to parse - - notation = "3/2"; + final String notation = "3/2"; parsed = new DefaultDiceParser().parse(notation); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/exception/ITDefaultDiceParserException.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/exception/ITDefaultDiceParserException.java index 793d4f2a..66c34f0f 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/exception/ITDefaultDiceParserException.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/exception/ITDefaultDiceParserException.java @@ -36,9 +36,7 @@ public ITDefaultDiceParserException() { @ArgumentsSource(InvalidNotationArgumentsProvider.class) @DisplayName("An invalid notation causes an exception") public final void testParse(final String notation) { - final ThrowingCallable closure; - - closure = () -> new DefaultDiceParser().parse(notation); + final ThrowingCallable closure = () -> new DefaultDiceParser().parse(notation); Assertions.assertThatThrownBy(closure) .isInstanceOf(Exception.class); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/notation/ITDefaultDiceParserNotation.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/notation/ITDefaultDiceParserNotation.java index 22f16650..21147a0e 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/notation/ITDefaultDiceParserNotation.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/notation/ITDefaultDiceParserNotation.java @@ -65,9 +65,7 @@ public final void testParse_NoQuantity() { @ArgumentsSource(NotationArgumentsProvider.class) @DisplayName("Can recover the parsed notation") public final void testParse_ReturnsNotation(final String notation) { - final DiceNotationExpression operation; // Parsed operation - - operation = new DefaultDiceParser().parse(notation); + final DiceNotationExpression operation = new DefaultDiceParser().parse(notation); Assertions.assertThat(operation.getExpression()) .isEqualTo(notation); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserComplexStructure.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserComplexStructure.java index eb4a603a..ef5ebfd1 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserComplexStructure.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserComplexStructure.java @@ -41,9 +41,7 @@ public final void testParse_Complex_Structure() { final IntegerOperand integer; final DiceOperand leftDice; final DiceOperand rightDice; - final String notation; - - notation = "1d20-5+2d6"; + final String notation = "1d20-5+2d6"; // ((1d20-5)+2d6) operationFirst = (AdditionOperation) new DefaultDiceParser().parse(notation); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserNumberStructure.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserNumberStructure.java index 56c663b3..ff1894b1 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserNumberStructure.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserNumberStructure.java @@ -33,9 +33,7 @@ public ITDefaultDiceParserNumberStructure() { @Test @DisplayName("A number returns the expected structure") public final void testParse() { - final IntegerOperand value; - - value = (IntegerOperand) new DefaultDiceParser().parse("12"); + final IntegerOperand value = (IntegerOperand) new DefaultDiceParser().parse("12"); Assertions.assertThat(value.getValue()) .isEqualTo(12); @@ -44,9 +42,7 @@ public final void testParse() { @Test @DisplayName("Zero returns the expected structure") public final void testParse_Zero() { - final IntegerOperand value; - - value = (IntegerOperand) new DefaultDiceParser().parse("0"); + final IntegerOperand value = (IntegerOperand) new DefaultDiceParser().parse("0"); Assertions.assertThat(value.getValue()) .isZero(); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserSignedDiceStructure.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserSignedDiceStructure.java index 174c490d..cb777028 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserSignedDiceStructure.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserSignedDiceStructure.java @@ -36,9 +36,7 @@ public ITDefaultDiceParserSignedDiceStructure() { @Test @DisplayName("A negative dice returns the expected structure") public final void testParse_OnesDice_SignedNegative() { - final DiceOperand operation; // Parsed expression - - operation = (DiceOperand) new DefaultDiceParser().parse("-1d1"); + final DiceOperand operation = (DiceOperand) new DefaultDiceParser().parse("-1d1"); Assertions.assertThat(operation.getDice() .getQuantity()) @@ -51,9 +49,7 @@ public final void testParse_OnesDice_SignedNegative() { @Test @DisplayName("A positive dice returns the expected structure") public final void testParse_OnesDice_SignedPositive() { - final DiceOperand operation; // Parsed expression - - operation = (DiceOperand) new DefaultDiceParser().parse("+1d1"); + final DiceOperand operation = (DiceOperand) new DefaultDiceParser().parse("+1d1"); Assertions.assertThat(operation.getDice() .getQuantity()) diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserSignedNumberStructure.java b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserSignedNumberStructure.java index df5b4727..d5bf477d 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserSignedNumberStructure.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/integration/parser/structure/ITDefaultDiceParserSignedNumberStructure.java @@ -36,9 +36,7 @@ public ITDefaultDiceParserSignedNumberStructure() { @Test @DisplayName("A negative number returns the expected structure") public final void testParse_Negative() { - final IntegerOperand operation; // Parsed expression - - operation = (IntegerOperand) new DefaultDiceParser().parse("-12"); + final IntegerOperand operation = (IntegerOperand) new DefaultDiceParser().parse("-12"); Assertions.assertThat(operation.getValue()) .isEqualTo(-12); @@ -47,9 +45,7 @@ public final void testParse_Negative() { @Test @DisplayName("A positive number returns the expected structure") public final void testParse_Positive() { - final IntegerOperand operation; // Parsed expression - - operation = (IntegerOperand) new DefaultDiceParser().parse("+12"); + final IntegerOperand operation = (IntegerOperand) new DefaultDiceParser().parse("+12"); Assertions.assertThat(operation.getValue()) .isEqualTo(12); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/unit/history/TestDefaultRollHistory.java b/src/test/java/com/bernardomg/tabletop/dice/test/unit/history/TestDefaultRollHistory.java index 04a3af22..24059676 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/unit/history/TestDefaultRollHistory.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/unit/history/TestDefaultRollHistory.java @@ -41,9 +41,7 @@ public TestDefaultRollHistory() { @DisplayName("The text representation matches the received one") public final void testToString(final String notation) { final RollHistory history; - final Collection results; - - results = new ArrayList<>(); + final Collection results = new ArrayList<>(); history = new DefaultRollHistory(results, notation, 0); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/unit/notation/operand/TestIntegerOperand.java b/src/test/java/com/bernardomg/tabletop/dice/test/unit/notation/operand/TestIntegerOperand.java index 49cc0f8e..885738d9 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/unit/notation/operand/TestIntegerOperand.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/unit/notation/operand/TestIntegerOperand.java @@ -33,9 +33,7 @@ public TestIntegerOperand() { @Test @DisplayName("The text expression is generated correctly") public final void testTextExpression() { - final DiceNotationExpression operand; // Tested operand - - operand = new IntegerOperand(1); + final DiceNotationExpression operand = new IntegerOperand(1); Assertions.assertThat(operand.getExpression()) .isEqualTo("1"); @@ -44,9 +42,7 @@ public final void testTextExpression() { @Test @DisplayName("The text expression is generated correctly for negatives") public final void testTextExpression_negative() { - final DiceNotationExpression operand; // Tested operand - - operand = new IntegerOperand(-1); + final DiceNotationExpression operand = new IntegerOperand(-1); Assertions.assertThat(operand.getExpression()) .isEqualTo("-1"); diff --git a/src/test/java/com/bernardomg/tabletop/dice/test/unit/roll/TestDiceToRollResultCalls.java b/src/test/java/com/bernardomg/tabletop/dice/test/unit/roll/TestDiceToRollResultCalls.java index ecdc2ad3..b53457c4 100644 --- a/src/test/java/com/bernardomg/tabletop/dice/test/unit/roll/TestDiceToRollResultCalls.java +++ b/src/test/java/com/bernardomg/tabletop/dice/test/unit/roll/TestDiceToRollResultCalls.java @@ -51,13 +51,11 @@ public TestDiceToRollResultCalls() { public final void testApply_GeneratesOnce() { // Mocks generator - when(generator.generate(dice)) - .thenReturn(Arrays.asList(1, 2, 3)); + when(generator.generate(dice)).thenReturn(Arrays.asList(1, 2, 3)); new DiceToRollResult(generator).apply(dice); - verify(generator,times(1)) - .generate(dice); + verify(generator, times(1)).generate(dice); } } From a40f570d1857210fdc942764817fe082b5716212 Mon Sep 17 00:00:00 2001 From: Bernardo-MG Date: Sat, 12 Jul 2025 16:08:28 +0200 Subject: [PATCH 5/5] Corrected javadocs --- .../tabletop/dice/history/DefaultRollHistory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollHistory.java b/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollHistory.java index 9152102f..16ac15fa 100644 --- a/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollHistory.java +++ b/src/main/java/com/bernardomg/tabletop/dice/history/DefaultRollHistory.java @@ -35,11 +35,11 @@ public final record DefaultRollHistory(Iterable rollResults, String *

* The text history will be used for the {@code toString} method. * - * @param results + * @param rollResults * each roll result - * @param text + * @param historyText * history text - * @param total + * @param totalRoll * sum of all the values */ public DefaultRollHistory(final Iterable rollResults, final String historyText,