Source for org.jfree.data.statistics.BoxAndWhiskerItem

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