Source Code Cross Referenced for StaticDataRow.java in  » Report » pentaho-report » org » jfree » report » states » datarow » 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.states.datarow 
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:         * StaticDataRow.java
027:         * ------------
028:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029:         */package org.jfree.report.states.datarow;
030:
031:        import java.util.Collections;
032:        import java.util.HashMap;
033:        import java.util.Map;
034:
035:        import org.jfree.report.DataRow;
036:        import org.jfree.report.util.IntegerCache;
037:
038:        /**
039:         * This is a static datarow holding a value for each name in the datarow. This
040:         * datarow does not hold dataflags and thus does not track the changes done to
041:         * the data inside.
042:         * <p/>
043:         * The StaticDataRow is a derived view and is used to provide a safe collection
044:         * of the values of the previous datarow.
045:         *
046:         * @author Thomas Morgner
047:         */
048:        public class StaticDataRow implements  DataRow {
049:            private String[] names;
050:            private Object[] values;
051:            private Map nameCache;
052:
053:            protected StaticDataRow() {
054:            }
055:
056:            protected StaticDataRow(final StaticDataRow dataRow) {
057:                if (dataRow == null) {
058:                    throw new NullPointerException();
059:                }
060:
061:                this .nameCache = dataRow.nameCache;
062:                this .names = dataRow.names;
063:                this .values = dataRow.values;
064:            }
065:
066:            public StaticDataRow(final DataRow dataRow) {
067:                if (dataRow == null) {
068:                    throw new NullPointerException();
069:                }
070:
071:                final HashMap nameCache = new HashMap();
072:                synchronized (dataRow) {
073:                    final int columnCount = dataRow.getColumnCount();
074:                    this .names = new String[columnCount];
075:                    this .values = new Object[dataRow.getColumnCount()];
076:                    for (int i = 0; i < columnCount; i++) {
077:                        names[i] = dataRow.getColumnName(i);
078:                        values[i] = dataRow.get(i);
079:                        if (names[i] != null) {
080:                            nameCache.put(names[i], IntegerCache.getInteger(i));
081:                        }
082:                    }
083:                }
084:                this .nameCache = Collections.unmodifiableMap(nameCache);
085:            }
086:
087:            public StaticDataRow(final String[] names, final Object[] values) {
088:                setData(names, values);
089:            }
090:
091:            protected void setData(final String[] names, final Object[] values) {
092:                if (names == null) {
093:                    throw new NullPointerException();
094:                }
095:                if (values == null) {
096:                    throw new NullPointerException();
097:                }
098:                final int length;
099:                if (names.length == values.length) {
100:                    length = names.length;
101:                    this .names = (String[]) names.clone();
102:                    this .values = (Object[]) values.clone();
103:                } else {
104:                    length = Math.min(names.length, values.length);
105:                    this .names = new String[length];
106:                    this .values = new Object[length];
107:                    System.arraycopy(names, 0, this .names, 0, length);
108:                    System.arraycopy(values, 0, this .values, 0, length);
109:                }
110:
111:                final HashMap nameCache = new HashMap();
112:                for (int i = 0; i < length; i++) {
113:                    final String name = names[i];
114:                    if (name != null) {
115:                        nameCache.put(name, IntegerCache.getInteger(i));
116:                    }
117:                }
118:                this .nameCache = Collections.unmodifiableMap(nameCache);
119:            }
120:
121:            protected void updateData(final Object[] values) {
122:                if (values.length != this .values.length) {
123:                    throw new IllegalArgumentException(
124:                            "You should preserve the number of columns.");
125:                }
126:
127:                this .values = (Object[]) values.clone();
128:            }
129:
130:            /**
131:             * Returns the value of the expression or column in the tablemodel using the
132:             * given column number as index. For functions and expressions, the
133:             * <code>getValue()</code> method is called and for columns from the
134:             * tablemodel the tablemodel method <code>getValueAt(row, column)</code> gets
135:             * called.
136:             *
137:             * @param col the item index.
138:             * @return the value.
139:             * @throws IllegalStateException if the datarow detected a deadlock.
140:             */
141:            public Object get(final int col) {
142:                return values[col];
143:            }
144:
145:            /**
146:             * Returns the value of the function, expression or column using its specific
147:             * name. The given name is translated into a valid column number and the the
148:             * column is queried. For functions and expressions, the
149:             * <code>getValue()</code> method is called and for columns from the
150:             * tablemodel the tablemodel method <code>getValueAt(row, column)</code> gets
151:             * called.
152:             *
153:             * @param col the item index.
154:             * @return the value.
155:             * @throws IllegalStateException if the datarow detected a deadlock.
156:             */
157:            public Object get(final String col) {
158:                final Integer idx = (Integer) nameCache.get(col);
159:                if (idx == null) {
160:                    return null;
161:                }
162:                return values[idx.intValue()];
163:            }
164:
165:            /**
166:             * Returns the name of the column, expression or function. For columns from
167:             * the tablemodel, the tablemodels <code>getColumnName</code> method is
168:             * called. For functions, expressions and report properties the assigned name
169:             * is returned.
170:             *
171:             * @param col the item index.
172:             * @return the name.
173:             */
174:            public String getColumnName(final int col) {
175:                return names[col];
176:            }
177:
178:            /**
179:             * Returns the number of columns, expressions and functions and marked
180:             * ReportProperties in the report.
181:             *
182:             * @return the item count.
183:             */
184:            public int getColumnCount() {
185:                return values.length;
186:            }
187:
188:            /**
189:             * Returns the column position of the column, expression or function with the
190:             * given name or -1 if the given name does not exist in this DataRow.
191:             *
192:             * @param name the item name.
193:             * @return the item index.
194:             */
195:            public int findColumn(final String name) {
196:                final Integer o = (Integer) nameCache.get(name);
197:                if (o != null) {
198:                    return o.intValue();
199:                }
200:                return -1;
201:            }
202:
203:            public boolean isChanged(final String name) {
204:                return false;
205:            }
206:
207:            public boolean isChanged(final int index) {
208:                return false;
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.