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-2020, by Object Refinery Limited and Contributors.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   -;
034 *
035 */
036
037package org.jfree.data.statistics;
038
039import java.io.Serializable;
040import java.util.Collections;
041import java.util.List;
042import org.jfree.chart.util.ObjectUtils;
043
044/**
045 * Represents one data item within a box-and-whisker dataset.  Instances of
046 * this class are immutable.
047 */
048public class BoxAndWhiskerItem implements Serializable {
049
050    /** For serialization. */
051    private static final long serialVersionUID = 7329649623148167423L;
052
053    /** The mean. */
054    private Number mean;
055
056    /** The median. */
057    private Number median;
058
059    /** The first quarter. */
060    private Number q1;
061
062    /** The third quarter. */
063    private Number q3;
064
065    /** The minimum regular value. */
066    private Number minRegularValue;
067
068    /** The maximum regular value. */
069    private Number maxRegularValue;
070
071    /** The minimum outlier. */
072    private Number minOutlier;
073
074    /** The maximum outlier. */
075    private Number maxOutlier;
076
077    /** The outliers. */
078    private List outliers;
079
080    /**
081     * Creates a new box-and-whisker item.
082     *
083     * @param mean  the mean ({@code null} permitted).
084     * @param median  the median ({@code null} permitted).
085     * @param q1  the first quartile ({@code null} permitted).
086     * @param q3  the third quartile ({@code null} permitted).
087     * @param minRegularValue  the minimum regular value ({@code null}
088     *                         permitted).
089     * @param maxRegularValue  the maximum regular value ({@code null}
090     *                         permitted).
091     * @param minOutlier  the minimum outlier ({@code null} permitted).
092     * @param maxOutlier  the maximum outlier ({@code null} permitted).
093     * @param outliers  the outliers ({@code null} permitted).
094     */
095    public BoxAndWhiskerItem(Number mean,
096                             Number median,
097                             Number q1,
098                             Number q3,
099                             Number minRegularValue,
100                             Number maxRegularValue,
101                             Number minOutlier,
102                             Number maxOutlier,
103                             List outliers) {
104
105        this.mean = mean;
106        this.median = median;
107        this.q1 = q1;
108        this.q3 = q3;
109        this.minRegularValue = minRegularValue;
110        this.maxRegularValue = maxRegularValue;
111        this.minOutlier = minOutlier;
112        this.maxOutlier = maxOutlier;
113        this.outliers = outliers;
114
115    }
116
117    /**
118     * Creates a new box-and-whisker item.
119     *
120     * @param mean  the mean.
121     * @param median  the median
122     * @param q1  the first quartile.
123     * @param q3  the third quartile.
124     * @param minRegularValue  the minimum regular value.
125     * @param maxRegularValue  the maximum regular value.
126     * @param minOutlier  the minimum outlier value.
127     * @param maxOutlier  the maximum outlier value.
128     * @param outliers  a list of the outliers.
129     *
130     * @since 1.0.7
131     */
132    public BoxAndWhiskerItem(double mean, double median, double q1, double q3,
133            double minRegularValue, double maxRegularValue, double minOutlier,
134            double maxOutlier, List outliers) {
135
136        // pass values to other constructor
137        this(Double.valueOf(mean), Double.valueOf(median), Double.valueOf(q1),
138                Double.valueOf(q3), Double.valueOf(minRegularValue),
139                Double.valueOf(maxRegularValue), Double.valueOf(minOutlier),
140                Double.valueOf(maxOutlier), outliers);
141
142    }
143
144    /**
145     * Returns the mean.
146     *
147     * @return The mean (possibly {@code null}).
148     */
149    public Number getMean() {
150        return this.mean;
151    }
152
153    /**
154     * Returns the median.
155     *
156     * @return The median (possibly {@code null}).
157     */
158    public Number getMedian() {
159        return this.median;
160    }
161
162    /**
163     * Returns the first quartile.
164     *
165     * @return The first quartile (possibly {@code null}).
166     */
167    public Number getQ1() {
168        return this.q1;
169    }
170
171    /**
172     * Returns the third quartile.
173     *
174     * @return The third quartile (possibly {@code null}).
175     */
176    public Number getQ3() {
177        return this.q3;
178    }
179
180    /**
181     * Returns the minimum regular value.
182     *
183     * @return The minimum regular value (possibly {@code null}).
184     */
185    public Number getMinRegularValue() {
186        return this.minRegularValue;
187    }
188
189    /**
190     * Returns the maximum regular value.
191     *
192     * @return The maximum regular value (possibly {@code null}).
193     */
194    public Number getMaxRegularValue() {
195        return this.maxRegularValue;
196    }
197
198    /**
199     * Returns the minimum outlier.
200     *
201     * @return The minimum outlier (possibly {@code null}).
202     */
203    public Number getMinOutlier() {
204        return this.minOutlier;
205    }
206
207    /**
208     * Returns the maximum outlier.
209     *
210     * @return The maximum outlier (possibly {@code null}).
211     */
212    public Number getMaxOutlier() {
213        return this.maxOutlier;
214    }
215
216    /**
217     * Returns a list of outliers.
218     *
219     * @return A list of outliers (possibly {@code null}).
220     */
221    public List getOutliers() {
222        if (this.outliers == null) {
223            return null;
224        }
225        return Collections.unmodifiableList(this.outliers);
226    }
227
228    /**
229     * Returns a string representation of this instance, primarily for
230     * debugging purposes.
231     *
232     * @return A string representation of this instance.
233     */
234    @Override
235    public String toString() {
236        return super.toString() + "[mean=" + this.mean + ",median="
237                + this.median + ",q1=" + this.q1 + ",q3=" + this.q3 + "]";
238    }
239
240    /**
241     * Tests this object for equality with an arbitrary object.
242     *
243     * @param obj  the object to test against ({@code null} permitted).
244     *
245     * @return A boolean.
246     */
247    @Override
248    public boolean equals(Object obj) {
249
250        if (obj == this) {
251            return true;
252        }
253        if (!(obj instanceof BoxAndWhiskerItem)) {
254            return false;
255        }
256        BoxAndWhiskerItem that = (BoxAndWhiskerItem) obj;
257        if (!ObjectUtils.equal(this.mean, that.mean)) {
258            return false;
259        }
260        if (!ObjectUtils.equal(this.median, that.median)) {
261            return false;
262        }
263        if (!ObjectUtils.equal(this.q1, that.q1)) {
264            return false;
265        }
266        if (!ObjectUtils.equal(this.q3, that.q3)) {
267            return false;
268        }
269        if (!ObjectUtils.equal(this.minRegularValue,
270                that.minRegularValue)) {
271            return false;
272        }
273        if (!ObjectUtils.equal(this.maxRegularValue,
274                that.maxRegularValue)) {
275            return false;
276        }
277        if (!ObjectUtils.equal(this.minOutlier, that.minOutlier)) {
278            return false;
279        }
280        if (!ObjectUtils.equal(this.maxOutlier, that.maxOutlier)) {
281            return false;
282        }
283        if (!ObjectUtils.equal(this.outliers, that.outliers)) {
284            return false;
285        }
286        return true;
287    }
288
289}