001 /* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. 006 * 007 * Project Info: http://www.jfree.org/jfreechart/index.html 008 * 009 * This library is free software; you can redistribute it and/or modify it 010 * under the terms of the GNU Lesser General Public License as published by 011 * the Free Software Foundation; either version 2.1 of the License, or 012 * (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but 015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 017 * License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this library; if not, write to the Free Software 021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 022 * USA. 023 * 024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 025 * in the United States and other countries.] 026 * 027 * ---------------------- 028 * BoxAndWhiskerItem.java 029 * ---------------------- 030 * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * $Id: BoxAndWhiskerItem.java,v 1.5.2.2 2005/12/01 20:16:58 mungady Exp $ 036 * 037 * Changes 038 * ------- 039 * 27-Aug-2003 : Version 1 (DG); 040 * 01-Mar-2004 : Added equals() method and implemented Serializable (DG); 041 * 042 */ 043 044 package org.jfree.data.statistics; 045 046 import java.io.Serializable; 047 import java.util.Collections; 048 import java.util.List; 049 050 import org.jfree.util.ObjectUtilities; 051 052 /** 053 * Represents one data item within a box-and-whisker dataset. This class is 054 * immutable. 055 */ 056 public class BoxAndWhiskerItem implements Serializable { 057 058 /** For serialization. */ 059 private static final long serialVersionUID = 7329649623148167423L; 060 061 /** The mean. */ 062 private Number mean; 063 064 /** The median. */ 065 private Number median; 066 067 /** The first quarter. */ 068 private Number q1; 069 070 /** The third quarter. */ 071 private Number q3; 072 073 /** The minimum regular value. */ 074 private Number minRegularValue; 075 076 /** The maximum regular value. */ 077 private Number maxRegularValue; 078 079 /** The minimum outlier. */ 080 private Number minOutlier; 081 082 /** The maximum outlier. */ 083 private Number maxOutlier; 084 085 /** The outliers. */ 086 private List outliers; 087 088 /** 089 * Creates a new box-and-whisker item. 090 * 091 * @param mean the mean (<code>null</code> permitted). 092 * @param median the median (<code>null</code> permitted). 093 * @param q1 the first quartile (<code>null</code> permitted). 094 * @param q3 the third quartile (<code>null</code> permitted). 095 * @param minRegularValue the minimum regular value (<code>null</code> 096 * permitted). 097 * @param maxRegularValue the maximum regular value (<code>null</code> 098 * permitted). 099 * @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 }