class Expression implements Parcelable {

    @NonNull
    BigDecimal evaluate(boolean priority, int scale, RoundingMode roundingMode) {
        if (numbers.size() != operators.size() + 1) {
            throw new IllegalStateException("Numbers and operators aren't balanced.");
        }

        if (numbers.size() == 1) return numbers.get(0);

        List<BigDecimal> nbs = new ArrayList<>(numbers);
        List<Operator> ops = new ArrayList<>(operators);

        if (priority) {
            // Evaluate products and quotients
            int i = 0;
            while (i < ops.size()) {
                Operator op = ops.get(i);
                if (op == Operator.MULTIPLY) {
                    ops.remove(i);
                    BigDecimal n1 = nbs.get(i);
                    BigDecimal n2 = nbs.remove(i + 1);
                    nbs.set(i, n1.multiply(n2));
                } else if (op == Operator.DIVIDE) {
                    ops.remove(i);
                    BigDecimal n1 = nbs.get(i);
                    BigDecimal n2 = nbs.remove(i + 1);
                    nbs.set(i, n1.divide(n2, scale, roundingMode));
                } else {
                    i++;
                }
            }
        }

        // Evaluate the rest
        while (!ops.isEmpty()) {
            Operator op = ops.remove(0);
            BigDecimal n1 = nbs.get(0);
            BigDecimal n2 = nbs.remove(1);
            if (op == Operator.ADD) {
                nbs.set(0, n1.add(n2));
            } else if (op == Operator.SUBTRACT) {
                nbs.set(0, n1.subtract(n2));
            } else if (op == Operator.MULTIPLY) {
                nbs.set(0, n1.multiply(n2));
            } else {
                nbs.set(0, n1.divide(n2, scale, roundingMode));
            }
        }

        return nbs.remove(0).stripTrailingZeros();
    }

      Expression();
    private  Expression(Parcel in);

}