summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/dice/DiceBox.java
diff options
context:
space:
mode:
authorEVE <EVE@EVE-PC>2017-03-14 12:08:11 -0400
committerEVE <EVE@EVE-PC>2017-03-14 12:08:11 -0400
commit635d3150e3e85c01b777ff165e21fa8965d58440 (patch)
tree3389128f83a5a79f8d0eec0a0e19f54b9d117b66 /dice-lang/src/bjc/dicelang/dice/DiceBox.java
parente59e2a97773f93bdd25bd4680809c10699f0feb3 (diff)
Cleanup
Diffstat (limited to 'dice-lang/src/bjc/dicelang/dice/DiceBox.java')
-rw-r--r--dice-lang/src/bjc/dicelang/dice/DiceBox.java74
1 files changed, 36 insertions, 38 deletions
diff --git a/dice-lang/src/bjc/dicelang/dice/DiceBox.java b/dice-lang/src/bjc/dicelang/dice/DiceBox.java
index 85edc77..7a7e7c4 100644
--- a/dice-lang/src/bjc/dicelang/dice/DiceBox.java
+++ b/dice-lang/src/bjc/dicelang/dice/DiceBox.java
@@ -21,24 +21,23 @@ public class DiceBox {
/*
* Only bother will valid expressions
*/
- if (!isValidExpression(exp))
- return null;
+ if(!isValidExpression(exp)) return null;
- if (scalarDiePattern.matcher(exp).matches()) {
+ if(scalarDiePattern.matcher(exp).matches()) {
/*
* Parse scalar die
*/
Die scal = new ScalarDie(Long.parseLong(exp.substring(0, exp.indexOf('s'))));
return new DieExpression(scal);
- } else if (simpleDiePattern.matcher(exp).matches()) {
+ } else if(simpleDiePattern.matcher(exp).matches()) {
/*
* Parse simple die groups
*/
String[] dieParts = exp.split("d");
long right = Long.parseLong(dieParts[1]);
- if (dieParts[0].equals("")) {
+ if(dieParts[0].equals("")) {
/*
* Handle short-form expressions.
*/
@@ -48,14 +47,14 @@ public class DiceBox {
Die scal = new SimpleDie(Long.parseLong(dieParts[0]), right);
return new DieExpression(scal);
}
- } else if (fudgeDiePattern.matcher(exp).matches()) {
+ } else if(fudgeDiePattern.matcher(exp).matches()) {
/*
* Parse fudge dice
*/
String nDice = exp.substring(0, exp.indexOf('d'));
return new DieExpression(new FudgeDie(Long.parseLong(nDice)));
- } else if (compoundDiePattern.matcher(exp).matches()) {
+ } else if(compoundDiePattern.matcher(exp).matches()) {
/*
* Parse compound die expressions
*/
@@ -65,7 +64,7 @@ public class DiceBox {
DieExpression right = parseExpression(dieParts[1]);
return new DieExpression(new CompoundDie(left.scalar, right.scalar));
- } else if (compoundingDiePattern.matcher(exp).matches()) {
+ } else if(compoundingDiePattern.matcher(exp).matches()) {
/*
* Parse compounding die expressions
*/
@@ -76,7 +75,7 @@ public class DiceBox {
Die scal = new CompoundingDie(left.scalar, right, dieParts[1]);
return new DieExpression(scal);
- } else if (explodingDiePattern.matcher(exp).matches()) {
+ } else if(explodingDiePattern.matcher(exp).matches()) {
/*
* Parse exploding die expressions
*/
@@ -87,7 +86,7 @@ public class DiceBox {
DieList lst = new ExplodingDice(left.scalar, right, dieParts[1], false);
return new DieExpression(lst);
- } else if (penetratingDiePattern.matcher(exp).matches()) {
+ } else if(penetratingDiePattern.matcher(exp).matches()) {
/*
* Parse penetrating die expressions
*/
@@ -98,7 +97,7 @@ public class DiceBox {
DieList lst = new ExplodingDice(left.scalar, right, dieParts[1], true);
return new DieExpression(lst);
- } else if (diceListPattern.matcher(exp).matches()) {
+ } else if(diceListPattern.matcher(exp).matches()) {
/*
* Parse simple die lists
*/
@@ -128,16 +127,16 @@ public class DiceBox {
*
* This is just a number.
*/
- private static final String scalarDie = "[\\+\\-]?\\d+sd";
- private static final Pattern scalarDiePattern = Pattern.compile("\\A" + scalarDie + "\\Z");
+ private static final String scalarDie = "[\\+\\-]?\\d+sd";
+ private static final Pattern scalarDiePattern = Pattern.compile("\\A" + scalarDie + "\\Z");
/*
* Defines a simple die.
*
* This is a group of one or more dice of the same size.
*/
- private static final String simpleDie = "(?:\\d+)?d\\d+";
- private static final Pattern simpleDiePattern = Pattern.compile("\\A" + simpleDie + "\\Z");
+ private static final String simpleDie = "(?:\\d+)?d\\d+";
+ private static final Pattern simpleDiePattern = Pattern.compile("\\A" + simpleDie + "\\Z");
/*
* Defines a fudge die.
@@ -145,16 +144,16 @@ public class DiceBox {
* This is like a simple die, but all the die give -1, 0, or 1 as
* results.
*/
- private static final String fudgeDie = "(?:\\d+)?dF";
- private static final Pattern fudgeDiePattern = Pattern.compile("\\A" + fudgeDie + "\\Z");
+ private static final String fudgeDie = "(?:\\d+)?dF";
+ private static final Pattern fudgeDiePattern = Pattern.compile("\\A" + fudgeDie + "\\Z");
/*
* Defines a compound die.
*
* This is like using two d10's to simulate a d100
*/
- private static final String compoundDie = simpleDie + "c(?:(?:" + simpleDie + ")|(?:\\d+))";
- private static final Pattern compoundDiePattern = Pattern.compile("\\A" + compoundDie + "\\Z");
+ private static final String compoundDie = simpleDie + "c(?:(?:" + simpleDie + ")|(?:\\d+))";
+ private static final Pattern compoundDiePattern = Pattern.compile("\\A" + compoundDie + "\\Z");
/*
* Defines a compound group.
@@ -170,8 +169,8 @@ public class DiceBox {
* This is like an exploding die, but is a single die, not a group of
* them.
*/
- private static final String compoundingDie = compoundGroup + "!!" + comparePoint;
- private static final Pattern compoundingDiePattern = Pattern.compile("\\A" + compoundingDie + "\\Z");
+ private static final String compoundingDie = compoundGroup + "!!" + comparePoint;
+ private static final Pattern compoundingDiePattern = Pattern.compile("\\A" + compoundingDie + "\\Z");
/*
* Defines an exploding die.
@@ -179,8 +178,8 @@ public class DiceBox {
* This is a die that you reroll the component of if it meets a certain
* condition.
*/
- private static final String explodingDie = compoundGroup + "!" + comparePoint;
- private static final Pattern explodingDiePattern = Pattern.compile("\\A" + explodingDie + "\\Z");
+ private static final String explodingDie = compoundGroup + "!" + comparePoint;
+ private static final Pattern explodingDiePattern = Pattern.compile("\\A" + explodingDie + "\\Z");
/*
* Defines a penetrating die.
@@ -188,16 +187,16 @@ public class DiceBox {
* This is like an exploding die, but the exploded result gets a -1
* penalty.
*/
- private static final String penetratingDie = compoundGroup + "!" + comparePoint;
- private static final Pattern penetratingDiePattern = Pattern.compile("\\A" + penetratingDie + "\\Z");
+ private static final String penetratingDie = compoundGroup + "!" + comparePoint;
+ private static final Pattern penetratingDiePattern = Pattern.compile("\\A" + penetratingDie + "\\Z");
/*
* Defines a die list.
*
* This is an array of dice of the specified size
*/
- private static final String diceList = compoundGroup + "dl" + compoundGroup;
- private static final Pattern diceListPattern = Pattern.compile("\\A" + diceList + "\\Z");
+ private static final String diceList = compoundGroup + "dl" + compoundGroup;
+ private static final Pattern diceListPattern = Pattern.compile("\\A" + diceList + "\\Z");
/**
* Check if a given string is a valid die expression.
@@ -208,25 +207,24 @@ public class DiceBox {
* @return Whether or not the string is a valid command
*/
public static boolean isValidExpression(String exp) {
- if (scalarDiePattern.matcher(exp).matches()) {
+ if(scalarDiePattern.matcher(exp).matches())
return true;
- } else if (simpleDiePattern.matcher(exp).matches()) {
+ else if(simpleDiePattern.matcher(exp).matches())
return true;
- } else if (fudgeDiePattern.matcher(exp).matches()) {
+ else if(fudgeDiePattern.matcher(exp).matches())
return true;
- } else if (compoundDiePattern.matcher(exp).matches()) {
+ else if(compoundDiePattern.matcher(exp).matches())
return true;
- } else if (compoundingDiePattern.matcher(exp).matches()) {
+ else if(compoundingDiePattern.matcher(exp).matches())
return true;
- } else if (explodingDiePattern.matcher(exp).matches()) {
+ else if(explodingDiePattern.matcher(exp).matches())
return true;
- } else if (penetratingDiePattern.matcher(exp).matches()) {
+ else if(penetratingDiePattern.matcher(exp).matches())
return true;
- } else if (diceListPattern.matcher(exp).matches()) {
+ else if(diceListPattern.matcher(exp).matches())
return true;
- } else {
+ else
return false;
- }
}
/*
@@ -235,7 +233,7 @@ public class DiceBox {
private static Predicate<Long> deriveCond(String patt) {
long num = Long.parseLong(patt.substring(1));
- switch (patt.charAt(0)) {
+ switch(patt.charAt(0)) {
case '<':
return (roll) -> roll < num;
case '=':