From e7413128ff4e376997de6e94e4bea5eca14811ef Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 27 Oct 2016 21:56:18 -0400 Subject: Moved examples --- .../main/java/bjc/dicelang/IDiceExpression.java | 91 ---------------------- 1 file changed, 91 deletions(-) delete mode 100644 dice-lang/src/main/java/bjc/dicelang/IDiceExpression.java (limited to 'dice-lang/src/main/java/bjc/dicelang/IDiceExpression.java') diff --git a/dice-lang/src/main/java/bjc/dicelang/IDiceExpression.java b/dice-lang/src/main/java/bjc/dicelang/IDiceExpression.java deleted file mode 100644 index acb1d4d..0000000 --- a/dice-lang/src/main/java/bjc/dicelang/IDiceExpression.java +++ /dev/null @@ -1,91 +0,0 @@ -package bjc.dicelang; - -import bjc.utils.funcutils.StringUtils; - -/** - * An expression for something that can be rolled like a polyhedral die - * - * @author ben - * - */ -@FunctionalInterface -public interface IDiceExpression { - /** - * Parse a string into an expression. - * - * It can accept the following types of expressions - * - * - * Dice concatenation is like using 2 d10s to emulate a d100, so - * instead of adding them, it reads them side by side. - * - * @param expression - * The string to convert to an expression - * - * @return The string, converted into expression form - */ - static IDiceExpression toExpression(String expression) { - String literalData = expression; - - if (StringUtils.containsInfixOperator(literalData, "c")) { - // Parse a compound die - String[] strangs = literalData.split("c"); - - return new CompoundDice(strangs); - } else if (StringUtils.containsInfixOperator(literalData, "d")) { - // Handle groups of similiar dice - return ComplexDice.fromString(literalData); - } else if (literalData.matches("\\Ad\\d+\\Z")) { - // Handle people who put 'd6' instead of '1d6' - return new Die(Integer.parseInt(literalData.substring(1))); - } else { - // Parse a scalar number - try { - return new ScalarDie(Integer.parseInt(literalData)); - } catch (NumberFormatException nfex) { - UnsupportedOperationException usex = new UnsupportedOperationException( - "Found malformed leaf token " + expression); - - usex.initCause(nfex); - - throw usex; - } - } - } - - /** - * Check if this expression can be optimized to a scalar value - * - * @return Whether or not this expression can be optimized to a scalar - * value - */ - public default boolean canOptimize() { - return false; - } - - /** - * Optimize this expression to a scalar value - * - * @return This expression, optimized to a scalar value - * - * @throws UnsupportedOperationException - * if this type of expression can't be optimized - */ - public default int optimize() { - throw new UnsupportedOperationException( - "Can't optimize this type of expression"); - } - - /** - * Roll the dice once - * - * @return The result of rowing the dice - */ - public int roll(); -} \ No newline at end of file -- cgit v1.2.3