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