use of freemarker.template.SimpleNumber in project android by JetBrains.
the class FmCompareVersionsMethod method exec.
@Override
public TemplateModel exec(List args) throws TemplateModelException {
if (args.size() != 2) {
throw new TemplateModelException("Wrong arguments");
}
GradleVersion lhs = GradleVersion.parse(args.get(0).toString());
GradleVersion rhs = GradleVersion.parse(args.get(1).toString());
return new SimpleNumber(lhs.compareTo(rhs));
}
use of freemarker.template.SimpleNumber in project leopard by tanhaichao.
the class AbstractTemplateMethod method exec.
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
// arguments.toArray();
Object[] args = new Object[arguments.size()];
int i = 0;
for (Object obj : arguments) {
if (obj != null) {
if (obj instanceof SimpleDate) {
args[i] = ((SimpleDate) obj).getAsDate();
} else if (obj instanceof SimpleNumber) {
args[i] = ((SimpleNumber) obj).getAsNumber();
} else if (obj instanceof SimpleNumber) {
args[i] = ((SimpleNumber) obj).getAsNumber();
} else if (obj instanceof SimpleScalar) {
args[i] = ((SimpleScalar) obj).toString();
} else if (obj instanceof StringModel) {
args[i] = ((StringModel) obj);
} else {
logger.error("obj:" + obj.getClass());
args[i] = obj.toString();
}
}
i++;
}
try {
return this.execute(args);
} catch (TemplateModelException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new TemplateModelException(e.getMessage(), e);
}
}
use of freemarker.template.SimpleNumber in project android by JetBrains.
the class FmCompareVersionsMethodTest method check.
@SuppressWarnings("rawtypes")
private void check(String lhs, String rhs, int expected) throws Exception {
FmCompareVersionsMethod method = new FmCompareVersionsMethod();
List list = newArrayList(new SimpleScalar(lhs), new SimpleScalar(rhs));
Number result = ((SimpleNumber) method.exec(list)).getAsNumber();
assertEquals(expected, Integer.signum(result.intValue()));
}
use of freemarker.template.SimpleNumber in project freemarker by apache.
the class UnaryPlusMinusExpression method _eval.
@Override
TemplateModel _eval(Environment env) throws TemplateException {
TemplateNumberModel targetModel = null;
TemplateModel tm = target.eval(env);
try {
targetModel = (TemplateNumberModel) tm;
} catch (ClassCastException cce) {
throw new NonNumericalException(target, tm, env);
}
if (!isMinus) {
return targetModel;
}
target.assertNonNull(targetModel, env);
Number n = targetModel.getAsNumber();
n = ArithmeticEngine.CONSERVATIVE_ENGINE.multiply(MINUS_ONE, n);
return new SimpleNumber(n);
}
use of freemarker.template.SimpleNumber in project freemarker by apache.
the class ListableRightUnboundedRangeModel method iterator.
public TemplateModelIterator iterator() throws TemplateModelException {
return new TemplateModelIterator() {
boolean needInc;
int nextType = 1;
int nextInt = getBegining();
long nextLong;
BigInteger nextBigInteger;
public TemplateModel next() throws TemplateModelException {
if (needInc) {
switch(nextType) {
case 1:
if (nextInt < Integer.MAX_VALUE) {
nextInt++;
} else {
nextType = 2;
nextLong = nextInt + 1L;
}
break;
case 2:
if (nextLong < Long.MAX_VALUE) {
nextLong++;
} else {
nextType = 3;
nextBigInteger = BigInteger.valueOf(nextLong);
nextBigInteger = nextBigInteger.add(BigInteger.ONE);
}
break;
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;
}
};
}
Aggregations