KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > renderer > OutlierList


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ----------------
27  * OutlierList.java
28  * ----------------
29  * (C) Copyright 2003, 2004, by David Browning and Contributors.
30  *
31  * Original Author: David Browning (for Australian Institute of Marine
32  * Science);
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * $Id: OutlierList.java,v 1.2 2005/02/09 13:57:23 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 05-Aug-2003 : Version 1, contributed by David Browning (DG);
40  * 28-Aug-2003 : Minor tidy-up including Javadocs (DG);
41  *
42  */

43 package org.jfree.chart.renderer;
44
45 import java.awt.geom.Point2D JavaDoc;
46 import java.util.ArrayList JavaDoc;
47 import java.util.Iterator JavaDoc;
48 import java.util.List JavaDoc;
49
50 /**
51  * A collection of outliers for a single entity in a box and whisker plot.
52  *
53  * Outliers are grouped in lists for each entity. Lists contain
54  * one or more outliers, determined by whether overlaps have
55  * occured. Overlapping outliers are grouped in the same list.
56  *
57  * Each list contains an averaged outlier, which is the same as a single
58  * outlier if there is only one outlier in the list, but the average of
59  * all the outliers in the list if there is more than one.
60  *
61  * NB This is simply my scheme for displaying outliers, and might not be
62  * acceptable by the wider community.
63  *
64  * @author David Browning
65  */

66 public class OutlierList {
67
68     /** Storage for the outliers. */
69     private List JavaDoc outliers;
70     
71     /** The averaged outlier. */
72     private Outlier averagedOutlier;
73     
74     /**
75      * A flag that indicates whether or not there are multiple outliers in the
76      * list.
77      */

78     private boolean multiple = false;
79
80     /**
81      * Creates a new list containing a single outlier.
82      *
83      * @param outlier the outlier.
84      */

85     public OutlierList(Outlier outlier) {
86         this.outliers = new ArrayList JavaDoc();
87         setAveragedOutlier(outlier);
88     }
89
90     /**
91      * Adds an outlier to the list.
92      *
93      * @param outlier the outlier.
94      *
95      * @return A boolean.
96      */

97     public boolean add(Outlier outlier) {
98         return this.outliers.add(outlier);
99     }
100     
101     /**
102      * Returns the number of outliers in the list.
103      *
104      * @return The item count.
105      */

106     public int getItemCount() {
107         return this.outliers.size();
108     }
109     
110     /**
111      * Returns the averaged outlier.
112      *
113      * @return The averaged outlier.
114      */

115     public Outlier getAveragedOutlier() {
116         return this.averagedOutlier;
117     }
118
119     /**
120      * Sets the averaged outlier.
121      *
122      * @param averagedOutlier the averaged outlier.
123      */

124     public void setAveragedOutlier(Outlier averagedOutlier) {
125         this.averagedOutlier = averagedOutlier;
126     }
127
128     /**
129      * Returns <code>true</code> if the list contains multiple outliers, and
130      * <code>false</code> otherwise.
131      *
132      * @return A boolean.
133      */

134     public boolean isMultiple() {
135         return this.multiple;
136     }
137
138     /**
139      * Sets the flag that indicates whether or not this list represents
140      * multiple outliers.
141      *
142      * @param multiple the flag.
143      */

144     public void setMultiple(boolean multiple) {
145         this.multiple = multiple;
146     }
147
148     /**
149      * Returns <code>true</code> if the outlier overlaps, and
150      * <code>false</code> otherwise.
151      *
152      * @param other the outlier.
153      *
154      * @return A boolean.
155      */

156     public boolean isOverlapped(Outlier other) {
157
158         if (other == null) {
159             return false;
160         }
161         
162         boolean result = other.overlaps(getAveragedOutlier());
163         return result;
164         
165     }
166
167     /**
168      * Updates the averaged outlier.
169      *
170      */

171     public void updateAveragedOutlier() {
172         double totalXCoords = 0.0;
173         double totalYCoords = 0.0;
174         int size = getItemCount();
175         for (Iterator JavaDoc iterator = this.outliers.iterator();
176              iterator.hasNext();) {
177             Outlier o = (Outlier) iterator.next();
178             totalXCoords += o.getX();
179             totalYCoords += o.getY();
180         }
181         getAveragedOutlier().getPoint().setLocation(
182             new Point2D.Double JavaDoc(totalXCoords / size, totalYCoords / size)
183         );
184     }
185
186 }
187
Popular Tags