Source for org.jfree.data.general.WaferMapDataset

   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:  * Changes
  36:  * -------
  37:  * 25-Nov-2003 : Version 1 contributed by Robert Redburn (with some 
  38:  *               modifications to match style conventions) (DG);
  39:  * ------------- JFREECHART 1.0.x ---------------------------------------------
  40:  * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG);
  41:  * 
  42:  */
  43: 
  44: package org.jfree.data.general;
  45: 
  46: import java.util.Set;
  47: import java.util.TreeSet;
  48: 
  49: import org.jfree.data.DefaultKeyedValues2D;
  50: 
  51: /**
  52:  * A dataset that can be used with the {@link org.jfree.chart.plot.WaferMapPlot}
  53:  * class.
  54:  */
  55: public class WaferMapDataset extends AbstractDataset {
  56: 
  57:     /** 
  58:      * Storage structure for the data values (row key is chipx, column is 
  59:      * chipy)
  60:      */
  61:     private DefaultKeyedValues2D data;
  62:     
  63:     /** wafer x dimension */
  64:     private int maxChipX;
  65:     
  66:     /** wafer y dimension */
  67:     private int maxChipY;
  68:     
  69:     /** space to draw between chips */
  70:     private double chipSpace;
  71:     
  72:     /** maximum value in this dataset */
  73:     private Double maxValue;
  74:     
  75:     /** minimum value in this dataset */
  76:     private Double minValue;
  77:     
  78:     /** default chip spacing */
  79:     private static final double DEFAULT_CHIP_SPACE = 1d;
  80:     
  81:     /**
  82:      * Creates a new dataset using the default chipspace.
  83:      * 
  84:      * @param maxChipX  the wafer x-dimension.
  85:      * @param maxChipY  the wafer y-dimension.
  86:      */
  87:     public WaferMapDataset(int maxChipX, int maxChipY) {
  88:         this(maxChipX, maxChipY, null);
  89:     }
  90:     
  91:     /**
  92:      * Creates a new dataset.
  93:      * 
  94:      * @param maxChipX  the wafer x-dimension. 
  95:      * @param maxChipY  the wafer y-dimension.
  96:      * @param chipSpace  the space between chips.
  97:      */
  98:     public WaferMapDataset(int maxChipX, int maxChipY, Number chipSpace) {
  99:         
 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: }