KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > charts > util > DefaultXYZDataset


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.charts.util;
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33
34 import net.sf.jasperreports.engine.JRConstants;
35
36 import org.jfree.data.xy.AbstractXYZDataset;
37 import org.jfree.data.xy.XYZDataset;
38
39 /**
40  * @author Flavius Sana (flavius_sana@users.sourceforge.net)
41  * @version $Id: DefaultXYZDataset.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
42  */

43 public class DefaultXYZDataset extends AbstractXYZDataset implements XYZDataset
44 {
45     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
46     
47     /**
48      *
49      */

50     List JavaDoc dataset = null;
51     
52     /**
53      *
54      */

55     public DefaultXYZDataset()
56     {
57         dataset = new ArrayList JavaDoc();
58     }
59     
60     /**
61      *
62      */

63     public void addValue( Comparable JavaDoc series, Number JavaDoc xValue, Number JavaDoc yValue, Number JavaDoc zValue ){
64         boolean found = false;
65         for( Iterator JavaDoc it = dataset.iterator(); it.hasNext(); ){
66             XYZElement element = (XYZElement)it.next();
67             if( element.getSeries().equals( series )){
68                 element.addElement( xValue, yValue, zValue );
69                 found = true;
70             }
71         }
72
73         if( !found ){
74             XYZElement element = new XYZElement();
75             element.setSeries( series );
76             element.addElement( xValue, yValue, zValue );
77
78             dataset.add( element );
79         }
80     }
81     
82     /**
83      *
84      */

85     public int getSeriesCount() {
86         int retVal = 0;
87         if( dataset != null ){
88             retVal = dataset.size();
89         }
90         
91         return retVal;
92     }
93
94     /**
95      *
96      */

97     public Number JavaDoc getZ(int series, int index ) {
98         Number JavaDoc retVal = null;
99         if( dataset != null ){
100             if( series < getSeriesCount() ){
101                 XYZElement element = (XYZElement)dataset.get( series );
102                 retVal = element.getZElement( index );
103             }
104         }
105         return retVal;
106     }
107
108     /**
109      *
110      */

111     public int getItemCount(int series ) {
112         int retVal = 0;
113         if( dataset != null ){
114             if( series < getSeriesCount() ){
115                 XYZElement element = (XYZElement)dataset.get( series );
116                 retVal = element.getCount();
117             }
118         }
119         return retVal;
120     }
121
122     /**
123      *
124      */

125     public Number JavaDoc getX(int series, int index ) {
126         Number JavaDoc retVal = null;
127         if( dataset != null ){
128             if( series < getSeriesCount() ){
129                 XYZElement element = (XYZElement)dataset.get( series );
130                 retVal = element.getXElement( index );
131             }
132         }
133         return retVal;
134     }
135     
136     /**
137      *
138      */

139     public Number JavaDoc getY(int series, int index ) {
140         Number JavaDoc retVal = null;
141         if( dataset != null ){
142             if( series < getSeriesCount() ){
143                 XYZElement element = (XYZElement)dataset.get( series );
144                 retVal = element.getYElement( index );
145             }
146         }
147         return retVal;
148     }
149
150     /**
151      *
152      */

153     public Comparable JavaDoc getSeriesKey(int index) {
154         String JavaDoc retVal = null;
155         if( dataset != null ){
156             if( index < getSeriesCount() ){
157                 XYZElement element = (XYZElement)dataset.get( index );
158                 retVal = element.getSeries().toString();
159             }
160         }
161         return retVal;
162     }
163
164 }
165
Popular Tags