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