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: * BoxAndWhiskerItem.java 29: * ---------------------- 30: * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * Changes 36: * ------- 37: * 27-Aug-2003 : Version 1 (DG); 38: * 01-Mar-2004 : Added equals() method and implemented Serializable (DG); 39: * ------------- JFREECHART 1.0.x --------------------------------------------- 40: * 15-Nov-2006 : Added toString() method override (DG); 41: * 02-Oct-2007 : Added new constructor (for convenience) (DG); 42: * 43: */ 44: 45: package org.jfree.data.statistics; 46: 47: import java.io.Serializable; 48: import java.util.Collections; 49: import java.util.List; 50: 51: import org.jfree.util.ObjectUtilities; 52: 53: /** 54: * Represents one data item within a box-and-whisker dataset. Instances of 55: * this class are immutable. 56: */ 57: public class BoxAndWhiskerItem implements Serializable { 58: 59: /** For serialization. */ 60: private static final long serialVersionUID = 7329649623148167423L; 61: 62: /** The mean. */ 63: private Number mean; 64: 65: /** The median. */ 66: private Number median; 67: 68: /** The first quarter. */ 69: private Number q1; 70: 71: /** The third quarter. */ 72: private Number q3; 73: 74: /** The minimum regular value. */ 75: private Number minRegularValue; 76: 77: /** The maximum regular value. */ 78: private Number maxRegularValue; 79: 80: /** The minimum outlier. */ 81: private Number minOutlier; 82: 83: /** The maximum outlier. */ 84: private Number maxOutlier; 85: 86: /** The outliers. */ 87: private List outliers; 88: 89: /** 90: * Creates a new box-and-whisker item. 91: * 92: * @param mean the mean (<code>null</code> permitted). 93: * @param median the median (<code>null</code> permitted). 94: * @param q1 the first quartile (<code>null</code> permitted). 95: * @param q3 the third quartile (<code>null</code> permitted). 96: * @param minRegularValue the minimum regular value (<code>null</code> 97: * permitted). 98: * @param maxRegularValue the maximum regular value (<code>null</code> 99: * permitted). 100: * @param minOutlier the minimum outlier (<code>null</code> permitted). 101: * @param maxOutlier the maximum outlier (<code>null</code> permitted). 102: * @param outliers the outliers (<code>null</code> permitted). 103: */ 104: public BoxAndWhiskerItem(Number mean, 105: Number median, 106: Number q1, 107: Number q3, 108: Number minRegularValue, 109: Number maxRegularValue, 110: Number minOutlier, 111: Number maxOutlier, 112: List outliers) { 113: 114: this.mean = mean; 115: this.median = median; 116: this.q1 = q1; 117: this.q3 = q3; 118: this.minRegularValue = minRegularValue; 119: this.maxRegularValue = maxRegularValue; 120: this.minOutlier = minOutlier; 121: this.maxOutlier = maxOutlier; 122: this.outliers = outliers; 123: 124: } 125: 126: /** 127: * Creates a new box-and-whisker item. 128: * 129: * @param mean the mean. 130: * @param median the median 131: * @param q1 the first quartile. 132: * @param q3 the third quartile. 133: * @param minRegularValue the minimum regular value. 134: * @param maxRegularValue the maximum regular value. 135: * @param minOutlier the minimum outlier value. 136: * @param maxOutlier the maximum outlier value. 137: * @param outliers a list of the outliers. 138: * 139: * @since 1.0.7 140: */ 141: public BoxAndWhiskerItem(double mean, double median, double q1, double q3, 142: double minRegularValue, double maxRegularValue, double minOutlier, 143: double maxOutlier, List outliers) { 144: 145: // pass values to other constructor 146: this(new Double(mean), new Double(median), new Double(q1), 147: new Double(q3), new Double(minRegularValue), 148: new Double(maxRegularValue), new Double(minOutlier), 149: new Double(maxOutlier), outliers); 150: 151: } 152: 153: /** 154: * Returns the mean. 155: * 156: * @return The mean (possibly <code>null</code>). 157: */ 158: public Number getMean() { 159: return this.mean; 160: } 161: 162: /** 163: * Returns the median. 164: * 165: * @return The median (possibly <code>null</code>). 166: */ 167: public Number getMedian() { 168: return this.median; 169: } 170: 171: /** 172: * Returns the first quartile. 173: * 174: * @return The first quartile (possibly <code>null</code>). 175: */ 176: public Number getQ1() { 177: return this.q1; 178: } 179: 180: /** 181: * Returns the third quartile. 182: * 183: * @return The third quartile (possibly <code>null</code>). 184: */ 185: public Number getQ3() { 186: return this.q3; 187: } 188: 189: /** 190: * Returns the minimum regular value. 191: * 192: * @return The minimum regular value (possibly <code>null</code>). 193: */ 194: public Number getMinRegularValue() { 195: return this.minRegularValue; 196: } 197: 198: /** 199: * Returns the maximum regular value. 200: * 201: * @return The maximum regular value (possibly <code>null</code>). 202: */ 203: public Number getMaxRegularValue() { 204: return this.maxRegularValue; 205: } 206: 207: /** 208: * Returns the minimum outlier. 209: * 210: * @return The minimum outlier (possibly <code>null</code>). 211: */ 212: public Number getMinOutlier() { 213: return this.minOutlier; 214: } 215: 216: /** 217: * Returns the maximum outlier. 218: * 219: * @return The maximum outlier (possibly <code>null</code>). 220: */ 221: public Number getMaxOutlier() { 222: return this.maxOutlier; 223: } 224: 225: /** 226: * Returns a list of outliers. 227: * 228: * @return A list of outliers (possibly <code>null</code>). 229: */ 230: public List getOutliers() { 231: if (this.outliers == null) { 232: return null; 233: } 234: return Collections.unmodifiableList(this.outliers); 235: } 236: 237: /** 238: * Returns a string representation of this instance, primarily for 239: * debugging purposes. 240: * 241: * @return A string representation of this instance. 242: */ 243: public String toString() { 244: return super.toString() + "[mean=" + this.mean + ",median=" 245: + this.median + ",q1=" + this.q1 + ",q3=" + this.q3 + "]"; 246: } 247: 248: /** 249: * Tests this object for equality with an arbitrary object. 250: * 251: * @param obj the object to test against (<code>null</code> permitted). 252: * 253: * @return A boolean. 254: */ 255: public boolean equals(Object obj) { 256: 257: if (obj == this) { 258: return true; 259: } 260: if (!(obj instanceof BoxAndWhiskerItem)) { 261: return false; 262: } 263: BoxAndWhiskerItem that = (BoxAndWhiskerItem) obj; 264: if (!ObjectUtilities.equal(this.mean, that.mean)) { 265: return false; 266: } 267: if (!ObjectUtilities.equal(this.median, that.median)) { 268: return false; 269: } 270: if (!ObjectUtilities.equal(this.q1, that.q1)) { 271: return false; 272: } 273: if (!ObjectUtilities.equal(this.q3, that.q3)) { 274: return false; 275: } 276: if (!ObjectUtilities.equal(this.minRegularValue, 277: that.minRegularValue)) { 278: return false; 279: } 280: if (!ObjectUtilities.equal(this.maxRegularValue, 281: that.maxRegularValue)) { 282: return false; 283: } 284: if (!ObjectUtilities.equal(this.minOutlier, that.minOutlier)) { 285: return false; 286: } 287: if (!ObjectUtilities.equal(this.maxOutlier, that.maxOutlier)) { 288: return false; 289: } 290: if (!ObjectUtilities.equal(this.outliers, that.outliers)) { 291: return false; 292: } 293: return true; 294: } 295: 296: }