Source Code Cross Referenced for JRShortIncrementerFactory.java in  » Report » jasperreports-2.0.1 » net » sf » jasperreports » engine » fill » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » jasperreports 2.0.1 » net.sf.jasperreports.engine.fill 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ============================================================================
003:         * GNU Lesser General Public License
004:         * ============================================================================
005:         *
006:         * JasperReports - Free Java report-generating library.
007:         * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008:         * 
009:         * This library is free software; you can redistribute it and/or
010:         * modify it under the terms of the GNU Lesser General Public
011:         * License as published by the Free Software Foundation; either
012:         * version 2.1 of the License, or (at your option) any later version.
013:         * 
014:         * This library is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
017:         * Lesser General Public License for more details.
018:         * 
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library; if not, write to the Free Software
021:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
022:         * 
023:         * JasperSoft Corporation
024:         * 303 Second Street, Suite 450 North
025:         * San Francisco, CA 94107
026:         * http://www.jaspersoft.com
027:         */
028:        package net.sf.jasperreports.engine.fill;
029:
030:        import net.sf.jasperreports.engine.JRVariable;
031:
032:        /**
033:         * @author Teodor Danciu (teodord@users.sourceforge.net)
034:         * @version $Id: JRShortIncrementerFactory.java 1347 2006-07-19 12:31:07Z teodord $
035:         */
036:        public class JRShortIncrementerFactory extends
037:                JRAbstractExtendedIncrementerFactory {
038:
039:            /**
040:             *
041:             */
042:            protected static final Short ZERO = new Short((short) 0);
043:
044:            /**
045:             *
046:             */
047:            private static JRShortIncrementerFactory mainInstance = new JRShortIncrementerFactory();
048:
049:            /**
050:             *
051:             */
052:            private JRShortIncrementerFactory() {
053:            }
054:
055:            /**
056:             *
057:             */
058:            public static JRShortIncrementerFactory getInstance() {
059:                return mainInstance;
060:            }
061:
062:            /**
063:             *
064:             */
065:            public JRExtendedIncrementer getExtendedIncrementer(byte calculation) {
066:                JRExtendedIncrementer incrementer = null;
067:
068:                switch (calculation) {
069:                case JRVariable.CALCULATION_COUNT: {
070:                    incrementer = JRShortCountIncrementer.getInstance();
071:                    break;
072:                }
073:                case JRVariable.CALCULATION_SUM: {
074:                    incrementer = JRShortSumIncrementer.getInstance();
075:                    break;
076:                }
077:                case JRVariable.CALCULATION_AVERAGE: {
078:                    incrementer = JRShortAverageIncrementer.getInstance();
079:                    break;
080:                }
081:                case JRVariable.CALCULATION_LOWEST:
082:                case JRVariable.CALCULATION_HIGHEST: {
083:                    incrementer = JRComparableIncrementerFactory.getInstance()
084:                            .getExtendedIncrementer(calculation);
085:                    break;
086:                }
087:                case JRVariable.CALCULATION_STANDARD_DEVIATION: {
088:                    incrementer = JRShortStandardDeviationIncrementer
089:                            .getInstance();
090:                    break;
091:                }
092:                case JRVariable.CALCULATION_VARIANCE: {
093:                    incrementer = JRShortVarianceIncrementer.getInstance();
094:                    break;
095:                }
096:                case JRVariable.CALCULATION_DISTINCT_COUNT: {
097:                    incrementer = JRShortDistinctCountIncrementer.getInstance();
098:                    break;
099:                }
100:                case JRVariable.CALCULATION_SYSTEM:
101:                case JRVariable.CALCULATION_NOTHING:
102:                case JRVariable.CALCULATION_FIRST:
103:                default: {
104:                    incrementer = JRDefaultIncrementerFactory.getInstance()
105:                            .getExtendedIncrementer(calculation);
106:                    break;
107:                }
108:                }
109:
110:                return incrementer;
111:            }
112:
113:        }
114:
115:        /**
116:         *
117:         */
118:        class JRShortCountIncrementer extends JRAbstractExtendedIncrementer {
119:            /**
120:             *
121:             */
122:            private static JRShortCountIncrementer mainInstance = new JRShortCountIncrementer();
123:
124:            /**
125:             *
126:             */
127:            private JRShortCountIncrementer() {
128:            }
129:
130:            /**
131:             *
132:             */
133:            public static JRShortCountIncrementer getInstance() {
134:                return mainInstance;
135:            }
136:
137:            /**
138:             *
139:             */
140:            public Object increment(JRCalculable variable,
141:                    Object expressionValue, AbstractValueProvider valueProvider) {
142:                Number value = (Number) variable.getIncrementedValue();
143:
144:                if (value == null || variable.isInitialized()) {
145:                    value = JRShortIncrementerFactory.ZERO;
146:                }
147:
148:                if (expressionValue == null) {
149:                    return value;
150:                }
151:
152:                return new Short((short) (value.shortValue() + 1));
153:            }
154:
155:            public Object combine(JRCalculable calculable,
156:                    JRCalculable calculableValue,
157:                    AbstractValueProvider valueProvider) {
158:                Number value = (Number) calculable.getIncrementedValue();
159:                Number combineValue = (Number) calculableValue.getValue();
160:
161:                if (value == null || calculable.isInitialized()) {
162:                    value = JRShortIncrementerFactory.ZERO;
163:                }
164:
165:                if (combineValue == null) {
166:                    return value;
167:                }
168:
169:                return new Short((short) (value.shortValue() + combineValue
170:                        .shortValue()));
171:            }
172:
173:            public Object initialValue() {
174:                return JRShortIncrementerFactory.ZERO;
175:            }
176:        }
177:
178:        /**
179:         *
180:         */
181:        class JRShortDistinctCountIncrementer extends
182:                JRAbstractExtendedIncrementer {
183:            /**
184:             *
185:             */
186:            private static JRShortDistinctCountIncrementer mainInstance = new JRShortDistinctCountIncrementer();
187:
188:            /**
189:             *
190:             */
191:            private JRShortDistinctCountIncrementer() {
192:            }
193:
194:            /**
195:             *
196:             */
197:            public static JRShortDistinctCountIncrementer getInstance() {
198:                return mainInstance;
199:            }
200:
201:            /**
202:             *
203:             */
204:            public Object increment(JRCalculable variable,
205:                    Object expressionValue, AbstractValueProvider valueProvider) {
206:                DistinctCountHolder holder = (DistinctCountHolder) valueProvider
207:                        .getValue(variable
208:                                .getHelperVariable(JRCalculable.HELPER_COUNT));
209:
210:                if (variable.isInitialized()) {
211:                    holder.init();
212:                }
213:
214:                return new Short((short) holder.getCount());
215:            }
216:
217:            public Object combine(JRCalculable calculable,
218:                    JRCalculable calculableValue,
219:                    AbstractValueProvider valueProvider) {
220:                DistinctCountHolder holder = (DistinctCountHolder) valueProvider
221:                        .getValue(calculable
222:                                .getHelperVariable(JRCalculable.HELPER_COUNT));
223:
224:                return new Short((short) holder.getCount());
225:            }
226:
227:            public Object initialValue() {
228:                return JRShortIncrementerFactory.ZERO;
229:            }
230:        }
231:
232:        /**
233:         *
234:         */
235:        class JRShortSumIncrementer extends JRAbstractExtendedIncrementer {
236:            /**
237:             *
238:             */
239:            private static JRShortSumIncrementer mainInstance = new JRShortSumIncrementer();
240:
241:            /**
242:             *
243:             */
244:            private JRShortSumIncrementer() {
245:            }
246:
247:            /**
248:             *
249:             */
250:            public static JRShortSumIncrementer getInstance() {
251:                return mainInstance;
252:            }
253:
254:            /**
255:             *
256:             */
257:            public Object increment(JRCalculable variable,
258:                    Object expressionValue, AbstractValueProvider valueProvider) {
259:                Number value = (Number) variable.getIncrementedValue();
260:                Number newValue = (Number) expressionValue;
261:
262:                if (newValue == null) {
263:                    if (variable.isInitialized()) {
264:                        return null;
265:                    }
266:
267:                    return value;
268:                }
269:
270:                if (value == null || variable.isInitialized()) {
271:                    value = JRShortIncrementerFactory.ZERO;
272:                }
273:
274:                return new Short((short) (value.shortValue() + newValue
275:                        .shortValue()));
276:            }
277:
278:            public Object initialValue() {
279:                return JRShortIncrementerFactory.ZERO;
280:            }
281:        }
282:
283:        /**
284:         *
285:         */
286:        class JRShortAverageIncrementer extends JRAbstractExtendedIncrementer {
287:            /**
288:             *
289:             */
290:            private static JRShortAverageIncrementer mainInstance = new JRShortAverageIncrementer();
291:
292:            /**
293:             *
294:             */
295:            private JRShortAverageIncrementer() {
296:            }
297:
298:            /**
299:             *
300:             */
301:            public static JRShortAverageIncrementer getInstance() {
302:                return mainInstance;
303:            }
304:
305:            /**
306:             *
307:             */
308:            public Object increment(JRCalculable variable,
309:                    Object expressionValue, AbstractValueProvider valueProvider) {
310:                if (expressionValue == null) {
311:                    if (variable.isInitialized()) {
312:                        return null;
313:                    }
314:                    return variable.getValue();
315:                }
316:                Number countValue = (Number) valueProvider.getValue(variable
317:                        .getHelperVariable(JRCalculable.HELPER_COUNT));
318:                Number sumValue = (Number) valueProvider.getValue(variable
319:                        .getHelperVariable(JRCalculable.HELPER_SUM));
320:                return new Short((short) (sumValue.shortValue() / countValue
321:                        .shortValue()));
322:            }
323:
324:            public Object initialValue() {
325:                return JRShortIncrementerFactory.ZERO;
326:            }
327:        }
328:
329:        /**
330:         *
331:         */
332:        class JRShortStandardDeviationIncrementer extends
333:                JRAbstractExtendedIncrementer {
334:            /**
335:             *
336:             */
337:            private static JRShortStandardDeviationIncrementer mainInstance = new JRShortStandardDeviationIncrementer();
338:
339:            /**
340:             *
341:             */
342:            private JRShortStandardDeviationIncrementer() {
343:            }
344:
345:            /**
346:             *
347:             */
348:            public static JRShortStandardDeviationIncrementer getInstance() {
349:                return mainInstance;
350:            }
351:
352:            /**
353:             *
354:             */
355:            public Object increment(JRCalculable variable,
356:                    Object expressionValue, AbstractValueProvider valueProvider) {
357:                if (expressionValue == null) {
358:                    if (variable.isInitialized()) {
359:                        return null;
360:                    }
361:                    return variable.getValue();
362:                }
363:                Number varianceValue = (Number) valueProvider.getValue(variable
364:                        .getHelperVariable(JRCalculable.HELPER_VARIANCE));
365:                return new Short((short) Math.sqrt(varianceValue.doubleValue()));
366:            }
367:
368:            public Object initialValue() {
369:                return JRShortIncrementerFactory.ZERO;
370:            }
371:        }
372:
373:        /**
374:         *
375:         */
376:        class JRShortVarianceIncrementer extends JRAbstractExtendedIncrementer {
377:            /**
378:             *
379:             */
380:            private static JRShortVarianceIncrementer mainInstance = new JRShortVarianceIncrementer();
381:
382:            /**
383:             *
384:             */
385:            private JRShortVarianceIncrementer() {
386:            }
387:
388:            /**
389:             *
390:             */
391:            public static JRShortVarianceIncrementer getInstance() {
392:                return mainInstance;
393:            }
394:
395:            /**
396:             *
397:             */
398:            public Object increment(JRCalculable variable,
399:                    Object expressionValue, AbstractValueProvider valueProvider) {
400:                Number value = (Number) variable.getIncrementedValue();
401:                Number newValue = (Number) expressionValue;
402:
403:                if (newValue == null) {
404:                    if (variable.isInitialized()) {
405:                        return null;
406:                    }
407:                    return value;
408:                } else if (value == null || variable.isInitialized()) {
409:                    return JRShortIncrementerFactory.ZERO;
410:                } else {
411:                    Number countValue = (Number) valueProvider
412:                            .getValue(variable
413:                                    .getHelperVariable(JRCalculable.HELPER_COUNT));
414:                    Number sumValue = (Number) valueProvider.getValue(variable
415:                            .getHelperVariable(JRCalculable.HELPER_SUM));
416:                    return new Short(
417:                            (short) ((countValue.shortValue() - 1)
418:                                    * value.shortValue()
419:                                    / countValue.shortValue() + (sumValue
420:                                    .shortValue()
421:                                    / countValue.shortValue() - newValue
422:                                    .shortValue())
423:                                    * (sumValue.shortValue()
424:                                            / countValue.shortValue() - newValue
425:                                            .shortValue())
426:                                    / (countValue.shortValue() - 1)));
427:                }
428:            }
429:
430:            public Object combine(JRCalculable calculable,
431:                    JRCalculable calculableValue,
432:                    AbstractValueProvider valueProvider) {
433:                Number value = (Number) calculable.getIncrementedValue();
434:
435:                if (calculableValue.getValue() == null) {
436:                    if (calculable.isInitialized()) {
437:                        return null;
438:                    }
439:
440:                    return value;
441:                } else if (value == null || calculable.isInitialized()) {
442:                    return new Short(((Number) calculableValue
443:                            .getIncrementedValue()).shortValue());
444:                }
445:
446:                float v1 = value.floatValue();
447:                float c1 = ((Number) valueProvider.getValue(calculable
448:                        .getHelperVariable(JRCalculable.HELPER_COUNT)))
449:                        .floatValue();
450:                float s1 = ((Number) valueProvider.getValue(calculable
451:                        .getHelperVariable(JRCalculable.HELPER_SUM)))
452:                        .floatValue();
453:
454:                float v2 = ((Number) calculableValue.getIncrementedValue())
455:                        .floatValue();
456:                float c2 = ((Number) valueProvider.getValue(calculableValue
457:                        .getHelperVariable(JRCalculable.HELPER_COUNT)))
458:                        .floatValue();
459:                float s2 = ((Number) valueProvider.getValue(calculableValue
460:                        .getHelperVariable(JRCalculable.HELPER_SUM)))
461:                        .floatValue();
462:
463:                c1 -= c2;
464:                s1 -= s2;
465:
466:                float c = c1 + c2;
467:
468:                return new Short((short) (c1 / c * v1 + c2 / c * v2 + c2 / c1
469:                        * s1 / c * s1 / c + c1 / c2 * s2 / c * s2 / c - 2 * s1
470:                        / c * s2 / c));
471:            }
472:
473:            public Object initialValue() {
474:                return JRShortIncrementerFactory.ZERO;
475:            }
476:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.