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-repo]
-[][site-release]
-[][site-develop]
-
-[][javadoc-release]
-[][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/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
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..16ac15fa 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,48 +27,27 @@
* @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.
*
* 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(@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/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/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/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/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..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,22 +205,31 @@ 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);
- } 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);
@@ -286,10 +300,9 @@ 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..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,10 +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; // 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);
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/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 @@