1 52 53 package freemarker.core; 54 55 import freemarker.template.*; 56 57 63 class NumericalRange implements TemplateSequenceModel, java.io.Serializable { 64 65 private int lower, upper; 66 private boolean descending; 67 68 public NumericalRange(int left, int right) { 69 lower = Math.min(left, right); 70 upper = Math.max(left, right); 71 descending = (left != lower); 72 } 73 74 public TemplateModel get(int i) throws TemplateModelException { 75 int index = descending ? (upper -i) : (lower + i); 76 if (index > upper || index <lower) { 77 throw new TemplateModelException("out of bounds of range"); 78 } 79 return new SimpleNumber(index); 80 } 81 82 public int size() { 83 return 1 + upper - lower; 84 } 85 } 86 87 | Popular Tags |