1 28 package net.sf.jasperreports.engine.fill; 29 30 import net.sf.jasperreports.engine.JRVariable; 31 32 33 37 public class JRComparableIncrementerFactory extends JRAbstractExtendedIncrementerFactory 38 { 39 40 41 44 private static JRComparableIncrementerFactory mainInstance = new JRComparableIncrementerFactory(); 45 46 47 50 private JRComparableIncrementerFactory() 51 { 52 } 53 54 55 58 public static JRComparableIncrementerFactory 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_LOWEST : 74 { 75 incrementer = JRComparableLowestIncrementer.getInstance(); 76 break; 77 } 78 case JRVariable.CALCULATION_HIGHEST : 79 { 80 incrementer = JRComparableHighestIncrementer.getInstance(); 81 break; 82 } 83 case JRVariable.CALCULATION_SYSTEM : 84 case JRVariable.CALCULATION_NOTHING : 85 case JRVariable.CALCULATION_COUNT : 86 case JRVariable.CALCULATION_SUM : 87 case JRVariable.CALCULATION_AVERAGE : 88 case JRVariable.CALCULATION_STANDARD_DEVIATION : 89 case JRVariable.CALCULATION_VARIANCE : 90 case JRVariable.CALCULATION_FIRST : 91 case JRVariable.CALCULATION_DISTINCT_COUNT : 92 default : 93 { 94 incrementer = JRDefaultIncrementerFactory.getInstance().getExtendedIncrementer(calculation); 95 break; 96 } 97 } 98 99 return incrementer; 100 } 101 } 102 103 104 107 class JRComparableLowestIncrementer extends JRAbstractExtendedIncrementer 108 { 109 112 private static JRComparableLowestIncrementer mainInstance = new JRComparableLowestIncrementer(); 113 114 117 private JRComparableLowestIncrementer() 118 { 119 } 120 121 124 public static JRComparableLowestIncrementer getInstance() 125 { 126 return mainInstance; 127 } 128 129 132 public Object increment( 133 JRCalculable variable, 134 Object expressionValue, 135 AbstractValueProvider valueProvider 136 ) 137 { 138 Comparable value = (Comparable )variable.getIncrementedValue(); 139 Comparable newValue = (Comparable )expressionValue; 140 141 if ( 142 value != null && !variable.isInitialized() && 143 (newValue == null || value.compareTo(newValue) < 0) 144 ) 145 { 146 newValue = value; 147 } 148 149 return newValue; 150 } 151 152 153 public Object initialValue() 154 { 155 return null; 156 } 157 } 158 159 160 163 class JRComparableHighestIncrementer extends JRAbstractExtendedIncrementer 164 { 165 168 private static JRComparableHighestIncrementer mainInstance = new JRComparableHighestIncrementer(); 169 170 173 private JRComparableHighestIncrementer() 174 { 175 } 176 177 180 public static JRComparableHighestIncrementer getInstance() 181 { 182 return mainInstance; 183 } 184 185 188 public Object increment( 189 JRCalculable variable, 190 Object expressionValue, 191 AbstractValueProvider valueProvider 192 ) 193 { 194 Comparable value = (Comparable )variable.getIncrementedValue(); 195 Comparable newValue = (Comparable )expressionValue; 196 197 if ( 198 value != null && !variable.isInitialized() && 199 (newValue == null || value.compareTo(newValue) > 0) 200 ) 201 { 202 newValue = value; 203 } 204 205 return newValue; 206 } 207 208 209 public Object initialValue() 210 { 211 return null; 212 } 213 } 214 | Popular Tags |