/** * Checks if the passed condition is true based on the passed list of node responses. If the id * does not exist in the responses, assume the response is NULL. * * @param condition The condition to check. * @param previousResponses The List of previous responses. * @return Whether or not the condition is true. */ public static boolean evaluateCondition(String condition, List<DataPoint> previousResponses) { // Blank conditions are always valid if (!"".equals(condition)) { start s = null; try { // The API is odd, we have to instantiate an object just to use its static methods below, // we do not actually need to keep the object around for any reason if (!conditionParserInitialized) { new ConditionParser(new StringReader(condition)); conditionParserInitialized = true; } else { ConditionParser.ReInit(new StringReader(condition)); } // Call start statically even though we have to instantiate the object above s = ConditionParser.start(); ConditionDepthFirst<Boolean, Boolean> visitor = new ConditionDepthFirst<Boolean, Boolean>(previousResponses); // Check the condition against the previous responses Boolean conditionValue = visitor.visit(s, null); /*if (DataPointConditionEvaluator._logger.isDebugEnabled()) { DataPointConditionEvaluator._logger.debug("Condition [" + condition + "] evaluated as " + conditionValue.toString()); }*/ Log.v(TAG, "Condition [" + condition + "] evaluated as " + conditionValue.toString()); return conditionValue.booleanValue(); } catch (ParseException pe) { throw new IllegalArgumentException( "Condition failed to parse, should have been checked in the XML validator: " + condition); } } return true; }