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.charts.util;
029:
030: import java.util.ArrayList;
031: import java.util.Iterator;
032: import java.util.List;
033:
034: import net.sf.jasperreports.engine.JRConstants;
035:
036: import org.jfree.data.xy.AbstractXYZDataset;
037: import org.jfree.data.xy.XYZDataset;
038:
039: /**
040: * @author Flavius Sana (flavius_sana@users.sourceforge.net)
041: * @version $Id: DefaultXYZDataset.java 1229 2006-04-19 10:27:35Z teodord $
042: */
043: public class DefaultXYZDataset extends AbstractXYZDataset implements
044: XYZDataset {
045: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
046:
047: /**
048: *
049: */
050: List dataset = null;
051:
052: /**
053: *
054: */
055: public DefaultXYZDataset() {
056: dataset = new ArrayList();
057: }
058:
059: /**
060: *
061: */
062: public void addValue(Comparable series, Number xValue,
063: Number yValue, Number zValue) {
064: boolean found = false;
065: for (Iterator it = dataset.iterator(); it.hasNext();) {
066: XYZElement element = (XYZElement) it.next();
067: if (element.getSeries().equals(series)) {
068: element.addElement(xValue, yValue, zValue);
069: found = true;
070: }
071: }
072:
073: if (!found) {
074: XYZElement element = new XYZElement();
075: element.setSeries(series);
076: element.addElement(xValue, yValue, zValue);
077:
078: dataset.add(element);
079: }
080: }
081:
082: /**
083: *
084: */
085: public int getSeriesCount() {
086: int retVal = 0;
087: if (dataset != null) {
088: retVal = dataset.size();
089: }
090:
091: return retVal;
092: }
093:
094: /**
095: *
096: */
097: public Number getZ(int series, int index) {
098: Number retVal = null;
099: 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 getX(int series, int index) {
126: Number 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 getY(int series, int index) {
140: Number 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 getSeriesKey(int index) {
154: String 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: }
|