1 52 53 package freemarker.core; 54 55 import freemarker.template.*; 56 57 60 61 abstract class NumericalBuiltins { 62 abstract static class NumberBuiltIn extends BuiltIn { 63 TemplateModel _getAsTemplateModel(Environment env) 64 throws TemplateException 65 { 66 TemplateModel model = target.getAsTemplateModel(env); 67 return calculateResult(EvaluationUtil.getNumber(model, target, env), model); 68 } 69 abstract TemplateModel calculateResult(Number num, TemplateModel model); 70 } 71 72 static class byteBI extends NumberBuiltIn { 73 TemplateModel calculateResult(Number num, TemplateModel model) { 74 if (num instanceof Byte ) { 75 return model; 76 } 77 return new SimpleNumber(new Byte (num.byteValue())); 78 } 79 } 80 81 static class shortBI extends NumberBuiltIn { 82 TemplateModel calculateResult(Number num, TemplateModel model) { 83 if (num instanceof Short ) { 84 return model; 85 } 86 return new SimpleNumber(new Short (num.shortValue())); 87 } 88 } 89 90 static class intBI extends NumberBuiltIn { 91 TemplateModel calculateResult(Number num, TemplateModel model) { 92 if (num instanceof Integer ) { 93 return model; 94 } 95 return new SimpleNumber(num.intValue()); 96 } 97 } 98 99 static class longBI extends NumberBuiltIn { 100 TemplateModel calculateResult(Number num, TemplateModel model) { 101 if (num instanceof Long ) { 102 return model; 103 } 104 return new SimpleNumber(num.longValue()); 105 } 106 } 107 108 static class floatBI extends NumberBuiltIn { 109 TemplateModel calculateResult(Number num, TemplateModel model) { 110 if (num instanceof Float ) { 111 return model; 112 } 113 return new SimpleNumber(num.floatValue()); 114 } 115 } 116 117 static class doubleBI extends NumberBuiltIn { 118 TemplateModel calculateResult(Number num, TemplateModel model) { 119 if (num instanceof Double ) { 120 return model; 121 } 122 return new SimpleNumber(num.doubleValue()); 123 } 124 } 125 126 static class cBI extends NumberBuiltIn { 127 128 TemplateModel calculateResult(Number num, TemplateModel model) { 129 return new SimpleScalar(num.toString()); 130 } 131 132 } 133 134 } | Popular Tags |