This class is thread-safe. @author Jonathan Revusky
168169170171172173174175176177178179180181
{ TemplateModel model = target.eval(env); if (!(model instanceof TemplateNumberModel) && model instanceof TemplateDateModel) { Date date = EvalUtil.modelToDate((TemplateDateModel) model, target); return new SimpleNumber(date.getTime()); } else { Number num = target.modelToNumber(model, env); if (num instanceof Long) { return model; } return new SimpleNumber(num.longValue()); } }
196197198199200201202
} static class roundBI extends BuiltInForNumber { private static final BigDecimal half = new BigDecimal("0.5"); TemplateModel calculateResult(Number num, TemplateModel model) { return new SimpleNumber(new BigDecimal(num.doubleValue()).add(half).divide(BIG_DECIMAL_ONE, 0, BigDecimal.ROUND_FLOOR)); }
205206207208209210211
static class shortBI extends BuiltInForNumber { TemplateModel calculateResult(Number num, TemplateModel model) { if (num instanceof Short) { return model; } return new SimpleNumber(new Short(num.shortValue())); }
72737475767778798081828384
default: // 3 nextBigInteger = nextBigInteger.add(BigInteger.ONE); } } needInc = true; return nextType == 1 ? new SimpleNumber(nextInt) : (nextType == 2 ? new SimpleNumber(nextLong) : new SimpleNumber(nextBigInteger)); } public boolean hasNext() throws TemplateModelException { return true; }
377378379380381382383
// backward compatibility: foundAtIdx = m_seq != null ? findInSeq(target) : findInCol(target); } return foundAtIdx == -1 ? Constants.MINUS_ONE : new SimpleNumber(foundAtIdx); }
189190191192193194195196197198
int argCnt = args.size(); checkMethodArgCount(argCnt, 1, 2); String subStr = getStringMethodArg(args, 0); if (argCnt > 1) { int startIdx = getNumberMethodArg(args, 1).intValue(); return new SimpleNumber(findLast ? s.lastIndexOf(subStr, startIdx) : s.indexOf(subStr, startIdx)); } else { return new SimpleNumber(findLast ? s.lastIndexOf(subStr) : s.indexOf(subStr)); } }
296297298299300301302
} static class lengthBI extends BuiltInForString { TemplateModel calculateResult(String s, Environment env) throws TemplateException { return new SimpleNumber(s.length()); }
175176177178179180181182183184185
switch(name.length() - loopVariableName.length()) { case 0: return loopVar; case 6: if(name.endsWith("_index")) { return new SimpleNumber(index); } break; case 9: if(name.endsWith("_has_next")) { return hasNext ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
5960616263646566676869
Number second = EvalUtil.modelToNumber((TemplateNumberModel) rightModel, right); ArithmeticEngine ae = env != null ? env.getArithmeticEngine() : getTemplate().getArithmeticEngine(); return new SimpleNumber(ae.add(first, second)); } else if(leftModel instanceof TemplateSequenceModel && rightModel instanceof TemplateSequenceModel) { return new ConcatenatedSequence((TemplateSequenceModel)leftModel, (TemplateSequenceModel)rightModel); }
85868788899091929394
static class numberBI extends BuiltInForString { TemplateModel calculateResult(String s, Environment env) throws TemplateException { try { return new SimpleNumber(env.getArithmeticEngine().toNumber(s)); } catch(NumberFormatException nfe) { throw NonNumericalException.newMalformedNumberException(this, s, env); } }