public static String rollShowResults(String diceExpression) { LinkedHashMap<Dice, OperatorType> dice = parseMany(diceExpression); StringCompiler sb = new StringCompiler(); Iterator<Map.Entry<Dice, OperatorType>> it = dice.entrySet().iterator(); OperatorType op = null; Integer res = 0, roll = 0; sb.append("{"); while (it.hasNext()) { Map.Entry<Dice, OperatorType> current = it.next(); if (op != null) { roll = current.getKey().roll(); res = op.doOperation(res, roll); } else { // First roll res = current.getKey().roll(); } op = current.getValue(); sb.append("[").append(roll).append(":").append(res).append("]"); if (op != null) { sb.append(op.toString()); } } sb.append("} = ").append(res); return sb.toString(); }
/* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { StringCompiler sb = new StringCompiler(); sb.append(nThrows).append(DICE_TOKEN).append(nFaces); if (modifierOperator != null) { sb.append(modifierOperator).append(modifier); } return sb.toString(); }