001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-present, by David Gilbert 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-present, by David Gilbert and Contributors.
031 *
032 * Original Author:  David Gilbert;
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 java.util.Objects;
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 final Number mean;
055
056    /** The median. */
057    private final Number median;
058
059    /** The first quarter. */
060    private final Number q1;
061
062    /** The third quarter. */
063    private final Number q3;
064
065    /** The minimum regular value. */
066    private final Number minRegularValue;
067
068    /** The maximum regular value. */
069    private final Number maxRegularValue;
070
071    /** The minimum outlier. */
072    private final Number minOutlier;
073
074    /** The maximum outlier. */
075    private final Number maxOutlier;
076
077    /** The outliers. */
078    private final List<? extends Number> 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, Number median, Number q1, Number q3,
096            Number minRegularValue, Number maxRegularValue, Number minOutlier,
097            Number maxOutlier, List<? extends Number> outliers) {
098
099        this.mean = mean;
100        this.median = median;
101        this.q1 = q1;
102        this.q3 = q3;
103        this.minRegularValue = minRegularValue;
104        this.maxRegularValue = maxRegularValue;
105        this.minOutlier = minOutlier;
106        this.maxOutlier = maxOutlier;
107        this.outliers = outliers;
108
109    }
110
111    /**
112     * Creates a new box-and-whisker item.
113     *
114     * @param mean  the mean.
115     * @param median  the median
116     * @param q1  the first quartile.
117     * @param q3  the third quartile.
118     * @param minRegularValue  the minimum regular value.
119     * @param maxRegularValue  the maximum regular value.
120     * @param minOutlier  the minimum outlier value.
121     * @param maxOutlier  the maximum outlier value.
122     * @param outliers  a list of the outliers.
123     */
124    public BoxAndWhiskerItem(double mean, double median, double q1, double q3,
125            double minRegularValue, double maxRegularValue, double minOutlier,
126            double maxOutlier, List<? extends Number> outliers) {
127
128        // pass values to other constructor
129        this(Double.valueOf(mean), Double.valueOf(median), Double.valueOf(q1),
130                Double.valueOf(q3), Double.valueOf(minRegularValue),
131                Double.valueOf(maxRegularValue), Double.valueOf(minOutlier),
132                Double.valueOf(maxOutlier), outliers);
133
134    }
135
136    /**
137     * Returns the mean.
138     *
139     * @return The mean (possibly {@code null}).
140     */
141    public Number getMean() {
142        return this.mean;
143    }
144
145    /**
146     * Returns the median.
147     *
148     * @return The median (possibly {@code null}).
149     */
150    public Number getMedian() {
151        return this.median;
152    }
153
154    /**
155     * Returns the first quartile.
156     *
157     * @return The first quartile (possibly {@code null}).
158     */
159    public Number getQ1() {
160        return this.q1;
161    }
162
163    /**
164     * Returns the third quartile.
165     *
166     * @return The third quartile (possibly {@code null}).
167     */
168    public Number getQ3() {
169        return this.q3;
170    }
171
172    /**
173     * Returns the minimum regular value.
174     *
175     * @return The minimum regular value (possibly {@code null}).
176     */
177    public Number getMinRegularValue() {
178        return this.minRegularValue;
179    }
180
181    /**
182     * Returns the maximum regular value.
183     *
184     * @return The maximum regular value (possibly {@code null}).
185     */
186    public Number getMaxRegularValue() {
187        return this.maxRegularValue;
188    }
189
190    /**
191     * Returns the minimum outlier.
192     *
193     * @return The minimum outlier (possibly {@code null}).
194     */
195    public Number getMinOutlier() {
196        return this.minOutlier;
197    }
198
199    /**
200     * Returns the maximum outlier.
201     *
202     * @return The maximum outlier (possibly {@code null}).
203     */
204    public Number getMaxOutlier() {
205        return this.maxOutlier;
206    }
207
208    /**
209     * Returns a list of outliers.
210     *
211     * @return A list of outliers (possibly {@code null}).
212     */
213    public List<Number> getOutliers() {
214        if (this.outliers == null) {
215            return null;
216        }
217        return Collections.unmodifiableList(this.outliers);
218    }
219
220    /**
221     * Returns a string representation of this instance, primarily for
222     * debugging purposes.
223     *
224     * @return A string representation of this instance.
225     */
226    @Override
227    public String toString() {
228        return super.toString() + "[mean=" + this.mean + ",median="
229                + this.median + ",q1=" + this.q1 + ",q3=" + this.q3 + "]";
230    }
231
232    /**
233     * Tests this object for equality with an arbitrary object.
234     *
235     * @param obj  the object to test against ({@code null} permitted).
236     *
237     * @return A boolean.
238     */
239    @Override
240    public boolean equals(Object obj) {
241
242        if (obj == this) {
243            return true;
244        }
245        if (!(obj instanceof BoxAndWhiskerItem)) {
246            return false;
247        }
248        BoxAndWhiskerItem that = (BoxAndWhiskerItem) obj;
249        if (!Objects.equals(this.mean, that.mean)) {
250            return false;
251        }
252        if (!Objects.equals(this.median, that.median)) {
253            return false;
254        }
255        if (!Objects.equals(this.q1, that.q1)) {
256            return false;
257        }
258        if (!Objects.equals(this.q3, that.q3)) {
259            return false;
260        }
261        if (!Objects.equals(this.minRegularValue,
262                that.minRegularValue)) {
263            return false;
264        }
265        if (!Objects.equals(this.maxRegularValue,
266                that.maxRegularValue)) {
267            return false;
268        }
269        if (!Objects.equals(this.minOutlier, that.minOutlier)) {
270            return false;
271        }
272        if (!Objects.equals(this.maxOutlier, that.maxOutlier)) {
273            return false;
274        }
275        if (!Objects.equals(this.outliers, that.outliers)) {
276            return false;
277        }
278        return true;
279    }
280
281}