KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > WaferMapDataset


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either 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, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * --------------------
23  * WaferMapDataset.java
24  * --------------------
25  * (C)opyright 2003, by Robert Redburn and Contributors.
26  *
27  * Original Author: Robert Redburn;
28  * Contributor(s): David Gilbert (for Object Refinery Limited);
29  *
30  * $Id: WaferMapDataset.java,v 1.1 2003/11/25 11:46:41 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 25-Nov-2003 : Version 1 contributed by Robert Redburn (with some modifications to match
35  * style conventions) (DG);
36  *
37  */

38
39 package org.jfree.data;
40
41 import java.util.Set JavaDoc;
42 import java.util.TreeSet JavaDoc;
43
44 /**
45  * A dataset that can be used with the {@link org.jfree.chart.plot.WaferMapPlot} class.
46  *
47  * @author Robert Redburn
48  */

49 public class WaferMapDataset extends AbstractDataset {
50
51     /** Storage structure for the data values (row key is chipx, column is chipy) */
52     private DefaultKeyedValues2D data;
53     
54     /** wafer x dimension */
55     private int maxChipX;
56     
57     /** wafer y dimension */
58     private int maxChipY;
59     
60     /** space to draw between chips */
61     private double chipSpace;
62     
63     /** maximum value in this dataset */
64     private Double JavaDoc maxValue;
65     
66     /** minimum value in this dataset */
67     private Double JavaDoc minValue;
68     
69     /** default chip spacing */
70     private static final double DEFAULT_CHIP_SPACE = 1d;
71     
72     /**
73      * Creates a new dataset using the default chipspace.
74      *
75      * @param maxChipX the wafer x-dimension.
76      * @param maxChipY the wafer y-dimension.
77      */

78     public WaferMapDataset(int maxChipX, int maxChipY) {
79         this(maxChipX, maxChipY, null);
80     }
81     
82     /**
83      * Creates a new dataset.
84      *
85      * @param maxChipX the wafer x-dimension.
86      * @param maxChipY the wafer y-dimension.
87      * @param chipSpace the space between chips.
88      */

89     public WaferMapDataset( int maxChipX, int maxChipY, Number JavaDoc chipSpace) {
90         
91         this.maxValue = new Double JavaDoc(Double.NEGATIVE_INFINITY);
92         this.minValue = new Double JavaDoc(Double.POSITIVE_INFINITY);
93         this.data = new DefaultKeyedValues2D();
94         
95         this.maxChipX = maxChipX;
96         this.maxChipY = maxChipY;
97         if (chipSpace == null) {
98             this.chipSpace = DEFAULT_CHIP_SPACE;
99         }
100         else {
101             this.chipSpace = chipSpace.doubleValue();
102         }
103
104     }
105
106     /**
107      * Sets a value in the dataset.
108      *
109      * @param value the value.
110      * @param chipx the x-index for the chip.
111      * @param chipy the y-index for the chip.
112      */

113     public void addValue(Number JavaDoc value, Comparable JavaDoc chipx, Comparable JavaDoc chipy) {
114         setValue(value, chipx, chipy);
115     }
116     
117     /**
118      * Adds a value to the dataset.
119      *
120      * @param v the value.
121      * @param x the x-index.
122      * @param y the y-index.
123      */

124     public void addValue( int v, int x, int y) {
125         setValue(new Double JavaDoc(v), new Integer JavaDoc(x), new Integer JavaDoc(y));
126     }
127     
128     /**
129      * Sets a value in the dataset and updates min and max value entries.
130      *
131      * @param value the value.
132      * @param chipx the x-index.
133      * @param chipy the y-index.
134      */

135     public void setValue(Number JavaDoc value, Comparable JavaDoc chipx, Comparable JavaDoc chipy) {
136         this.data.setValue( value, chipx, chipy );
137         if( isMaxValue(value) ) this.maxValue = (Double JavaDoc)value;
138         if( isMinValue(value) ) this.minValue = (Double JavaDoc)value;
139     }
140
141     /**
142      * Returns the number of unique values.
143      *
144      * @return the number of unique values.
145      */

146     public int getUniqueValueCount() {
147         return getUniqueValues().size();
148     }
149
150     /**
151      * Returns the set of unique values.
152      *
153      * @return the set of unique values.
154      */

155     public Set JavaDoc getUniqueValues() {
156         Set JavaDoc unique = new TreeSet JavaDoc();
157         //step through all the values and add them to the hash
158
for (int r = 0; r < data.getRowCount(); r++) {
159             for(int c = 0; c < data.getColumnCount(); c++) {
160                 Number JavaDoc value = data.getValue(r, c);
161                 if (value != null) {
162                     unique.add(value);
163                 }
164             }
165         }
166         return unique;
167     }
168
169     /**
170      * Returns the data value for a chip.
171      *
172      * @param chipx the x-index.
173      * @param chipy the y-index.
174      *
175      * @return the data value.
176      */

177     public Number JavaDoc getChipValue(int chipx, int chipy) {
178         return getChipValue(new Integer JavaDoc(chipx), new Integer JavaDoc(chipy));
179     }
180
181     /**
182      * Returns the value for a given chip x and y or null.
183      *
184      * @param chipx the x-index.
185      * @param chipy the y-index.
186      *
187      * @return the data value.
188      */

189     public Number JavaDoc getChipValue(Comparable JavaDoc chipx, Comparable JavaDoc chipy) {
190         int rowIndex = data.getRowIndex(chipx);
191         if (rowIndex < 0) {
192             return null;
193         }
194         int colIndex = data.getColumnIndex(chipy);
195         if (colIndex < 0) {
196             return null;
197         }
198         return this.data.getValue(rowIndex, colIndex);
199     }
200
201     /**
202      * Tests to see if the passed value is larger than the stored maxvalue.
203      *
204      * @param check the number to check.
205      *
206      * @return true or false.
207      */

208     public boolean isMaxValue(Number JavaDoc check) {
209         if (check.doubleValue() > this.maxValue.doubleValue()) {
210             return true;
211         }
212         return false;
213     }
214
215     /**
216      * Tests to see if the passed value is smaller than the stored minvalue.
217      *
218      * @param check the number to check.
219      *
220      * @return true or false.
221      */

222     public boolean isMinValue(Number JavaDoc check) {
223         if (check.doubleValue() < this.minValue.doubleValue()) {
224             return true;
225         }
226         return false;
227     }
228     
229     /**
230      * Returns the maximum value stored in the dataset.
231      *
232      * @return the maximum value.
233      */

234     public Number JavaDoc getMaxValue() {
235         return this.maxValue;
236     }
237     
238     /**
239      * Returns the minimum value stored in the dataset.
240      *
241      * @return the minimum value.
242      */

243     public Number JavaDoc getMinValue() {
244         return this.minValue;
245     }
246
247     /**
248      * Returns the wafer x-dimension.
249      *
250      * @return the number of chips in the x-dimension.
251      */

252     public int getMaxChipX() {
253         return maxChipX;
254     }
255
256     /**
257      * Sets wafer x dimension.
258      *
259      * @param maxChipX the number of chips in the x-dimension.
260      */

261     public void setMaxChipX(int maxChipX) {
262         this.maxChipX = maxChipX;
263     }
264
265     /**
266      * Returns the number of chips in the y-dimension.
267      *
268      * @return the number of chips.
269      */

270     public int getMaxChipY() {
271         return maxChipY;
272     }
273
274     /**
275      * Sets the number of chips in the y-dimension.
276      *
277      * @param maxChipY the number of chips.
278      */

279     public void setMaxChipY(int maxChipY) {
280         this.maxChipY = maxChipY;
281     }
282
283     /**
284      * Returns the space to draw between chips.
285      *
286      * @return the space.
287      */

288     public double getChipSpace() {
289         return chipSpace;
290     }
291
292     /**
293      * Sets the space to draw between chips.
294      *
295      * @param space the space.
296      */

297     public void setChipSpace(double space) {
298         this.chipSpace = space;
299     }
300     
301 }
302
Popular Tags