-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding a dieId to identify a random element and use the dieId to predetermine the result of a random element * Returning the exact position in the expression on an exception
- Loading branch information
1 parent
d5162d2
commit a3cc671
Showing
84 changed files
with
2,758 additions
and
2,079 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 58 additions & 45 deletions
103
src/main/java/de/janno/evaluator/dice/DiceEvaluator.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package de.janno.evaluator.dice; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
|
||
@Value(staticConstructor = "of") | ||
public class DieId implements Comparable<DieId> { | ||
@NonNull | ||
RollId rollId; | ||
int dieIndex; | ||
int reroll; | ||
|
||
@VisibleForTesting | ||
public static DieId of(int expressionPositionStartInc, String value, int reEvaluateCounter, int dieIndex, int reroll) { | ||
return new DieId(RollId.of(ExpressionPosition.of(expressionPositionStartInc, value), reEvaluateCounter), dieIndex, reroll); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return rollId + "i" + dieIndex + "r" + reroll; | ||
} | ||
|
||
@Override | ||
public int compareTo(DieId o) { | ||
if (!this.rollId.equals(o.getRollId())) { | ||
return this.rollId.compareTo(o.getRollId()); | ||
} else if (this.dieIndex != o.getDieIndex()) { | ||
return Integer.compare(this.dieIndex, o.getDieIndex()); | ||
} | ||
return Integer.compare(this.reroll, o.reroll); | ||
} | ||
} |
13 changes: 11 additions & 2 deletions
13
src/main/java/de/janno/evaluator/dice/ExpressionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
package de.janno.evaluator.dice; | ||
|
||
public class ExpressionException extends Exception{ | ||
public ExpressionException(String message) { | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
@Getter | ||
public class ExpressionException extends Exception { | ||
|
||
@NonNull | ||
private final ExpressionPosition expressionPosition; | ||
|
||
public ExpressionException(@NonNull String message, @NonNull ExpressionPosition expressionPosition) { | ||
super(message); | ||
this.expressionPosition = expressionPosition; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/de/janno/evaluator/dice/ExpressionPosition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package de.janno.evaluator.dice; | ||
|
||
import com.google.common.base.Joiner; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
|
||
@Value | ||
public class ExpressionPosition implements Comparable<ExpressionPosition> { | ||
int startInc; | ||
@NonNull | ||
String value; | ||
/** | ||
* A non operator/function extension on the left, like a parentheses. Needed to build the expression back together. | ||
*/ | ||
@Nullable | ||
String leftExtension; | ||
/** | ||
* A non operator/function extension on the right, like a parentheses. Needed to build the expression back together. | ||
*/ | ||
@Nullable | ||
String rightExtension; | ||
|
||
public static ExpressionPosition of(final int startInc, final String value) { | ||
return new ExpressionPosition(startInc, value, null, null); | ||
} | ||
|
||
public ExpressionPosition extendLeft(final String leftValue) { | ||
return new ExpressionPosition(this.startInc, this.value, leftValue, this.rightExtension); | ||
} | ||
|
||
public ExpressionPosition extendRight(final String rightValue) { | ||
return new ExpressionPosition(this.startInc, this.value, this.leftExtension, rightValue); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return startInc + value; | ||
} | ||
|
||
public String toStringWithExtension() { | ||
return Joiner.on("").skipNulls().join(leftExtension, value, rightExtension); | ||
} | ||
|
||
@Override | ||
public int compareTo(ExpressionPosition o) { | ||
return Integer.compare(startInc, o.startInc); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.