コード例 #1
0
  /**
   * Logic Operation on founding a Closing parenthesis
   *
   * @param pil
   * @throws NotNumberException
   * @throws NotBooleanException
   * @throws EmptyListException
   * @throws NotTheSameInstanceException
   * @throws NullObjectsInTheArrayException
   */
  @SuppressWarnings("incomplete-switch")
  private static void doLogicOperation(List<Object> pil)
      throws NotNumberException, NotBooleanException, EmptyListException,
          NotTheSameInstanceException, NullObjectsInTheArrayException {
    List<Object> operands = new ArrayList<Object>();
    List<Object> operators = new ArrayList<Object>();

    Object o = pull(pil);
    while (CommonDifferentTests.areDifferentWhateverClass(o, LogicOperationOperators.OP)) {
      if (CommonClassTests.isBoolean(o)) operands.add(o);
      if (o instanceof LogicOperationOperators) operators.add(o);
      o = pull(pil);
    }

    while (CommonMathTests.ADifferentFromB(operators.size(), 0)) {
      LogicOperationOperators op = (LogicOperationOperators) pull(operators);
      Object o1 = pull(operands);
      Object o2 = pull(operands);

      switch (op) {
        case AND:
          operands.add(CommonLogicTests.and(o1, o2));
          break;
        case OR:
          operands.add(CommonLogicTests.or(o1, o2));
          break;
      }
    }

    pil.add(operands.get(0));
  }
コード例 #2
0
  /**
   * Get the Boolean from the Object given
   *
   * @param o
   * @return
   * @throws NotBooleanException
   */
  public static Boolean getBoolean(Object o) throws NotBooleanException {
    if (!CommonClassTests.isBoolean(o))
      throw new NotBooleanException(
          "The object given is not instance of java.lang.Boolean : " + o.getClass().toString());

    return (Boolean) o;
  }