/** * Compares two {@link TemplateModel}-s according the rules of the FTL "==" operator. * * @since 2.3.20 */ public boolean applyEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_EQUALS, rightValue, this); }
/** * Compares two {@link TemplateModel}-s according the rules of the FTL "<" operator. * * @since 2.3.20 */ public boolean applyLessThanOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_LESS_THAN, rightValue, this); }
/** * Compares two {@link TemplateModel}-s according the rules of the FTL "<" operator. * * @since 2.3.20 */ public boolean applyLessThanOrEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_LESS_THAN_EQUALS, rightValue, this); }
/** * Compares two {@link TemplateModel}-s according the rules of the FTL ">=" operator. * * @since 2.3.20 */ public boolean applyWithGreaterThanOrEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_GREATER_THAN_EQUALS, rightValue, this); }
@Override boolean evalToBoolean(Environment env) throws TemplateException { return EvalUtil.compare(left, operation, opString, right, this, env); }
/** * Compares two {@link TemplateModel}-s according the rules of the FTL ">" operator. * * @since 2.3.20 */ public boolean applyGreaterThanOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_GREATER_THAN, rightValue, this); }
/** * Same as {@link #compare(TemplateModel, int, TemplateModel, Environment)}, but if the two types are incompatible, * they are treated as non-equal instead of throwing an exception. Comparing dates of different types will * still throw an exception, however. */ static boolean compareLenient( TemplateModel leftValue, int operator, TemplateModel rightValue, Environment env) throws TemplateException { return compare( leftValue, null, operator, null, rightValue, null, null, false, true, false, false, env); }
/** * Compares values according the rules of the FTL comparator operators; if the {@link Expression}-s are * accessible, use {@link #compare(Expression, int, String, Expression, Expression, Environment)} instead, as * that gives better error messages. * * @param leftValue maybe {@code null}, which will usually cause the appropriate {@link TemplateException}. * @param operator one of the {@code COMP_OP_...} constants, like {@link #CMP_OP_EQUALS}. * @param rightValue maybe {@code null}, which will usually cause the appropriate {@link TemplateException}. * @param env {@code null} is tolerated, but should be avoided */ static boolean compare( TemplateModel leftValue, int operator, TemplateModel rightValue, Environment env) throws TemplateException { return compare( leftValue, null, operator, null, rightValue, null, null, false, false, false, false, env); }
private TemplateModel calculateResultForSequence(TemplateSequenceModel seq, Environment env) throws TemplateException { TemplateModel best = null; for (int i = 0; i < seq.size(); i++) { TemplateModel cur = seq.get(i); if (cur != null && (best == null || EvalUtil.compare(cur, null, comparatorOperator, null, best, null, this, true, false, false, false, env))) { best = cur; } } return best; }
/** * Compares two expressions according the rules of the FTL comparator operators. * * @param leftExp not {@code null} * @param operator one of the {@code COMP_OP_...} constants, like {@link #CMP_OP_EQUALS}. * @param operatorString can be null {@code null}; the actual operator used, used for more accurate error message. * @param rightExp not {@code null} * @param env {@code null} is tolerated, but should be avoided */ static boolean compare( Expression leftExp, int operator, String operatorString, Expression rightExp, Expression defaultBlamed, Environment env) throws TemplateException { TemplateModel ltm = leftExp.eval(env); TemplateModel rtm = rightExp.eval(env); return compare( ltm, leftExp, operator, operatorString, rtm, rightExp, defaultBlamed, false, false, false, false, env); }
private static boolean modelsEqual( int seqItemIndex, TemplateModel seqItem, TemplateModel searchedItem, Environment env) throws TemplateModelException { try { return EvalUtil.compare( seqItem, null, EvalUtil.CMP_OP_EQUALS, null, searchedItem, null, null, false, true, true, true, // The last one is true to emulate an old bug for BC env); } catch (TemplateException ex) { throw new _TemplateModelException(ex, "This error has occurred when comparing sequence item at 0-based index ", Integer.valueOf(seqItemIndex), " to the searched item:\n", new _DelayedGetMessage(ex)); } }
private TemplateModel calculateResultForColletion(TemplateCollectionModel coll, Environment env) throws TemplateException { TemplateModel best = null; TemplateModelIterator iter = coll.iterator(); while (iter.hasNext()) { TemplateModel cur = iter.next(); if (cur != null && (best == null || EvalUtil.compare(cur, null, comparatorOperator, null, best, null, this, true, false, false, false, env))) { best = cur; } } return best; }
@Override TemplateModel _eval(Environment env) throws TemplateException { TemplateModel targetValue = target.evalToNonMissing(env); List parameters = this.parameters; int paramCnt = parameters.size(); for (int i = 0; i + 1 < paramCnt; i += 2) { Expression caseExp = (Expression) parameters.get(i); TemplateModel caseValue = caseExp.evalToNonMissing(env); if (EvalUtil.compare( targetValue, target, EvalUtil.CMP_OP_EQUALS, "==", caseValue, caseExp, this, true, false, false, false, env)) { return ((Expression) parameters.get(i + 1)).evalToNonMissing(env); } } if (paramCnt % 2 == 0) { throw new _MiscTemplateException(target, "The value before ?", key, "(case1, value1, case2, value2, ...) didn't match any of the " + "case parameters, and there was no default value parameter (an additional last parameter) " + "eithter. "); } return ((Expression) parameters.get(paramCnt - 1)).evalToNonMissing(env); }
} else if (cas.condition != null) { processCase = EvalUtil.compare( searched, EvalUtil.CMP_OP_EQUALS, "case==", cas.condition, cas.condition, env);
/** * Compares two {@link TemplateModel}-s according the rules of the FTL ">" operator. * * @since 2.3.20 */ public boolean applyGreaterThanOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_GREATER_THAN, rightValue, this); }
/** * Compares two {@link TemplateModel}-s according the rules of the FTL "<" operator. * * @since 2.3.20 */ public boolean applyLessThanOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_LESS_THAN, rightValue, this); }
/** * Compares two {@link TemplateModel}-s according the rules of the FTL "<" operator. * * @since 2.3.20 */ public boolean applyLessThanOrEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_LESS_THAN_EQUALS, rightValue, this); }
/** * Compares two {@link TemplateModel}-s according the rules of the FTL "==" operator. * * @since 2.3.20 */ public boolean applyEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_EQUALS, rightValue, this); }
/** * Compares two {@link TemplateModel}-s according the rules of the FTL "<" operator. * * @since 2.3.20 */ public boolean applyLessThanOrEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_LESS_THAN_EQUALS, rightValue, this); }
/** * Compares two {@link TemplateModel}-s according the rules of the FTL ">" operator. * * @since 2.3.20 */ public boolean applyGreaterThanOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { return EvalUtil.compare(leftValue, EvalUtil.CMP_OP_GREATER_THAN, rightValue, this); }