001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2020, 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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 * ---------------------- 028 * BoxAndWhiskerItem.java 029 * ---------------------- 030 * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * Changes 036 * ------- 037 * 27-Aug-2003 : Version 1 (DG); 038 * 01-Mar-2004 : Added equals() method and implemented Serializable (DG); 039 * ------------- JFREECHART 1.0.x --------------------------------------------- 040 * 15-Nov-2006 : Added toString() method override (DG); 041 * 02-Oct-2007 : Added new constructor (for convenience) (DG); 042 * 043 */ 044 045package org.jfree.data.statistics; 046 047import java.io.Serializable; 048import java.util.Collections; 049import java.util.List; 050import org.jfree.chart.util.ObjectUtils; 051 052/** 053 * Represents one data item within a box-and-whisker dataset. Instances of 054 * this class are immutable. 055 */ 056public 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} permitted). 092 * @param median the median ({@code null} permitted). 093 * @param q1 the first quartile ({@code null} permitted). 094 * @param q3 the third quartile ({@code null} permitted). 095 * @param minRegularValue the minimum regular value ({@code null} 096 * permitted). 097 * @param maxRegularValue the maximum regular value ({@code null} 098 * permitted). 099 * @param minOutlier the minimum outlier ({@code null} permitted). 100 * @param maxOutlier the maximum outlier ({@code null} permitted). 101 * @param outliers the outliers ({@code null} 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 * Creates a new box-and-whisker item. 127 * 128 * @param mean the mean. 129 * @param median the median 130 * @param q1 the first quartile. 131 * @param q3 the third quartile. 132 * @param minRegularValue the minimum regular value. 133 * @param maxRegularValue the maximum regular value. 134 * @param minOutlier the minimum outlier value. 135 * @param maxOutlier the maximum outlier value. 136 * @param outliers a list of the outliers. 137 * 138 * @since 1.0.7 139 */ 140 public BoxAndWhiskerItem(double mean, double median, double q1, double q3, 141 double minRegularValue, double maxRegularValue, double minOutlier, 142 double maxOutlier, List outliers) { 143 144 // pass values to other constructor 145 this(Double.valueOf(mean), Double.valueOf(median), Double.valueOf(q1), 146 Double.valueOf(q3), Double.valueOf(minRegularValue), 147 Double.valueOf(maxRegularValue), Double.valueOf(minOutlier), 148 Double.valueOf(maxOutlier), outliers); 149 150 } 151 152 /** 153 * Returns the mean. 154 * 155 * @return The mean (possibly {@code null}). 156 */ 157 public Number getMean() { 158 return this.mean; 159 } 160 161 /** 162 * Returns the median. 163 * 164 * @return The median (possibly {@code null}). 165 */ 166 public Number getMedian() { 167 return this.median; 168 } 169 170 /** 171 * Returns the first quartile. 172 * 173 * @return The first quartile (possibly {@code null}). 174 */ 175 public Number getQ1() { 176 return this.q1; 177 } 178 179 /** 180 * Returns the third quartile. 181 * 182 * @return The third quartile (possibly {@code null}). 183 */ 184 public Number getQ3() { 185 return this.q3; 186 } 187 188 /** 189 * Returns the minimum regular value. 190 * 191 * @return The minimum regular value (possibly {@code null}). 192 */ 193 public Number getMinRegularValue() { 194 return this.minRegularValue; 195 } 196 197 /** 198 * Returns the maximum regular value. 199 * 200 * @return The maximum regular value (possibly {@code null}). 201 */ 202 public Number getMaxRegularValue() { 203 return this.maxRegularValue; 204 } 205 206 /** 207 * Returns the minimum outlier. 208 * 209 * @return The minimum outlier (possibly {@code null}). 210 */ 211 public Number getMinOutlier() { 212 return this.minOutlier; 213 } 214 215 /** 216 * Returns the maximum outlier. 217 * 218 * @return The maximum outlier (possibly {@code null}). 219 */ 220 public Number getMaxOutlier() { 221 return this.maxOutlier; 222 } 223 224 /** 225 * Returns a list of outliers. 226 * 227 * @return A list of outliers (possibly {@code null}). 228 */ 229 public List getOutliers() { 230 if (this.outliers == null) { 231 return null; 232 } 233 return Collections.unmodifiableList(this.outliers); 234 } 235 236 /** 237 * Returns a string representation of this instance, primarily for 238 * debugging purposes. 239 * 240 * @return A string representation of this instance. 241 */ 242 @Override 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} permitted). 252 * 253 * @return A boolean. 254 */ 255 @Override 256 public boolean equals(Object obj) { 257 258 if (obj == this) { 259 return true; 260 } 261 if (!(obj instanceof BoxAndWhiskerItem)) { 262 return false; 263 } 264 BoxAndWhiskerItem that = (BoxAndWhiskerItem) obj; 265 if (!ObjectUtils.equal(this.mean, that.mean)) { 266 return false; 267 } 268 if (!ObjectUtils.equal(this.median, that.median)) { 269 return false; 270 } 271 if (!ObjectUtils.equal(this.q1, that.q1)) { 272 return false; 273 } 274 if (!ObjectUtils.equal(this.q3, that.q3)) { 275 return false; 276 } 277 if (!ObjectUtils.equal(this.minRegularValue, 278 that.minRegularValue)) { 279 return false; 280 } 281 if (!ObjectUtils.equal(this.maxRegularValue, 282 that.maxRegularValue)) { 283 return false; 284 } 285 if (!ObjectUtils.equal(this.minOutlier, that.minOutlier)) { 286 return false; 287 } 288 if (!ObjectUtils.equal(this.maxOutlier, that.maxOutlier)) { 289 return false; 290 } 291 if (!ObjectUtils.equal(this.outliers, that.outliers)) { 292 return false; 293 } 294 return true; 295 } 296 297}