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