1 28 package net.sf.jasperreports.engine.fill; 29 30 import net.sf.jasperreports.engine.JRVariable; 31 32 33 37 public class JRDefaultIncrementerFactory extends JRAbstractExtendedIncrementerFactory 38 { 39 40 41 44 private static JRDefaultIncrementerFactory mainInstance = new JRDefaultIncrementerFactory(); 45 46 47 50 private JRDefaultIncrementerFactory() 51 { 52 } 53 54 55 58 public static JRDefaultIncrementerFactory getInstance() 59 { 60 return mainInstance; 61 } 62 63 64 67 public JRExtendedIncrementer getExtendedIncrementer(byte calculation) 68 { 69 JRExtendedIncrementer incrementer = null; 70 71 switch (calculation) 72 { 73 case JRVariable.CALCULATION_SYSTEM : 74 { 75 incrementer = JRDefaultSystemIncrementer.getInstance(); 76 break; 77 } 78 case JRVariable.CALCULATION_FIRST : 79 { 80 incrementer = JRDefaultFirstIncrementer.getInstance(); 81 break; 82 } 83 case JRVariable.CALCULATION_NOTHING : 84 case JRVariable.CALCULATION_COUNT : 85 case JRVariable.CALCULATION_SUM : 86 case JRVariable.CALCULATION_AVERAGE : 87 case JRVariable.CALCULATION_LOWEST : 88 case JRVariable.CALCULATION_HIGHEST : 89 case JRVariable.CALCULATION_STANDARD_DEVIATION : 90 case JRVariable.CALCULATION_VARIANCE : 91 case JRVariable.CALCULATION_DISTINCT_COUNT : 92 default : 93 { 94 incrementer = JRDefaultNothingIncrementer.getInstance(); 95 break; 96 } 97 } 98 99 return incrementer; 100 } 101 102 103 public static JRExtendedIncrementerFactory getFactory (Class valueClass) 104 { 105 JRExtendedIncrementerFactory factory; 106 107 if (java.math.BigDecimal .class.equals(valueClass)) 108 { 109 factory = JRBigDecimalIncrementerFactory.getInstance(); 110 } 111 else if ( 112 java.lang.Number .class.equals(valueClass) 113 || java.lang.Double .class.equals(valueClass) 114 ) 115 { 116 factory = JRDoubleIncrementerFactory.getInstance(); 117 } 118 else if (java.lang.Float .class.equals(valueClass)) 119 { 120 factory = JRFloatIncrementerFactory.getInstance(); 121 } 122 else if (java.lang.Long .class.equals(valueClass)) 123 { 124 factory = JRLongIncrementerFactory.getInstance(); 125 } 126 else if (java.lang.Integer .class.equals(valueClass)) 127 { 128 factory = JRIntegerIncrementerFactory.getInstance(); 129 } 130 else if (java.lang.Short .class.equals(valueClass)) 131 { 132 factory = JRShortIncrementerFactory.getInstance(); 133 } 134 else if (java.lang.Byte .class.equals(valueClass)) 135 { 136 factory = JRByteIncrementerFactory.getInstance(); 137 } 138 else if (java.lang.Comparable .class.isAssignableFrom(valueClass)) 139 { 140 factory = JRComparableIncrementerFactory.getInstance(); 141 } 142 else 143 { 144 factory = JRDefaultIncrementerFactory.getInstance(); 145 } 146 147 return factory; 148 } 149 } 150 151 152 155 class JRDefaultNothingIncrementer extends JRAbstractExtendedIncrementer 156 { 157 158 159 162 private static JRDefaultNothingIncrementer mainInstance = new JRDefaultNothingIncrementer(); 163 164 165 168 private JRDefaultNothingIncrementer() 169 { 170 } 171 172 173 176 public static JRDefaultNothingIncrementer getInstance() 177 { 178 return mainInstance; 179 } 180 181 182 185 public Object increment( 186 JRCalculable variable, 187 Object expressionValue, 188 AbstractValueProvider valueProvider 189 ) 190 { 191 return expressionValue; 192 } 193 194 195 public Object combine(JRCalculable calculable, JRCalculable calculableValue, AbstractValueProvider valueProvider) 196 { 197 if (!calculableValue.isInitialized()) 198 { 199 return calculableValue.getValue(); 200 } 201 202 if (!calculable.isInitialized()) 203 { 204 return calculable.getValue(); 205 } 206 207 return null; 208 } 209 210 public Object initialValue() 211 { 212 return null; 213 } 214 } 215 216 217 220 class JRDefaultSystemIncrementer extends JRAbstractExtendedIncrementer 221 { 222 225 private static JRDefaultSystemIncrementer mainInstance = new JRDefaultSystemIncrementer(); 226 227 230 private JRDefaultSystemIncrementer() 231 { 232 } 233 234 237 public static JRDefaultSystemIncrementer getInstance() 238 { 239 return mainInstance; 240 } 241 242 245 public Object increment( 246 JRCalculable variable, 247 Object expressionValue, 248 AbstractValueProvider valueProvider 249 ) 250 { 251 return variable.getValue(); 252 } 253 254 public Object combine(JRCalculable calculable, JRCalculable calculableValue, AbstractValueProvider valueProvider) 255 { 256 return calculable.getValue(); 257 } 258 259 public Object initialValue() 260 { 261 return null; 262 } 263 } 264 265 class JRDefaultFirstIncrementer extends JRAbstractExtendedIncrementer 266 { 267 private static final JRDefaultFirstIncrementer instance = new JRDefaultFirstIncrementer(); 268 269 private JRDefaultFirstIncrementer() 270 { 271 } 272 273 public static JRDefaultFirstIncrementer getInstance() 274 { 275 return instance; 276 } 277 278 public Object initialValue() 279 { 280 return null; 281 } 282 283 public Object combine(JRCalculable calculable, JRCalculable calculableValue, AbstractValueProvider valueProvider) 284 { 285 if (!calculable.isInitialized()) 286 { 287 return calculable.getValue(); 288 } 289 290 if (!calculableValue.isInitialized()) 291 { 292 return calculableValue.getValue(); 293 } 294 295 return null; 296 } 297 298 public Object increment(JRCalculable calculable, Object expressionValue, AbstractValueProvider valueProvider) 299 { 300 if (calculable.isInitialized()) 301 { 302 return expressionValue; 303 } 304 305 return calculable.getIncrementedValue(); 306 } 307 } 308 | Popular Tags |