public Object apply(EvaluatorState state, List<Object> arguments) { if (arguments.size() < 1) throw new BadOperandCountException(arguments.size(), 1, 1); else { Class<?> operandClass = String.class; Object o0 = arguments.get(0); if (checkCompatibleOperand(o0, operandClass)) { o0 = convertCompatibleOperand(o0, operandClass); assert o0 instanceof String; String designator = (String) o0; return Boolean.valueOf(features.contains(designator)); } else throw new IncompatibleOperandException(o0, operandClass); } } }
private static boolean checkOperandCount(Expression e, int count) { return checkOperandCount(e, count, count); }
public static boolean isCondition(String value, Location location, VerifierContext context, Object[] outputCondition) { try { Condition c = Condition.valueOf(value); if (c != null) { Condition.EvaluatorState state = (Condition.EvaluatorState) context.getResourceState("conditionEvaluatorState"); if (state != null) { c.evaluate(state); return true; } else { throw new IllegalStateException("no condition evaluator state"); } } else { throw new IllegalStateException("no condition"); } } catch (Condition.ParserException e) { return false; } catch (Condition.EvaluatorException e) { return false; } }
private Condition.EvaluatorState makeConditionEvaluatorState() { // media parameters Map<String,Object> mp = new java.util.HashMap<String,Object>(); populateMediaParameters(mp); // bound parameters Map<String,Object> bp = new java.util.HashMap<String,Object>(); populateBoundParameters(bp); // supported features Set<String> sf = new java.util.HashSet<String>(); populateSupportedFeatures(sf); return Condition.makeEvaluatorState(mp, bp, sf); }
public boolean isCondition(Condition.EvaluatorState state) { return (condition == null) || condition.evaluate(state); }
public static Object convertCompatibleOperand(Object o, Class<?> compatibleClass) { if (o == null) throw new IllegalStateException(); else if (o instanceof Number) return convertCompatibleOperand((Number) o, compatibleClass); else if (o instanceof String) return convertCompatibleOperand((String) o, compatibleClass); else if (o instanceof Boolean) return convertCompatibleOperand((Boolean) o, compatibleClass); else throw new IllegalStateException(); }
Condition parse(CharBuffer cb) { if (cb.hasRemaining()) { state.setInput(cb, skipWhitespace); state.operators().push(Operator.SENTINEL); parseExpression(); state.expect(Token.EOS); return new Condition(state.topOperand()); } else throw new ParserException("empty condition"); }
protected Condition.EvaluatorState makeConditionEvaluatorState() { return Condition.makeEvaluatorState(getConditionMediaParameters(), getConditionBoundParameters(), getConditionSupportedFeatures()); }
public boolean evaluate(EvaluatorState state) { Object o = new ExpressionEvaluator(state).evaluate(expression); Class<?> operandClass = Boolean.class; if (checkCompatibleOperand(o, operandClass)) { o = convertCompatibleOperand(o, operandClass); if (o instanceof Boolean) return ((Boolean) o).booleanValue(); else throw new IllegalStateException(); } else throw new EvaluatorException("condition expression evaluates to non-boolean compatible value " + o); }
public static void badCondition(String value, Location location, VerifierContext context) { Reporter reporter = context.getReporter(); Locator locator = location.getLocator(); try { Condition c = Condition.valueOf(value); if (c != null) { Condition.EvaluatorState state = (Condition.EvaluatorState) context.getResourceState("conditionEvaluatorState"); if (state != null) { c.evaluate(state); } else { throw new IllegalStateException("no condition evaluator state"); } } else { throw new IllegalStateException("no condition"); } } catch (Condition.ParserException e) { reporter.logInfo(reporter.message(locator, "*KEY*", "Invalid syntax of <condition> ''{0}'': {1}", value, e.getMessage())); } catch (Condition.EvaluatorException e) { reporter.logInfo(reporter.message(locator, "*KEY*", "Incomplete evaluation of <condition> ''{0}'': {1}", value, e.getMessage())); } }
public Object apply(EvaluatorState state, List<Object> arguments) { if (arguments.size() < 1) throw new BadOperandCountException(arguments.size(), 1, 1); else { Class<?> operandClass = String.class; Object o0 = arguments.get(0); if (checkCompatibleOperand(o0, operandClass)) { o0 = convertCompatibleOperand(o0, operandClass); assert o0 instanceof String; String name = (String) o0; if (parameters.containsKey(name)) return parameters.get(name); else throw new UnknownParameterException(name); } else throw new IncompatibleOperandException(o0, operandClass); } } }
public Object apply(EvaluatorState state, List<Object> arguments) { if (arguments.size() < 1) throw new BadOperandCountException(arguments.size(), 1, 1); else { Class<?> operandClass = String.class; Object o0 = arguments.get(0); if (checkCompatibleOperand(o0, operandClass)) { o0 = convertCompatibleOperand(o0, operandClass); assert o0 instanceof String; String query = (String) o0; try { MediaQuery mq = MediaQuery.valueOf(query); return mq.evaluate(parameters); } catch (MediaQuery.ParserException e) { throw new BuiltinFunctionException(e); } } else throw new IncompatibleOperandException(o0, operandClass); } } }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int minCount = 2; final int maxCount = 2; if (checkOperandCount(e, minCount, maxCount)) { Class<?> operandClass = Number.class; Object o0 = ee.evaluate(e.getOperand(0)); if (!checkCompatibleOperand(o0, operandClass)) throw new IncompatibleOperandException(e, o0, operandClass); else o0 = convertCompatibleOperand(o0, operandClass); Object o1 = ee.evaluate(e.getOperand(1)); if (!checkCompatibleOperand(o1, operandClass)) throw new IncompatibleOperandException(e, o1, operandClass); else o1 = convertCompatibleOperand(o1, operandClass); return evaluate(ee.getState(), e.getOperator(), o0, o1); } else throw new BadOperandCountException(e, minCount, maxCount); } else throw new BadOperatorException(e, "binary arithmetic"); }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int minCount = 2; final int maxCount = 2; if (checkOperandCount(e, minCount, maxCount)) { Class<?> operandClass = Boolean.class; Object o0 = ee.evaluate(e.getOperand(0)); if (!checkCompatibleOperand(o0, operandClass)) throw new IncompatibleOperandException(e, o0, operandClass); else o0 = convertCompatibleOperand(o0, operandClass); Object o1 = ee.evaluate(e.getOperand(1)); if (!checkCompatibleOperand(o1, operandClass)) throw new IncompatibleOperandException(e, o1, operandClass); else o1 = convertCompatibleOperand(o1, operandClass); return evaluate(ee.getState(), e.getOperator(), o0, o1); } else throw new BadOperandCountException(e, minCount, maxCount); } else throw new BadOperatorException(e, "binary logic"); }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int minCount = 1; final int maxCount = 1; if (checkOperandCount(e, minCount, maxCount)) { Class<?> operandClass = Number.class; Object o0 = ee.evaluate(e.getOperand(0)); if (!checkCompatibleOperand(o0, operandClass)) throw new IncompatibleOperandException(e, o0, operandClass); else o0 = convertCompatibleOperand(o0, operandClass); return evaluate(ee.getState(), e.getOperator(), o0); } else throw new BadOperandCountException(e, minCount, maxCount); } else throw new BadOperatorException(e, "unary arithmetic"); }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int minCount = 1; final int maxCount = 1; if (checkOperandCount(e, minCount, maxCount)) { Class<?> operandClass = Boolean.class; Object o0 = ee.evaluate(e.getOperand(0)); if (!checkCompatibleOperand(o0, operandClass)) throw new IncompatibleOperandException(e, o0, operandClass); else o0 = convertCompatibleOperand(o0, operandClass); return evaluate(ee.getState(), e.getOperator(), o0); } else throw new BadOperandCountException(e, minCount, maxCount); } else throw new BadOperatorException(e, "unary logic"); }
if (o1 instanceof Number) { return evaluate(ee.getState(), e, operator, (Number) o0, (Number) o1); } else if (checkCompatibleOperand(o1, operandClass)) { return evaluate(ee.getState(), e, operator, (Number) o0, (Number) convertCompatibleOperand(o1, operandClass)); } else { throw new IncompatibleOperandException(e, o1, operandClass); if (o1 instanceof String) { return evaluate(ee.getState(), e, operator, (String) o0, (String) o1); } else if (checkCompatibleOperand(o1, operandClass)) { return evaluate(ee.getState(), e, operator, (String) o0, (String) convertCompatibleOperand(o1, operandClass)); } else { throw new IncompatibleOperandException(e, o1, operandClass); if (o1 instanceof Boolean) { return evaluate(ee.getState(), e, operator, (Boolean) o0, (Boolean) o1); } else if (checkCompatibleOperand(o1, operandClass)) { return evaluate(ee.getState(), e, operator, (Boolean) o0, (Boolean) convertCompatibleOperand(o1, operandClass)); } else { throw new IncompatibleOperandException(e, o1, operandClass);