Source Code Cross Referenced for ItemMinFunction.java in  » Report » pentaho-report » org » jfree » report » function » 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 » pentaho report » org.jfree.report.function 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * ===========================================
003:         * JFreeReport : a free Java reporting library
004:         * ===========================================
005:         *
006:         * Project Info:  http://reporting.pentaho.org/
007:         *
008:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009:         *
010:         * This library is free software; you can redistribute it and/or modify it under the terms
011:         * of the GNU Lesser General Public License as published by the Free Software Foundation;
012:         * either 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, but WITHOUT ANY WARRANTY;
015:         * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         * See the GNU Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public License along with this
019:         * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         *
022:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023:         * in the United States and other countries.]
024:         *
025:         * ------------
026:         * ItemMinFunction.java
027:         * ------------
028:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029:         */package org.jfree.report.function;
030:
031:        import org.jfree.report.Group;
032:        import org.jfree.report.event.ReportEvent;
033:        import org.jfree.util.Log;
034:
035:        /**
036:         * A report function that calculates the minimum value of one field (column) from the
037:         * data-row. The function can be used in two ways: <ul> <li>to calculate a minimum value
038:         * for the entire report;</li> <li>to calculate a minimum value within a particular
039:         * group;</li> </ul> This function expects its input values to be either java.lang.Number
040:         * instances or Strings that can be parsed to java.lang.Number instances using a
041:         * java.text.DecimalFormat.
042:         * <p/>
043:         * The function undestands two parameters, the <code>field</code> parameter is required
044:         * and denotes the name of an ItemBand-field which gets summed up.
045:         * <p/>
046:         * The parameter <code>group</code> denotes the name of a group. When this group is
047:         * started, the counter gets reseted to null.
048:         *
049:         * @author Thomas Morgner
050:         */
051:        public class ItemMinFunction extends AbstractFunction {
052:            /**
053:             * The minimum value.
054:             */
055:            private transient Comparable min;
056:            /**
057:             * The name of the group on which to reset the count. This can be set to null to compute the minimum for the whole
058:             * report.
059:             */
060:            private String group;
061:            /**
062:             * The name of the field from where to read the values.
063:             */
064:            private String field;
065:
066:            /**
067:             * Constructs an unnamed function. Make sure to set a Name or function initialisation
068:             * will fail.
069:             */
070:            public ItemMinFunction() {
071:                min = null;
072:            }
073:
074:            /**
075:             * Constructs a named function. <P> The field must be defined before using the
076:             * function.
077:             *
078:             * @param name The function name.
079:             */
080:            public ItemMinFunction(final String name) {
081:                this ();
082:                setName(name);
083:            }
084:
085:            /**
086:             * Receives notification that a new report is about to start. <P> Does nothing.
087:             *
088:             * @param event Information about the event.
089:             */
090:            public void reportInitialized(final ReportEvent event) {
091:                this .min = null;
092:            }
093:
094:            /**
095:             * Receives notification that a new group is about to start.  If this is the group
096:             * defined for the function, then the minimum value is reset to zero.
097:             *
098:             * @param event Information about the event.
099:             */
100:            public void groupStarted(final ReportEvent event) {
101:                final String mygroup = getGroup();
102:                if (mygroup == null) {
103:                    return;
104:                }
105:
106:                final Group group = event.getReport().getGroup(
107:                        event.getState().getCurrentGroupIndex());
108:                if (getGroup().equals(group.getName())) {
109:                    this .min = null;
110:                }
111:            }
112:
113:            /**
114:             * Returns the group name.
115:             *
116:             * @return The group name.
117:             */
118:            public String getGroup() {
119:                return group;
120:            }
121:
122:            /**
123:             * Sets the group name. <P> If a group is defined, the minimum value is reset to zero at
124:             * the start of every instance of this group.
125:             *
126:             * @param name the group name (null permitted).
127:             */
128:            public void setGroup(final String name) {
129:                this .group = name;
130:            }
131:
132:            /**
133:             * Returns the field used by the function. The field name corresponds to a column name in the report's data-row.
134:             *
135:             * @return The field name.
136:             */
137:            public String getField() {
138:                return field;
139:            }
140:
141:            /**
142:             * Sets the field name for the function. The field name corresponds to a column name in the report's data-row.
143:             *
144:             * @param field the field name.
145:             */
146:            public void setField(final String field) {
147:                this .field = field;
148:            }
149:
150:            /**
151:             * Receives notification that a row of data is being processed.  Reads the data from the
152:             * field defined for this function and calculates the minimum value.
153:             *
154:             * @param event Information about the event.
155:             */
156:            public void itemsAdvanced(final ReportEvent event) {
157:                final Object fieldValue = event.getDataRow().get(getField());
158:                if (fieldValue instanceof  Comparable == false) {
159:                    return;
160:                }
161:                try {
162:                    final Comparable compare = (Comparable) fieldValue;
163:                    if (min == null) {
164:                        min = compare;
165:                    } else if (min.compareTo(compare) > 0) {
166:                        min = compare;
167:                    }
168:                } catch (Exception e) {
169:                    Log
170:                            .error("ItemMinFunction.advanceItems(): problem adding number.");
171:                }
172:            }
173:
174:            /**
175:             * Returns the function value, in this case the running total of a specific column in
176:             * the report's data row.
177:             *
178:             * @return The function value.
179:             */
180:            public Object getValue() {
181:                return min;
182:            }
183:
184:            /**
185:             * Return a completly separated copy of this function. The copy does no longer share any
186:             * changeable objects with the original function.
187:             *
188:             * @return a copy of this function.
189:             */
190:            public Expression getInstance() {
191:                final ItemMinFunction function = (ItemMinFunction) super
192:                        .getInstance();
193:                function.min = null;
194:                return function;
195:            }
196:
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.