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