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 * WaferMapDataset.java
029 * --------------------
030 * (C)opyright 2003-2007, by Robert Redburn and Contributors.
031 *
032 * Original Author: Robert Redburn;
033 * Contributor(s): David Gilbert (for Object Refinery Limited);
034 *
035 * $Id: WaferMapDataset.java,v 1.3.2.2 2007/02/02 15:50:44 mungady Exp $
036 *
037 * Changes
038 * -------
039 * 25-Nov-2003 : Version 1 contributed by Robert Redburn (with some
040 * modifications to match style conventions) (DG);
041 * ------------- JFREECHART 1.0.x ---------------------------------------------
042 * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG);
043 *
044 */
045
046 package org.jfree.data.general;
047
048 import java.util.Set;
049 import java.util.TreeSet;
050
051 import org.jfree.data.DefaultKeyedValues2D;
052
053 /**
054 * A dataset that can be used with the {@link org.jfree.chart.plot.WaferMapPlot}
055 * class.
056 */
057 public class WaferMapDataset extends AbstractDataset {
058
059 /**
060 * Storage structure for the data values (row key is chipx, column is
061 * chipy)
062 */
063 private DefaultKeyedValues2D data;
064
065 /** wafer x dimension */
066 private int maxChipX;
067
068 /** wafer y dimension */
069 private int maxChipY;
070
071 /** space to draw between chips */
072 private double chipSpace;
073
074 /** maximum value in this dataset */
075 private Double maxValue;
076
077 /** minimum value in this dataset */
078 private Double minValue;
079
080 /** default chip spacing */
081 private static final double DEFAULT_CHIP_SPACE = 1d;
082
083 /**
084 * Creates a new dataset using the default chipspace.
085 *
086 * @param maxChipX the wafer x-dimension.
087 * @param maxChipY the wafer y-dimension.
088 */
089 public WaferMapDataset(int maxChipX, int maxChipY) {
090 this(maxChipX, maxChipY, null);
091 }
092
093 /**
094 * Creates a new dataset.
095 *
096 * @param maxChipX the wafer x-dimension.
097 * @param maxChipY the wafer y-dimension.
098 * @param chipSpace the space between chips.
099 */
100 public WaferMapDataset(int maxChipX, int maxChipY, Number chipSpace) {
101
102 this.maxValue = new Double(Double.NEGATIVE_INFINITY);
103 this.minValue = new Double(Double.POSITIVE_INFINITY);
104 this.data = new DefaultKeyedValues2D();
105
106 this.maxChipX = maxChipX;
107 this.maxChipY = maxChipY;
108 if (chipSpace == null) {
109 this.chipSpace = DEFAULT_CHIP_SPACE;
110 }
111 else {
112 this.chipSpace = chipSpace.doubleValue();
113 }
114
115 }
116
117 /**
118 * Sets a value in the dataset.
119 *
120 * @param value the value.
121 * @param chipx the x-index for the chip.
122 * @param chipy the y-index for the chip.
123 */
124 public void addValue(Number value, Comparable chipx, Comparable chipy) {
125 setValue(value, chipx, chipy);
126 }
127
128 /**
129 * Adds a value to the dataset.
130 *
131 * @param v the value.
132 * @param x the x-index.
133 * @param y the y-index.
134 */
135 public void addValue(int v, int x, int y) {
136 setValue(new Double(v), new Integer(x), new Integer(y));
137 }
138
139 /**
140 * Sets a value in the dataset and updates min and max value entries.
141 *
142 * @param value the value.
143 * @param chipx the x-index.
144 * @param chipy the y-index.
145 */
146 public void setValue(Number value, Comparable chipx, Comparable chipy) {
147 this.data.setValue(value, chipx, chipy);
148 if (isMaxValue(value)) {
149 this.maxValue = (Double) value;
150 }
151 if (isMinValue(value)) {
152 this.minValue = (Double) value;
153 }
154 }
155
156 /**
157 * Returns the number of unique values.
158 *
159 * @return The number of unique values.
160 */
161 public int getUniqueValueCount() {
162 return getUniqueValues().size();
163 }
164
165 /**
166 * Returns the set of unique values.
167 *
168 * @return The set of unique values.
169 */
170 public Set getUniqueValues() {
171 Set unique = new TreeSet();
172 //step through all the values and add them to the hash
173 for (int r = 0; r < this.data.getRowCount(); r++) {
174 for (int c = 0; c < this.data.getColumnCount(); c++) {
175 Number value = this.data.getValue(r, c);
176 if (value != null) {
177 unique.add(value);
178 }
179 }
180 }
181 return unique;
182 }
183
184 /**
185 * Returns the data value for a chip.
186 *
187 * @param chipx the x-index.
188 * @param chipy the y-index.
189 *
190 * @return The data value.
191 */
192 public Number getChipValue(int chipx, int chipy) {
193 return getChipValue(new Integer(chipx), new Integer(chipy));
194 }
195
196 /**
197 * Returns the value for a given chip x and y or null.
198 *
199 * @param chipx the x-index.
200 * @param chipy the y-index.
201 *
202 * @return The data value.
203 */
204 public Number getChipValue(Comparable chipx, Comparable chipy) {
205 int rowIndex = this.data.getRowIndex(chipx);
206 if (rowIndex < 0) {
207 return null;
208 }
209 int colIndex = this.data.getColumnIndex(chipy);
210 if (colIndex < 0) {
211 return null;
212 }
213 return this.data.getValue(rowIndex, colIndex);
214 }
215
216 /**
217 * Tests to see if the passed value is larger than the stored maxvalue.
218 *
219 * @param check the number to check.
220 *
221 * @return A boolean.
222 */
223 public boolean isMaxValue(Number check) {
224 if (check.doubleValue() > this.maxValue.doubleValue()) {
225 return true;
226 }
227 return false;
228 }
229
230 /**
231 * Tests to see if the passed value is smaller than the stored minvalue.
232 *
233 * @param check the number to check.
234 *
235 * @return A boolean.
236 */
237 public boolean isMinValue(Number check) {
238 if (check.doubleValue() < this.minValue.doubleValue()) {
239 return true;
240 }
241 return false;
242 }
243
244 /**
245 * Returns the maximum value stored in the dataset.
246 *
247 * @return The maximum value.
248 */
249 public Number getMaxValue() {
250 return this.maxValue;
251 }
252
253 /**
254 * Returns the minimum value stored in the dataset.
255 *
256 * @return The minimum value.
257 */
258 public Number getMinValue() {
259 return this.minValue;
260 }
261
262 /**
263 * Returns the wafer x-dimension.
264 *
265 * @return The number of chips in the x-dimension.
266 */
267 public int getMaxChipX() {
268 return this.maxChipX;
269 }
270
271 /**
272 * Sets wafer x dimension.
273 *
274 * @param maxChipX the number of chips in the x-dimension.
275 */
276 public void setMaxChipX(int maxChipX) {
277 this.maxChipX = maxChipX;
278 }
279
280 /**
281 * Returns the number of chips in the y-dimension.
282 *
283 * @return The number of chips.
284 */
285 public int getMaxChipY() {
286 return this.maxChipY;
287 }
288
289 /**
290 * Sets the number of chips in the y-dimension.
291 *
292 * @param maxChipY the number of chips.
293 */
294 public void setMaxChipY(int maxChipY) {
295 this.maxChipY = maxChipY;
296 }
297
298 /**
299 * Returns the space to draw between chips.
300 *
301 * @return The space.
302 */
303 public double getChipSpace() {
304 return this.chipSpace;
305 }
306
307 /**
308 * Sets the space to draw between chips.
309 *
310 * @param space the space.
311 */
312 public void setChipSpace(double space) {
313 this.chipSpace = space;
314 }
315
316 }