test_class.file: lib/src/test/java/com/maltaisn/calcdialog/ExpressionTest.java
test_class.identifier: ExpressionTest
test_case.body: @Test
      public void longExpression() {
          Expression expr = new Expression();
          expr.numbers.add(new BigDecimal("-1"));
          expr.operators.add(Expression.Operator.DIVIDE);
          expr.numbers.add(new BigDecimal("6"));
          expr.operators.add(Expression.Operator.ADD);
          expr.numbers.add(new BigDecimal("5"));
          expr.operators.add(Expression.Operator.MULTIPLY);
          expr.numbers.add(new BigDecimal("12"));
          expr.operators.add(Expression.Operator.DIVIDE);
          expr.numbers.add(new BigDecimal("3"));
          expr.operators.add(Expression.Operator.DIVIDE);
          expr.numbers.add(new BigDecimal("8"));
          expr.operators.add(Expression.Operator.SUBTRACT);
          expr.numbers.add(new BigDecimal("-10"));
  
          BigDecimal result1 = expr.evaluate(false, 8, RoundingMode.HALF_UP);
          assertEquals(result1, new BigDecimal("12.41666667"));
  
          BigDecimal result2 = expr.evaluate(true, 8, RoundingMode.HALF_UP);
          assertEquals(result2, new BigDecimal("12.33333333"));
      }
test_case.class_method_signature: ExpressionTest.longExpression()
test_case.full_signature: @Test public void longExpression()
test_case.identifier: longExpression
test_case.invocations: add add add add add add add add add add add add add evaluate assertEquals evaluate assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void longExpression()
focal_class.declarator: numbers = new ArrayList<>()
focal_class.modifier: final
focal_class.original_string: final List<BigDecimal> numbers = new ArrayList<>();
focal_class.type: List<BigDecimal>
focal_class.var_name: numbers
focal_class.declarator: operators = new ArrayList<>()
focal_class.modifier: final
focal_class.original_string: final List<Operator> operators = new ArrayList<>();
focal_class.type: List<Operator>
focal_class.var_name: operators
focal_class.declarator: CREATOR = new Creator<Expression>() {
          @Override
          public Expression createFromParcel(Parcel in) {
              return new Expression(in);
          }
  
          @Override
          public Expression[] newArray(int size) {
              return new Expression[size];
          }
      }
focal_class.modifier: public static final
focal_class.original_string: public static final Creator<Expression> CREATOR = new Creator<Expression>() {
          @Override
          public Expression createFromParcel(Parcel in) {
              return new Expression(in);
          }
  
          @Override
          public Expression[] newArray(int size) {
              return new Expression[size];
          }
      };
focal_class.type: Creator<Expression>
focal_class.var_name: CREATOR
focal_class.file: lib/src/main/java/com/maltaisn/calcdialog/Expression.java
focal_class.identifier: Expression
focal_class.interfaces: implements Parcelable
focal_class.class_method_signature: Expression.Expression()
focal_class.full_signature:   Expression()
focal_class.identifier: Expression
focal_class.parameters: ()
focal_class.signature:  Expression()
focal_class.class_method_signature: Expression.clear()
focal_class.full_signature:  void clear()
focal_class.identifier: clear
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void clear()
focal_class.class_method_signature: Expression.isEmpty()
focal_class.full_signature:  boolean isEmpty()
focal_class.identifier: isEmpty
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isEmpty()
focal_class.class_method_signature: Expression.evaluate(boolean priority, int scale, RoundingMode roundingMode)
focal_class.full_signature: @NonNull BigDecimal evaluate(boolean priority, int scale, RoundingMode roundingMode)
focal_class.identifier: evaluate
focal_class.modifiers: @NonNull
focal_class.parameters: (boolean priority, int scale, RoundingMode roundingMode)
focal_class.return: BigDecimal
focal_class.signature: BigDecimal evaluate(boolean priority, int scale, RoundingMode roundingMode)
focal_class.class_method_signature: Expression.format(NumberFormat nbFormat)
focal_class.full_signature:  String format(NumberFormat nbFormat)
focal_class.identifier: format
focal_class.parameters: (NumberFormat nbFormat)
focal_class.return: String
focal_class.signature: String format(NumberFormat nbFormat)
focal_class.class_method_signature: Expression.toString()
focal_class.full_signature: @NonNull @Override public String toString()
focal_class.identifier: toString
focal_class.modifiers: @NonNull @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String toString()
focal_class.class_method_signature: Expression.Expression(Parcel in)
focal_class.full_signature: private  Expression(Parcel in)
focal_class.identifier: Expression
focal_class.modifiers: private
focal_class.parameters: (Parcel in)
focal_class.signature:  Expression(Parcel in)
focal_class.class_method_signature: Expression.writeToParcel(@NonNull Parcel out, int flags)
focal_class.full_signature: @Override public void writeToParcel(@NonNull Parcel out, int flags)
focal_class.identifier: writeToParcel
focal_class.modifiers: @Override public
focal_class.parameters: (@NonNull Parcel out, int flags)
focal_class.return: void
focal_class.signature: void writeToParcel(@NonNull Parcel out, int flags)
focal_class.class_method_signature: Expression.describeContents()
focal_class.full_signature: @Override public int describeContents()
focal_class.identifier: describeContents
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int describeContents()
focal_method.body: @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();
      }
focal_method.class_method_signature: Expression.evaluate(boolean priority, int scale, RoundingMode roundingMode)
focal_method.full_signature: @NonNull BigDecimal evaluate(boolean priority, int scale, RoundingMode roundingMode)
focal_method.identifier: evaluate
focal_method.invocations: size size size get size get remove get remove set multiply remove get remove set divide isEmpty remove get remove set add set subtract set multiply set divide stripTrailingZeros remove
focal_method.modifiers: @NonNull
focal_method.parameters: (boolean priority, int scale, RoundingMode roundingMode)
focal_method.return: BigDecimal
focal_method.signature: BigDecimal evaluate(boolean priority, int scale, RoundingMode roundingMode)