Source Code Cross Referenced for MatrixSeries.java in  » Chart » jfreechart » org » jfree » data » xy » 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 » Chart » jfreechart » org.jfree.data.xy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ===========================================================
002:         * JFreeChart : a free chart library for the Java(tm) platform
003:         * ===========================================================
004:         *
005:         * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006:         *
007:         * Project Info:  http://www.jfree.org/jfreechart/index.html
008:         *
009:         * This library is free software; you can redistribute it and/or modify it 
010:         * under the terms of the GNU Lesser General Public License as published by 
011:         * the Free Software Foundation; either version 2.1 of the License, or 
012:         * (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but 
015:         * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017:         * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022:         * USA.  
023:         *
024:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025:         * in the United States and other countries.]
026:         *
027:         * -----------------
028:         * MatrixSeries.java
029:         * -----------------
030:         * (C) Copyright 2003-2007, by Barak Naveh and Contributors.
031:         *
032:         * Original Author:  Barak Naveh;;
033:         * Contributor(s):   David Gilbert (for Object Refinery Limited);
034:         *                   Zhitao Wang;
035:         *
036:         * $Id: MatrixSeries.java,v 1.5.2.3 2007/02/02 15:14:53 mungady Exp $
037:         *
038:         * Changes
039:         * -------
040:         * 10-Jul-2003 : Version 1 contributed by Barak Naveh (DG);
041:         * 10-Feb-2004 : Fixed Checkstyle complaints (DG);
042:         * 21-May-2004 : Fixed bug 940188 - problem in getItemColumn() and 
043:         *               getItemRow() (DG);
044:         * ------------- JFREECHART 1.0.x ---------------------------------------------
045:         * 27-Nov-2006 : Fixed bug in equals() method (DG);
046:         * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG);
047:         *
048:         */
049:
050:        package org.jfree.data.xy;
051:
052:        import java.io.Serializable;
053:
054:        import org.jfree.data.general.Series;
055:
056:        /**
057:         * Represents a dense matrix M[i,j] where each Mij item of the matrix has a
058:         * value (default is 0).
059:         */
060:        public class MatrixSeries extends Series implements  Serializable {
061:
062:            /** For serialization. */
063:            private static final long serialVersionUID = 7934188527308315704L;
064:
065:            /** Series matrix values */
066:            protected double[][] data;
067:
068:            /**
069:             * Constructs a new matrix series.
070:             * <p>
071:             * By default, all matrix items are initialzed to 0.
072:             * </p>
073:             *
074:             * @param name  series name (<code>null</code> not permitted).
075:             * @param rows  the number of rows.
076:             * @param columns  the number of columns.
077:             */
078:            public MatrixSeries(String name, int rows, int columns) {
079:                super (name);
080:                this .data = new double[rows][columns];
081:                zeroAll();
082:            }
083:
084:            /**
085:             * Returns the number of columns in this matrix series.
086:             *
087:             * @return The number of columns in this matrix series.
088:             */
089:            public int getColumnsCount() {
090:                return this .data[0].length;
091:            }
092:
093:            /**
094:             * Return the matrix item at the specified index.  Note that this method
095:             * creates a new <code>Double</code> instance every time it is called.
096:             *
097:             * @param itemIndex item index.
098:             *
099:             * @return The matrix item at the specified index.
100:             * 
101:             * @see #get(int, int)
102:             */
103:            public Number getItem(int itemIndex) {
104:                int i = getItemRow(itemIndex);
105:                int j = getItemColumn(itemIndex);
106:
107:                Number n = new Double(get(i, j));
108:
109:                return n;
110:            }
111:
112:            /**
113:             * Returns the column of the specified item.
114:             *
115:             * @param itemIndex the index of the item.
116:             *
117:             * @return The column of the specified item.
118:             */
119:            public int getItemColumn(int itemIndex) {
120:                //assert itemIndex >= 0 && itemIndex < getItemCount();
121:                return itemIndex % getColumnsCount();
122:            }
123:
124:            /**
125:             * Returns the number of items in the series.
126:             *
127:             * @return The item count.
128:             */
129:            public int getItemCount() {
130:                return getRowCount() * getColumnsCount();
131:            }
132:
133:            /**
134:             * Returns the row of the specified item.
135:             *
136:             * @param itemIndex the index of the item.
137:             *
138:             * @return The row of the specified item.
139:             */
140:            public int getItemRow(int itemIndex) {
141:                //assert itemIndex >= 0 && itemIndex < getItemCount();
142:                return itemIndex / getColumnsCount();
143:            }
144:
145:            /**
146:             * Returns the number of rows in this matrix series.
147:             *
148:             * @return The number of rows in this matrix series.
149:             */
150:            public int getRowCount() {
151:                return this .data.length;
152:            }
153:
154:            /**
155:             * Returns the value of the specified item in this matrix series.
156:             *
157:             * @param i the row of the item.
158:             * @param j the column of the item.
159:             *
160:             * @return The value of the specified item in this matrix series.
161:             * 
162:             * @see #getItem(int)
163:             * @see #update(int, int, double)
164:             */
165:            public double get(int i, int j) {
166:                return this .data[i][j];
167:            }
168:
169:            /**
170:             * Updates the value of the specified item in this matrix series.
171:             *
172:             * @param i the row of the item.
173:             * @param j the column of the item.
174:             * @param mij the new value for the item.
175:             * 
176:             * @see #get(int, int)
177:             */
178:            public void update(int i, int j, double mij) {
179:                this .data[i][j] = mij;
180:                fireSeriesChanged();
181:            }
182:
183:            /**
184:             * Sets all matrix values to zero and sends a 
185:             * {@link org.jfree.data.general.SeriesChangeEvent} to all registered 
186:             * listeners.
187:             */
188:            public void zeroAll() {
189:                int rows = getRowCount();
190:                int columns = getColumnsCount();
191:
192:                for (int row = 0; row < rows; row++) {
193:                    for (int column = 0; column < columns; column++) {
194:                        this .data[row][column] = 0.0;
195:                    }
196:                }
197:                fireSeriesChanged();
198:            }
199:
200:            /**
201:             * Tests this object instance for equality with an arbitrary object.
202:             * 
203:             * @param obj  the object (<code>null</code> permitted).
204:             * 
205:             * @return A boolean.
206:             */
207:            public boolean equals(Object obj) {
208:                if (obj == this ) {
209:                    return true;
210:                }
211:                if (!(obj instanceof  MatrixSeries)) {
212:                    return false;
213:                }
214:                MatrixSeries that = (MatrixSeries) obj;
215:                if (!(getRowCount() == that.getRowCount())) {
216:                    return false;
217:                }
218:                if (!(getColumnsCount() == that.getColumnsCount())) {
219:                    return false;
220:                }
221:                for (int r = 0; r < getRowCount(); r++) {
222:                    for (int c = 0; c < getColumnsCount(); c++) {
223:                        if (get(r, c) != that.get(r, c)) {
224:                            return false;
225:                        }
226:                    }
227:                }
228:                return super.equals(obj);
229:            }
230:
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.