/** * 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)); }
/** * Pull an element from a list<br> * <i>return and remove the latest element</i> * * @param list * @return */ private static Object pull(List<Object> list) { Object o = list.get(list.size() - 1); list.remove(list.size() - 1); return o; }