Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * -------------------- 28: * WaferMapDataset.java 29: * -------------------- 30: * (C)opyright 2003-2007, by Robert Redburn and Contributors. 31: * 32: * Original Author: Robert Redburn; 33: * Contributor(s): David Gilbert (for Object Refinery Limited); 34: * 35: * $Id: WaferMapDataset.java,v 1.3.2.2 2007/02/02 15:50:44 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 25-Nov-2003 : Version 1 contributed by Robert Redburn (with some 40: * modifications to match style conventions) (DG); 41: * ------------- JFREECHART 1.0.x --------------------------------------------- 42: * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG); 43: * 44: */ 45: 46: package org.jfree.data.general; 47: 48: import java.util.Set; 49: import java.util.TreeSet; 50: 51: import org.jfree.data.DefaultKeyedValues2D; 52: 53: /** 54: * A dataset that can be used with the {@link org.jfree.chart.plot.WaferMapPlot} 55: * class. 56: */ 57: public class WaferMapDataset extends AbstractDataset { 58: 59: /** 60: * Storage structure for the data values (row key is chipx, column is 61: * chipy) 62: */ 63: private DefaultKeyedValues2D data; 64: 65: /** wafer x dimension */ 66: private int maxChipX; 67: 68: /** wafer y dimension */ 69: private int maxChipY; 70: 71: /** space to draw between chips */ 72: private double chipSpace; 73: 74: /** maximum value in this dataset */ 75: private Double maxValue; 76: 77: /** minimum value in this dataset */ 78: private Double minValue; 79: 80: /** default chip spacing */ 81: private static final double DEFAULT_CHIP_SPACE = 1d; 82: 83: /** 84: * Creates a new dataset using the default chipspace. 85: * 86: * @param maxChipX the wafer x-dimension. 87: * @param maxChipY the wafer y-dimension. 88: */ 89: public WaferMapDataset(int maxChipX, int maxChipY) { 90: this(maxChipX, maxChipY, null); 91: } 92: 93: /** 94: * Creates a new dataset. 95: * 96: * @param maxChipX the wafer x-dimension. 97: * @param maxChipY the wafer y-dimension. 98: * @param chipSpace the space between chips. 99: */ 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: }