KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > fill > JRDefaultIncrementerFactory


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.fill;
29
30 import net.sf.jasperreports.engine.JRVariable;
31
32
33 /**
34  * @author Teodor Danciu (teodord@users.sourceforge.net)
35  * @version $Id: JRDefaultIncrementerFactory.java 1311 2006-06-23 12:19:26 +0300 (Fri, 23 Jun 2006) teodord $
36  */

37 public class JRDefaultIncrementerFactory extends JRAbstractExtendedIncrementerFactory
38 {
39
40
41     /**
42      *
43      */

44     private static JRDefaultIncrementerFactory mainInstance = new JRDefaultIncrementerFactory();
45
46
47     /**
48      *
49      */

50     private JRDefaultIncrementerFactory()
51     {
52     }
53
54
55     /**
56      *
57      */

58     public static JRDefaultIncrementerFactory getInstance()
59     {
60         return mainInstance;
61     }
62
63
64     /**
65      *
66      */

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 JavaDoc valueClass)
104     {
105         JRExtendedIncrementerFactory factory;
106         
107         if (java.math.BigDecimal JavaDoc.class.equals(valueClass))
108         {
109             factory = JRBigDecimalIncrementerFactory.getInstance();
110         }
111         else if (
112             java.lang.Number JavaDoc.class.equals(valueClass)
113             || java.lang.Double JavaDoc.class.equals(valueClass)
114             )
115         {
116             factory = JRDoubleIncrementerFactory.getInstance();
117         }
118         else if (java.lang.Float JavaDoc.class.equals(valueClass))
119         {
120             factory = JRFloatIncrementerFactory.getInstance();
121         }
122         else if (java.lang.Long JavaDoc.class.equals(valueClass))
123         {
124             factory = JRLongIncrementerFactory.getInstance();
125         }
126         else if (java.lang.Integer JavaDoc.class.equals(valueClass))
127         {
128             factory = JRIntegerIncrementerFactory.getInstance();
129         }
130         else if (java.lang.Short JavaDoc.class.equals(valueClass))
131         {
132             factory = JRShortIncrementerFactory.getInstance();
133         }
134         else if (java.lang.Byte JavaDoc.class.equals(valueClass))
135         {
136             factory = JRByteIncrementerFactory.getInstance();
137         }
138         else if (java.lang.Comparable JavaDoc.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 /**
153  *
154  */

155 class JRDefaultNothingIncrementer extends JRAbstractExtendedIncrementer
156 {
157
158
159     /**
160      *
161      */

162     private static JRDefaultNothingIncrementer mainInstance = new JRDefaultNothingIncrementer();
163
164
165     /**
166      *
167      */

168     private JRDefaultNothingIncrementer()
169     {
170     }
171
172
173     /**
174      *
175      */

176     public static JRDefaultNothingIncrementer getInstance()
177     {
178         return mainInstance;
179     }
180
181
182     /**
183      *
184      */

185     public Object JavaDoc increment(
186         JRCalculable variable,
187         Object JavaDoc expressionValue,
188         AbstractValueProvider valueProvider
189         )
190     {
191         return expressionValue;
192     }
193
194
195     public Object JavaDoc 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 JavaDoc initialValue()
211     {
212         return null;
213     }
214 }
215
216
217 /**
218  *
219  */

220 class JRDefaultSystemIncrementer extends JRAbstractExtendedIncrementer
221 {
222     /**
223      *
224      */

225     private static JRDefaultSystemIncrementer mainInstance = new JRDefaultSystemIncrementer();
226
227     /**
228      *
229      */

230     private JRDefaultSystemIncrementer()
231     {
232     }
233
234     /**
235      *
236      */

237     public static JRDefaultSystemIncrementer getInstance()
238     {
239         return mainInstance;
240     }
241
242     /**
243      *
244      */

245     public Object JavaDoc increment(
246         JRCalculable variable,
247         Object JavaDoc expressionValue,
248         AbstractValueProvider valueProvider
249         )
250     {
251         return variable.getValue();
252     }
253
254     public Object JavaDoc combine(JRCalculable calculable, JRCalculable calculableValue, AbstractValueProvider valueProvider)
255     {
256         return calculable.getValue();
257     }
258     
259     public Object JavaDoc 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 JavaDoc initialValue()
279     {
280         return null;
281     }
282
283     public Object JavaDoc 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 JavaDoc increment(JRCalculable calculable, Object JavaDoc expressionValue, AbstractValueProvider valueProvider)
299     {
300         if (calculable.isInitialized())
301         {
302             return expressionValue;
303         }
304
305         return calculable.getIncrementedValue();
306     }
307 }
308
Popular Tags