freemarker.template.SimpleNumber Java Examples
The following examples show how to use
freemarker.template.SimpleNumber.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EffortPointsToCssClass.java From windup with Eclipse Public License 1.0 | 6 votes |
@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"; }
Example #2
Source File: GetEffortDescriptionForPoints.java From windup with Eclipse Public License 1.0 | 6 votes |
@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; }
Example #3
Source File: TimeStepRunnerCodeGenerator.java From hazelcast-simulator with Apache License 2.0 | 6 votes |
@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); }
Example #4
Source File: TemporalDialer.java From freemarker-java-8 with Apache License 2.0 | 5 votes |
private long parseLong(Object o) throws TemplateModelException { if (o instanceof Number) { return ((Number) o).longValue(); } else if (o instanceof SimpleNumber) { return ((SimpleNumber) o).getAsNumber().longValue(); } else if (o instanceof String) { try { return Long.parseLong((String) o); } catch (NumberFormatException nfe) { // suppress error } } throw new TemplateModelException("Invalid number: '" + o + "'"); }
Example #5
Source File: GetLogarithmicDistribution.java From windup with Eclipse Public License 1.0 | 5 votes |
@Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { if (arguments.size() < 2) throw new TemplateModelException(NAME + ": Expected 2 arguments, count and maximum count."); if (!(arguments.get(0) instanceof TemplateNumberModel)) throw new TemplateModelException(NAME + ": Both arguments must be numbers, but the first was " + arguments.get(0).getClass().getName()); if (!(arguments.get(1) instanceof TemplateNumberModel)) throw new TemplateModelException(NAME + ": Both arguments must be numbers, but the second was " + arguments.get(1).getClass().getName()); int count = ((TemplateNumberModel) arguments.get(0)).getAsNumber().intValue(); if (count < 1) return new SimpleNumber(0); int maximum = ((TemplateNumberModel) arguments.get(1)).getAsNumber().intValue(); if (maximum < 0) throw new TemplateModelException(NAME + "Maximum must be at least 0, " + maximum); if (count > maximum) { LOG.severe("Count " + count + " is larger than maximum " + maximum + ". Using the maximum as count."); count = maximum; } double ratio = ((double)count) / ((double)maximum + QUITE_A_LOT_FACTOR); // <0..1> // Map it to scale 1..1000. double ratio2 = 1.0d + ratio * (998d * (1-FLATTENER)); double log10 = Math.log10(ratio2) / 3D; // 0..2.999 => 0..0.999 //LOG.info(String.format("count: %d, max: %d, ratio %f, ratio2 %f, log10 %f", count, maximum, ratio, ratio2, log10)); return new NumberModel(Double.valueOf(log10), new DefaultObjectWrapper()); }
Example #6
Source File: FtlDateParser.java From hasting with MIT License | 5 votes |
@Override public Object exec(List args) throws TemplateModelException { SimpleNumber num = (SimpleNumber)args.get(0); long time = num.getAsNumber().longValue(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); return format.format(new Date(time)); }
Example #7
Source File: SourceReportGenerator.java From testability-explorer with Apache License 2.0 | 5 votes |
@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 costModel.computeOverall(cost); } else { throw new IllegalStateException(); } }
Example #8
Source File: SourceReportGenerator.java From testability-explorer with Apache License 2.0 | 5 votes |
@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(); } }
Example #9
Source File: DurationAdapter.java From freemarker-java-8 with Apache License 2.0 | 5 votes |
@Override public TemplateModel getForType(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); }
Example #10
Source File: PeriodAdapter.java From freemarker-java-8 with Apache License 2.0 | 5 votes |
@Override public TemplateModel getForType(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); }
Example #11
Source File: FmCompareVersionsIgnoringQualifiers.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
@Override public Object exec(List args) throws TemplateModelException { if (args.size() != 2) { throw new TemplateModelException("Wrong arguments"); } String string1 = ((TemplateScalarModel) args.get(0)).getAsString(); String string2 = ((TemplateScalarModel) args.get(1)).getAsString(); return new SimpleNumber(compare(string1, string2)); }
Example #12
Source File: SysUserTempletModel.java From mysiteforme with Apache License 2.0 | 5 votes |
@Override public Object exec(@SuppressWarnings("rawtypes")List list) { if(list == null || list.size() == 0){ throw new RuntimeException("参数为空"); } SimpleNumber simpleNumber = (SimpleNumber) list.get(0); if(simpleNumber == null){ return null; } Long userId = simpleNumber.getAsNumber().longValue(); return userService.findUserById(userId); }
Example #13
Source File: ArticleClickTempletModel.java From mysiteforme with Apache License 2.0 | 5 votes |
@Override public Object exec(@SuppressWarnings("rawtypes")List list) { if(list == null || list.size() == 0){ throw new RuntimeException("参数为空"); } SimpleNumber simpleNumber = (SimpleNumber) list.get(0); Long articleId = simpleNumber.getAsNumber().longValue(); return blogArticleService.getArticleClick(articleId); }
Example #14
Source File: CommentNumberTempletModel.java From mysiteforme with Apache License 2.0 | 5 votes |
@Override public Object exec(List list) throws TemplateModelException { if(list == null || list.size() == 0){ throw new MyException("参数为空"); } SimpleNumber simpleNumber = (SimpleNumber) list.get(0); Long articleId = simpleNumber.getAsNumber().longValue(); return blogCommentService.getArticleCommentsCount(articleId); }
Example #15
Source File: RandomMethod.java From halo with GNU General Public License v3.0 | 5 votes |
/** * 生成随机数 * * @param arguments 参数 * @return Object * @throws TemplateModelException TemplateModelException */ @Override public Object exec(List arguments) throws TemplateModelException { if (arguments.size() != 2) { throw new TemplateModelException("Wrong arguments! 2 arguments are needed"); } SimpleNumber argOne = (SimpleNumber) arguments.get(0); SimpleNumber argTwo = (SimpleNumber) arguments.get(1); int start = argOne.getAsNumber().intValue(); int end = argTwo.getAsNumber().intValue(); return RandomUtil.randomInt(start, end); }
Example #16
Source File: RandomMethod.java From stone with GNU General Public License v3.0 | 5 votes |
/** * 生成随机数 * * @param arguments 参数 * @return Object * @throws TemplateModelException TemplateModelException */ @Override public Object exec(List arguments) throws TemplateModelException { SimpleNumber argOne = (SimpleNumber) arguments.get(0); SimpleNumber argTwo = (SimpleNumber) arguments.get(1); int start = argOne.getAsNumber().intValue(); int end = argTwo.getAsNumber().intValue(); return RandomUtil.randomInt(start, end); }
Example #17
Source File: LoopDirective.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
@SuppressWarnings("rawtypes") @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { // Check if no parameters were given: int fromVal = 0; Integer toVal = null; int step = 1; for (Object entryObj : params.entrySet()) { Map.Entry entry = (Entry) entryObj; String paramName = (String) entry.getKey(); TemplateModel paramValue = (TemplateModel) entry.getValue(); switch (paramName) { case "from": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } fromVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "to": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } toVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "step": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } step = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); if (step == 0) { throw new TemplateModelException("The \"" + paramName + "\" parameter must not be 0."); } break; default: //Case not caught, should this cause an error? break; } } if (toVal == null) { throw new TemplateModelException("The \"to\" parameter must be provided."); } if (body == null) { throw new TemplateModelException("This directive must have content."); } if (step > 0) { for (int i = fromVal; i <= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step <= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } else { for (int i = fromVal; i >= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step >= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } }
Example #18
Source File: LoopDirective.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
@SuppressWarnings("rawtypes") @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { // Check if no parameters were given: int fromVal = 0; Integer toVal = null; int step = 1; for (Object entryObj : params.entrySet()) { Map.Entry entry = (Entry) entryObj; String paramName = (String) entry.getKey(); TemplateModel paramValue = (TemplateModel) entry.getValue(); switch (paramName) { case "from": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } fromVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "to": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } toVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "step": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } step = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); if (step == 0) { throw new TemplateModelException("The \"" + paramName + "\" parameter must not be 0."); } break; default: //Case not caught, should this cause an error? break; } } if (toVal == null) { throw new TemplateModelException("The \"to\" parameter must be provided."); } if (body == null) { throw new TemplateModelException("This directive must have content."); } if (step > 0) { for (int i = fromVal; i <= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step <= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } else { for (int i = fromVal; i >= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step >= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } }
Example #19
Source File: RecentPostsMethod.java From stone with GNU General Public License v3.0 | 3 votes |
/** * 获取最近的文章 * * @param arguments 参数 * @return Object * @throws TemplateModelException TemplateModelException */ @Override public Object exec(List arguments) throws TemplateModelException { SimpleNumber argOne = (SimpleNumber) arguments.get(0); int limit = argOne.getAsNumber().intValue(); return postService.getRecentPosts(limit); }
Example #20
Source File: RecentCommentsMethod.java From stone with GNU General Public License v3.0 | 3 votes |
/** * 获取最近的评论 * * @param arguments 参数 * @return Object * @throws TemplateModelException TemplateModelException */ @Override public Object exec(List arguments) throws TemplateModelException { SimpleNumber argOne = (SimpleNumber) arguments.get(0); int limit = argOne.getAsNumber().intValue(); return commentService.getRecentComments(limit); }