Package freemarker.template

Examples of freemarker.template.SimpleNumber


                loopVar = it.next();
                hasNext = it.hasNext();
                put(iteratorBlock.getIndexName(), loopVar);
                TemplateBooleanModel hasNextModel = hasNext ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
                put(iteratorBlock.getIndexName() + "_has_next", hasNextModel);
                put(iteratorBlock.getIndexName() + "_index", new SimpleNumber(index));
                TemplateElement nestedBlock = iteratorBlock.getNestedBlock();
                if (nestedBlock != null) {
                    env.render(nestedBlock);
                }
                index++;
            }
        }
        else if (list instanceof TemplateSequenceModel) {
            TemplateSequenceModel tsm = (TemplateSequenceModel) list;
            int size = tsm.size();
            for (index =0; index <size; index++) {
              clear();
                loopVar = tsm.get(index);
                put(iteratorBlock.getIndexName(), loopVar);
                hasNext = (size > index + 1);
                TemplateBooleanModel hasNextModel = (size > index +1) ?  TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
                put(iteratorBlock.getIndexName() + "_has_next", hasNextModel);
                put(iteratorBlock.getIndexName() + "_index", new SimpleNumber(index));
                TemplateElement nestedBlock = iteratorBlock.getNestedBlock();
                if (nestedBlock != null) {
                    env.render(nestedBlock);
                }
            }
View Full Code Here


        }
    }
   
    public TemplateModel get(int index) throws TemplateModelException
    {
        return (TemplateModel) exec(Collections.singletonList(new SimpleNumber(
                Integer.valueOf(index))));
    }
View Full Code Here

    public abstract TemplateModel apply(final String string, final Environment env, final BuiltInExpression callingExpression) throws TemplateException;
   
    public static class Length extends StringFunctions {
        @Override
        public TemplateModel apply(String string, Environment env, BuiltInExpression caller) {
            return new SimpleNumber(Integer.valueOf(string.length()));
        }
View Full Code Here

        }
    }

    public TemplateModel get(int index) throws TemplateModelException
    {
        return (TemplateModel) exec(Collections.singletonList(new
                SimpleNumber(Integer.valueOf(index))));
    }
View Full Code Here

            if (o instanceof NumberModel) {
                NumberModel s = (NumberModel) o;
                return new Double( s.getAsNumber().doubleValue() );
            }
            if (o instanceof SimpleNumber) {
                SimpleNumber s = (SimpleNumber) o;
                return new Double( s.getAsNumber().doubleValue() );
            }
            if (o instanceof SimpleScalar) {
                SimpleScalar s = (SimpleScalar) o;
                return new Double( s.getAsString() );
            }
            return new Double( o.toString() );
        }
        return new Double(0.00);
    }
View Full Code Here

            if (o instanceof NumberModel) {
                NumberModel s = (NumberModel) o;
                return new Double( s.getAsNumber().doubleValue() );
            }
            if (o instanceof SimpleNumber) {
                SimpleNumber s = (SimpleNumber) o;
                return new Double( s.getAsNumber().doubleValue() );
            }
            if (o instanceof SimpleScalar) {
                SimpleScalar s = (SimpleScalar) o;
                return new Double( s.getAsString() );
            }
            return new Double( o.toString() );
        }
        return new Double(0.00);
    }
View Full Code Here

                }
               
                if (m_dir == 1) {
                    for (int i = startIndex; i < seqSize; i++) {
                        if (modelsEqual(m_seq.get(i), arg, m_env))
                            return new SimpleNumber(i);
                    }
                } else {
                    for (int i = startIndex; i >= 0; i--) {
                        if (modelsEqual(m_seq.get(i), arg, m_env))
                            return new SimpleNumber(i);
                    }
                }
                return Constants.MINUS_ONE;
            }
View Full Code Here

                else
                    index = s.lastIndexOf(sub);
            } else {
                index = s.indexOf(sub, fidx);
            }
            return new SimpleNumber(index);
        }
View Full Code Here

            final Environment env = Environment.getCurrentEnvironment();
            final ModelComparator comparator = new ModelComparator(env);
            if (reverse) {
                for (int i = startIndex; i > -1; --i) {
                    if (comparator.modelsEqual(sequence.get(i), compareToThis)) {
                        return new SimpleNumber(i);
                    }
                }
            }
            else {
                final int s = sequence.size();
                for (int i = startIndex; i < s; ++i) {
                    if (comparator.modelsEqual(sequence.get(i), compareToThis)) {
                        return new SimpleNumber(i);
                    }
                }
            }
            return new SimpleNumber(-1);
        }
View Full Code Here

        catch(ClassCastException ex) {
            throw TemplateNode.invalidTypeException(model, caller.getTarget(), env, "string or number");
        }
        ArithmeticEngine e = env == null ? caller.getTemplate().getArithmeticEngine() : env.getArithmeticEngine();
        try {
            return new SimpleNumber(e.toNumber(string));
        } catch(NumberFormatException nfe) {
                String mess = "Error: " + caller.getStartLocation()
                + "\nExpecting a number in string here, found: " + string;
                throw new NonNumericalException(mess, env);
            }
View Full Code Here

TOP

Related Classes of freemarker.template.SimpleNumber

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.