本文整理汇总了Java中freemarker.template.SimpleNumber类的典型用法代码示例。如果您正苦于以下问题:Java SimpleNumber类的具体用法?Java SimpleNumber怎么用?Java SimpleNumber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleNumber类属于freemarker.template包,在下文中一共展示了SimpleNumber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getComplexParams
import freemarker.template.SimpleNumber; //导入依赖的package包/类
protected Map getComplexParams(Map params) {
HashMap map = new HashMap(params.size());
for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
Object value = entry.getValue();
if (value != null && complexType(value)) {
if (value instanceof freemarker.ext.beans.BeanModel) {
map.put(entry.getKey(), ((freemarker.ext.beans.BeanModel) value).getWrappedObject());
} else if (value instanceof SimpleNumber) {
map.put(entry.getKey(), ((SimpleNumber) value).getAsNumber());
} else if (value instanceof SimpleSequence) {
try {
map.put(entry.getKey(), ((SimpleSequence) value).toList());
} catch (TemplateModelException e) {
if (LOG.isErrorEnabled()) {
LOG.error("There was a problem converting a SimpleSequence to a list", e);
}
}
}
}
}
return map;
}
示例2: execute
import freemarker.template.SimpleNumber; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
try {
SimpleNumber pFor = (SimpleNumber) params.get("for");
Number forMillis = null;
if (pFor != null) {
forMillis = pFor.getAsNumber();
try {
Thread.sleep(forMillis.longValue());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
示例3: exec
import freemarker.template.SimpleNumber; //导入依赖的package包/类
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
testAtLeastOneArgument(arguments);
String value = readValue(arguments.get(0));
MessageFormat formatter = new MessageFormat(value, bundle.getLocale());
if (arguments.size() == 1) {
value = formatter.format(new Object[] {});
} else {
List<Object> parameters = new ArrayList<>();
for (Object obj : arguments.subList(1, arguments.size())) {
if (obj instanceof SimpleNumber) {
parameters.add(((SimpleNumber) obj).getAsNumber());
} else if (obj instanceof SimpleDate) {
parameters.add(((SimpleDate) obj).getAsDate());
} else {
parameters.add(obj.toString());
}
}
value = formatter.format(parameters.toArray(), new StringBuffer(), null).toString();
}
return value;
}
示例4: exec
import freemarker.template.SimpleNumber; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object exec(List list) throws TemplateModelException {
if (list.size() != 2) {
throw new TemplateModelException("Wrong number of arguments for method isAssignableFrom()."
+ " Method has two required parameters: [Class, SimpleNumber]. Found: " + list.size());
}
Object arg1 = ((WrapperTemplateModel) list.get(0)).getWrappedObject();
if (!(arg1 instanceof Method)) {
throw new TemplateModelException("Wrong type of the first parameter."
+ " It should be Method. Found: " + arg1.getClass());
}
Object arg2 = list.get(1);
if (!(arg2 instanceof SimpleNumber)) {
throw new TemplateModelException("Wrong type of the second parameter."
+ " It should be SimpleNumber. Found: " + arg2.getClass());
}
return timeStepModel.hasStartNanosAnnotation((Method) arg1, ((SimpleNumber) arg2).getAsNumber().intValue() - 1);
}
示例5: exec
import freemarker.template.SimpleNumber; //导入依赖的package包/类
@Override
public Object exec(List arguments) throws TemplateModelException
{
ExecutionStatistics.get().begin(NAME);
if (arguments.size() < 1)
{
throw new TemplateModelException("Error, method expects one or two arguments (Integer, [verbosity:String])");
}
SimpleNumber simpleNumber = (SimpleNumber) arguments.get(0);
int effort = simpleNumber.getAsNumber().intValue();
Verbosity verbosity = Verbosity.SHORT;
if (arguments.size() > 1)
{
final TemplateScalarModel verbosityModel = (TemplateScalarModel) arguments.get(1);
String verbosityString = verbosityModel.getAsString();
verbosity = Verbosity.valueOf(verbosityString.toUpperCase());
}
String result = EffortReportService.getEffortLevelDescription(verbosity, effort);
ExecutionStatistics.get().end(NAME);
return result;
}
示例6: exec
import freemarker.template.SimpleNumber; //导入依赖的package包/类
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
if (arguments.size() != 1)
{
throw new TemplateModelException("Error, method expects one argument (int)");
}
SimpleNumber freemarkerArg = (SimpleNumber) arguments.get(0);
int effortPoints = freemarkerArg.getAsNumber().intValue();
if (effortPoints == 0)
return "info";
else if (effortPoints < 8)
return "warning";
else if (effortPoints < 14)
return "severe";
else
return "critical";
}
示例7: get
import freemarker.template.SimpleNumber; //导入依赖的package包/类
@Override
public TemplateModel get(String s) throws TemplateModelException {
if (METHOD_DAYS.equalsIgnoreCase(s)) {
return new SimpleNumber(getObject().getDays());
} else if (METHOD_MONTHS.equalsIgnoreCase(s)) {
return new SimpleNumber(getObject().getMonths());
} else if (METHOD_YEARS.equalsIgnoreCase(s)) {
return new SimpleNumber(getObject().getYears());
}
throw new TemplateModelException(METHOD_UNKNOWN_MSG + s);
}
示例8: get
import freemarker.template.SimpleNumber; //导入依赖的package包/类
@Override
public TemplateModel get(String s) throws TemplateModelException {
if (METHOD_NANO.equalsIgnoreCase(s)) {
return new SimpleNumber(getObject().getNano());
} else if (METHOD_SECONDS.equalsIgnoreCase(s)) {
return new SimpleNumber(getObject().getSeconds());
}
throw new TemplateModelException(METHOD_UNKNOWN_MSG + s);
}
示例9: exec
import freemarker.template.SimpleNumber; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object exec(List arguments) throws TemplateModelException {
TemplateModel model = (TemplateModel) arguments.get(0);
if (model instanceof SimpleNumber) {
SimpleNumber number = (SimpleNumber) model;
return "" + number;
} else if (model instanceof BeanModel) {
BeanModel arg0 = (BeanModel) model;
Cost cost = (Cost) arg0.getAdaptedObject(Cost.class);
return "Cost: " + costModel.computeOverall(cost) + " [" + cost + "]";
} else {
throw new IllegalStateException();
}
}
示例10: getInt
import freemarker.template.SimpleNumber; //导入依赖的package包/类
public static Integer getInt(Map params, String paramName){
SimpleNumber valueModel=(SimpleNumber)params.get(paramName);
if (valueModel!=null){
int value=valueModel.getAsNumber().intValue();
return value;
}
return null;
}
示例11: getLong
import freemarker.template.SimpleNumber; //导入依赖的package包/类
public static Long getLong(Map params, String paramName){
SimpleNumber valueModel=(SimpleNumber)params.get(paramName);
if (valueModel!=null){
Long value=valueModel.getAsNumber().longValue();
return value;
}
return null;
}
示例12: getBigDecimal
import freemarker.template.SimpleNumber; //导入依赖的package包/类
public static BigDecimal getBigDecimal(Map params, String paramName){
SimpleNumber valueModel=(SimpleNumber)params.get(paramName);
if (valueModel!=null){
if (valueModel.getAsNumber() instanceof BigDecimal){
return (BigDecimal)valueModel.getAsNumber();
}
return new BigDecimal(valueModel.getAsNumber().doubleValue());
}
return null;
}
示例13: getStringArg
import freemarker.template.SimpleNumber; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public String getStringArg(Map args, String key) {
Object o = args.get(key);
if (o instanceof SimpleScalar) {
return ((SimpleScalar) o).getAsString();
} else if (o instanceof StringModel) {
return ((StringModel) o).getAsString();
} else if (o instanceof SimpleNumber) {
return ((SimpleNumber) o).getAsNumber().toString();
} else if (o instanceof NumberModel) {
return ((NumberModel) o).getAsNumber().toString();
}
return null;
}
示例14: exec
import freemarker.template.SimpleNumber; //导入依赖的package包/类
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
testExactlyOneArgument(arguments);
Object arg = arguments.get(0);
testArgumentIsNumber(arg);
long millis = ((SimpleNumber) arg).getAsNumber().longValue();
long hrs = TimeUnit.MILLISECONDS.toHours(millis);
long min = TimeUnit.MILLISECONDS.toMinutes(millis) % MINUTES_PER_HOUR;
long sec = TimeUnit.MILLISECONDS.toSeconds(millis) % SECONDS_PER_MINUTES;
return String.format("%02d:%02d:%02d", hrs, min, sec);
}
示例15: testArgumentIsNumber
import freemarker.template.SimpleNumber; //导入依赖的package包/类
protected void testArgumentIsNumber(Object arg) throws TemplateModelException {
if (!(arg instanceof SimpleNumber)) {
String message = "Argument (%s) must be a number.";
message = String.format(message, arg);
throw new TemplateModelException(message);
}
}