public static LinkedHashMap<Dice, OperatorType> parseMany(String dts) { LinkedHashMap<Dice, OperatorType> ret = new LinkedHashMap<Dice, OperatorType>(); ArrayList<String> parts = Utils.splitEncolosed(dts, OPENED_DICE, CLOSED_DICE); Dice dt = null; OperatorType ot = null; for (int i = 0; (i + 1) <= parts.size(); i += 2) { String part1 = parts.get(i); String part2 = (i + 1) < parts.size() ? parts.get(i + 1) : ""; if (isDice(part1)) { if (dt == null) { dt = Dice.parse(part1); } else { ret.put(dt, OperatorType.Addition); dt = Dice.parse(part1); ot = null; } } if (isDice(part2)) { ret.put(dt, OperatorType.Addition); dt = Dice.parse(part2); } else { if (OperatorType.isOperator(part2)) { ot = OperatorType.getOperator(part2); } ret.put(dt, ot); dt = null; } ot = null; } return ret; }
public static ArrayList<Integer> roll(Dice... dice) { ArrayList<Integer> ret = new ArrayList<Integer>(); for (Dice die : dice) { ret.add(die.roll()); } return ret; }