1 28 package net.sf.jasperreports.engine.fill; 29 30 import java.util.HashSet ; 31 import java.util.Set ; 32 33 34 38 public class JRDistinctCountExtendedIncrementerFactory extends JRAbstractExtendedIncrementerFactory 39 { 40 41 42 45 private static JRDistinctCountExtendedIncrementerFactory mainInstance = new JRDistinctCountExtendedIncrementerFactory(); 46 47 48 51 public JRDistinctCountExtendedIncrementerFactory() 52 { 53 } 54 55 56 59 public static JRDistinctCountExtendedIncrementerFactory getInstance() 60 { 61 return mainInstance; 62 } 63 64 65 68 public JRExtendedIncrementer getExtendedIncrementer(byte calculation) 69 { 70 return new JRDistinctCountExtendedIncrementer(); 71 } 72 73 74 public static JRExtendedIncrementerFactory getFactory (Class valueClass) 75 { 76 return JRDistinctCountExtendedIncrementerFactory.getInstance(); 77 } 78 } 79 80 81 84 class JRDistinctCountExtendedIncrementer extends JRAbstractExtendedIncrementer 85 { 86 87 private DistinctCountHolder lastHolder = new DistinctCountHolder(); 88 89 90 93 public JRDistinctCountExtendedIncrementer() 94 { 95 } 96 97 98 101 public Object increment( 102 JRCalculable variable, 103 Object expressionValue, 104 AbstractValueProvider valueProvider 105 ) 106 { 107 DistinctCountHolder holder = (DistinctCountHolder)variable.getIncrementedValue(); 108 109 if (holder == null) 110 { 111 holder = lastHolder; 112 } 113 else 114 { 115 lastHolder = holder; 116 } 117 118 holder.addLastValue(); 119 120 return new DistinctCountHolder(holder, expressionValue); 121 } 122 123 124 127 public Object combine(JRCalculable calculable1, JRCalculable calculable2, AbstractValueProvider valueProvider) 128 { 129 Set distinctValues = new HashSet (); 130 131 DistinctCountHolder holder1 = (DistinctCountHolder)calculable1.getValue(); 132 if (holder1 != null) 133 { 134 distinctValues.addAll(holder1.getDistinctValues()); 135 if (holder1.getLastValue() != null) 136 distinctValues.add(holder1.getLastValue()); 137 } 138 139 DistinctCountHolder holder2 = (DistinctCountHolder)calculable2.getValue(); 140 if (holder2 != null) 141 { 142 distinctValues.addAll(holder2.getDistinctValues()); 143 if (holder2.getLastValue() != null) 144 distinctValues.add(holder2.getLastValue()); 145 } 146 147 return new DistinctCountHolder(distinctValues); 148 } 149 150 151 154 public Object initialValue() 155 { 156 return null; 157 } 158 159 160 } 161 | Popular Tags |