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, Number median, Number q1,
106: Number q3, Number minRegularValue, Number maxRegularValue,
107: Number minOutlier, Number maxOutlier, List outliers) {
108:
109: this .mean = mean;
110: this .median = median;
111: this .q1 = q1;
112: this .q3 = q3;
113: this .minRegularValue = minRegularValue;
114: this .maxRegularValue = maxRegularValue;
115: this .minOutlier = minOutlier;
116: this .maxOutlier = maxOutlier;
117: this .outliers = outliers;
118:
119: }
120:
121: /**
122: * Returns the mean.
123: *
124: * @return The mean (possibly <code>null</code>).
125: */
126: public Number getMean() {
127: return this .mean;
128: }
129:
130: /**
131: * Returns the median.
132: *
133: * @return The median (possibly <code>null</code>).
134: */
135: public Number getMedian() {
136: return this .median;
137: }
138:
139: /**
140: * Returns the first quartile.
141: *
142: * @return The first quartile (possibly <code>null</code>).
143: */
144: public Number getQ1() {
145: return this .q1;
146: }
147:
148: /**
149: * Returns the third quartile.
150: *
151: * @return The third quartile (possibly <code>null</code>).
152: */
153: public Number getQ3() {
154: return this .q3;
155: }
156:
157: /**
158: * Returns the minimum regular value.
159: *
160: * @return The minimum regular value (possibly <code>null</code>).
161: */
162: public Number getMinRegularValue() {
163: return this .minRegularValue;
164: }
165:
166: /**
167: * Returns the maximum regular value.
168: *
169: * @return The maximum regular value (possibly <code>null</code>).
170: */
171: public Number getMaxRegularValue() {
172: return this .maxRegularValue;
173: }
174:
175: /**
176: * Returns the minimum outlier.
177: *
178: * @return The minimum outlier (possibly <code>null</code>).
179: */
180: public Number getMinOutlier() {
181: return this .minOutlier;
182: }
183:
184: /**
185: * Returns the maximum outlier.
186: *
187: * @return The maximum outlier (possibly <code>null</code>).
188: */
189: public Number getMaxOutlier() {
190: return this .maxOutlier;
191: }
192:
193: /**
194: * Returns a list of outliers.
195: *
196: * @return A list of outliers (possibly <code>null</code>).
197: */
198: public List getOutliers() {
199: if (this .outliers == null) {
200: return null;
201: }
202: return Collections.unmodifiableList(this .outliers);
203: }
204:
205: /**
206: * Returns a string representation of this instance, primarily for
207: * debugging purposes.
208: *
209: * @return A string representation of this instance.
210: */
211: public String toString() {
212: return super .toString() + "[mean=" + this .mean + ",median="
213: + this .median + ",q1=" + this .q1 + ",q3=" + this .q3
214: + "]";
215: }
216:
217: /**
218: * Tests this object for equality with an arbitrary object.
219: *
220: * @param obj the object to test against (<code>null</code> permitted).
221: *
222: * @return A boolean.
223: */
224: public boolean equals(Object obj) {
225:
226: if (obj == this ) {
227: return true;
228: }
229: if (!(obj instanceof BoxAndWhiskerItem)) {
230: return false;
231: }
232: BoxAndWhiskerItem that = (BoxAndWhiskerItem) obj;
233: if (!ObjectUtilities.equal(this .mean, that.mean)) {
234: return false;
235: }
236: if (!ObjectUtilities.equal(this .median, that.median)) {
237: return false;
238: }
239: if (!ObjectUtilities.equal(this .q1, that.q1)) {
240: return false;
241: }
242: if (!ObjectUtilities.equal(this .q3, that.q3)) {
243: return false;
244: }
245: if (!ObjectUtilities.equal(this .minRegularValue,
246: that.minRegularValue)) {
247: return false;
248: }
249: if (!ObjectUtilities.equal(this .maxRegularValue,
250: that.maxRegularValue)) {
251: return false;
252: }
253: if (!ObjectUtilities.equal(this .minOutlier, that.minOutlier)) {
254: return false;
255: }
256: if (!ObjectUtilities.equal(this .maxOutlier, that.maxOutlier)) {
257: return false;
258: }
259: if (!ObjectUtilities.equal(this .outliers, that.outliers)) {
260: return false;
261: }
262: return true;
263: }
264:
265: }
|