1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2005, 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 under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * --------------------
  25. * WaferMapDataset.java
  26. * --------------------
  27. * (C)opyright 2003-2005, by Robert Redburn and Contributors.
  28. *
  29. * Original Author: Robert Redburn;
  30. * Contributor(s): David Gilbert (for Object Refinery Limited);
  31. *
  32. * $Id: WaferMapDataset.java,v 1.2 2005/01/14 17:31:44 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 25-Nov-2003 : Version 1 contributed by Robert Redburn (with some modifications to match
  37. * style conventions) (DG);
  38. *
  39. */
  40. package org.jfree.data.general;
  41. import java.util.Set;
  42. import java.util.TreeSet;
  43. import org.jfree.data.DefaultKeyedValues2D;
  44. /**
  45. * A dataset that can be used with the {@link org.jfree.chart.plot.WaferMapPlot} class.
  46. *
  47. * @author Robert Redburn
  48. */
  49. public class WaferMapDataset extends AbstractDataset {
  50. /** Storage structure for the data values (row key is chipx, column is chipy) */
  51. private DefaultKeyedValues2D data;
  52. /** wafer x dimension */
  53. private int maxChipX;
  54. /** wafer y dimension */
  55. private int maxChipY;
  56. /** space to draw between chips */
  57. private double chipSpace;
  58. /** maximum value in this dataset */
  59. private Double maxValue;
  60. /** minimum value in this dataset */
  61. private Double minValue;
  62. /** default chip spacing */
  63. private static final double DEFAULT_CHIP_SPACE = 1d;
  64. /**
  65. * Creates a new dataset using the default chipspace.
  66. *
  67. * @param maxChipX the wafer x-dimension.
  68. * @param maxChipY the wafer y-dimension.
  69. */
  70. public WaferMapDataset(int maxChipX, int maxChipY) {
  71. this(maxChipX, maxChipY, null);
  72. }
  73. /**
  74. * Creates a new dataset.
  75. *
  76. * @param maxChipX the wafer x-dimension.
  77. * @param maxChipY the wafer y-dimension.
  78. * @param chipSpace the space between chips.
  79. */
  80. public WaferMapDataset(int maxChipX, int maxChipY, Number chipSpace) {
  81. this.maxValue = new Double(Double.NEGATIVE_INFINITY);
  82. this.minValue = new Double(Double.POSITIVE_INFINITY);
  83. this.data = new DefaultKeyedValues2D();
  84. this.maxChipX = maxChipX;
  85. this.maxChipY = maxChipY;
  86. if (chipSpace == null) {
  87. this.chipSpace = DEFAULT_CHIP_SPACE;
  88. }
  89. else {
  90. this.chipSpace = chipSpace.doubleValue();
  91. }
  92. }
  93. /**
  94. * Sets a value in the dataset.
  95. *
  96. * @param value the value.
  97. * @param chipx the x-index for the chip.
  98. * @param chipy the y-index for the chip.
  99. */
  100. public void addValue(Number value, Comparable chipx, Comparable chipy) {
  101. setValue(value, chipx, chipy);
  102. }
  103. /**
  104. * Adds a value to the dataset.
  105. *
  106. * @param v the value.
  107. * @param x the x-index.
  108. * @param y the y-index.
  109. */
  110. public void addValue(int v, int x, int y) {
  111. setValue(new Double(v), new Integer(x), new Integer(y));
  112. }
  113. /**
  114. * Sets a value in the dataset and updates min and max value entries.
  115. *
  116. * @param value the value.
  117. * @param chipx the x-index.
  118. * @param chipy the y-index.
  119. */
  120. public void setValue(Number value, Comparable chipx, Comparable chipy) {
  121. this.data.setValue(value, chipx, chipy);
  122. if (isMaxValue(value)) {
  123. this.maxValue = (Double) value;
  124. }
  125. if (isMinValue(value)) {
  126. this.minValue = (Double) value;
  127. }
  128. }
  129. /**
  130. * Returns the number of unique values.
  131. *
  132. * @return The number of unique values.
  133. */
  134. public int getUniqueValueCount() {
  135. return getUniqueValues().size();
  136. }
  137. /**
  138. * Returns the set of unique values.
  139. *
  140. * @return The set of unique values.
  141. */
  142. public Set getUniqueValues() {
  143. Set unique = new TreeSet();
  144. //step through all the values and add them to the hash
  145. for (int r = 0; r < this.data.getRowCount(); r++) {
  146. for (int c = 0; c < this.data.getColumnCount(); c++) {
  147. Number value = this.data.getValue(r, c);
  148. if (value != null) {
  149. unique.add(value);
  150. }
  151. }
  152. }
  153. return unique;
  154. }
  155. /**
  156. * Returns the data value for a chip.
  157. *
  158. * @param chipx the x-index.
  159. * @param chipy the y-index.
  160. *
  161. * @return The data value.
  162. */
  163. public Number getChipValue(int chipx, int chipy) {
  164. return getChipValue(new Integer(chipx), new Integer(chipy));
  165. }
  166. /**
  167. * Returns the value for a given chip x and y or null.
  168. *
  169. * @param chipx the x-index.
  170. * @param chipy the y-index.
  171. *
  172. * @return The data value.
  173. */
  174. public Number getChipValue(Comparable chipx, Comparable chipy) {
  175. int rowIndex = this.data.getRowIndex(chipx);
  176. if (rowIndex < 0) {
  177. return null;
  178. }
  179. int colIndex = this.data.getColumnIndex(chipy);
  180. if (colIndex < 0) {
  181. return null;
  182. }
  183. return this.data.getValue(rowIndex, colIndex);
  184. }
  185. /**
  186. * Tests to see if the passed value is larger than the stored maxvalue.
  187. *
  188. * @param check the number to check.
  189. *
  190. * @return true or false.
  191. */
  192. public boolean isMaxValue(Number check) {
  193. if (check.doubleValue() > this.maxValue.doubleValue()) {
  194. return true;
  195. }
  196. return false;
  197. }
  198. /**
  199. * Tests to see if the passed value is smaller than the stored minvalue.
  200. *
  201. * @param check the number to check.
  202. *
  203. * @return true or false.
  204. */
  205. public boolean isMinValue(Number check) {
  206. if (check.doubleValue() < this.minValue.doubleValue()) {
  207. return true;
  208. }
  209. return false;
  210. }
  211. /**
  212. * Returns the maximum value stored in the dataset.
  213. *
  214. * @return The maximum value.
  215. */
  216. public Number getMaxValue() {
  217. return this.maxValue;
  218. }
  219. /**
  220. * Returns the minimum value stored in the dataset.
  221. *
  222. * @return The minimum value.
  223. */
  224. public Number getMinValue() {
  225. return this.minValue;
  226. }
  227. /**
  228. * Returns the wafer x-dimension.
  229. *
  230. * @return The number of chips in the x-dimension.
  231. */
  232. public int getMaxChipX() {
  233. return this.maxChipX;
  234. }
  235. /**
  236. * Sets wafer x dimension.
  237. *
  238. * @param maxChipX the number of chips in the x-dimension.
  239. */
  240. public void setMaxChipX(int maxChipX) {
  241. this.maxChipX = maxChipX;
  242. }
  243. /**
  244. * Returns the number of chips in the y-dimension.
  245. *
  246. * @return The number of chips.
  247. */
  248. public int getMaxChipY() {
  249. return this.maxChipY;
  250. }
  251. /**
  252. * Sets the number of chips in the y-dimension.
  253. *
  254. * @param maxChipY the number of chips.
  255. */
  256. public void setMaxChipY(int maxChipY) {
  257. this.maxChipY = maxChipY;
  258. }
  259. /**
  260. * Returns the space to draw between chips.
  261. *
  262. * @return The space.
  263. */
  264. public double getChipSpace() {
  265. return this.chipSpace;
  266. }
  267. /**
  268. * Sets the space to draw between chips.
  269. *
  270. * @param space the space.
  271. */
  272. public void setChipSpace(double space) {
  273. this.chipSpace = space;
  274. }
  275. }