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