KickJava   Java API By Example, From Geeks To Geeks.

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


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  * OutlierListCollection.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): -;
34  *
35  * $Id: OutlierListCollection.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  * 01-Sep-2003 : Made storage internal rather than extending ArrayList (DG);
41  *
42  */

43
44 package org.jfree.chart.renderer;
45
46 import java.util.ArrayList JavaDoc;
47 import java.util.Iterator JavaDoc;
48 import java.util.List JavaDoc;
49
50 /**
51  * A collection of outlier lists for a box and whisker plot. Each collection is
52  * associated with a single box and whisker entity.
53  *
54  * Outliers are grouped in lists for each entity. Lists contain
55  * one or more outliers, determined by whether overlaps have
56  * occurred. Overlapping outliers are grouped in the same list.
57  *
58  * @see org.jfree.chart.renderer.OutlierList
59  *
60  * @author David Browning
61  */

62 public class OutlierListCollection {
63
64     /** Storage for the outlier lists. */
65     private List JavaDoc outlierLists;
66     
67     /**
68      * Unbelievably, outliers which are more than 2 * interquartile range are
69      * called far outs... See Tukey EDA (a classic one of a kind...)
70      */

71     private boolean highFarOut = false;
72
73     /**
74      * A flag that indicates whether or not the collection contains low far
75      * out values.
76      */

77     private boolean lowFarOut = false;
78     
79     /**
80      * Creates a new empty collection.
81      */

82     public OutlierListCollection() {
83         this.outlierLists = new ArrayList JavaDoc();
84     }
85     
86     /**
87      * A flag to indicate the presence of one or more far out values at the
88      * top end of the range.
89      *
90      * @return A <code>boolean</code>.
91      */

92     public boolean isHighFarOut() {
93         return this.highFarOut;
94     }
95
96     /**
97      * Sets the flag that indicates the presence of one or more far out values
98      * at the top end of the range.
99      *
100      * @param farOut the flag.
101      */

102     public void setHighFarOut(boolean farOut) {
103         this.highFarOut = farOut;
104     }
105
106     /**
107      * A flag to indicate the presence of one or more far out values at the
108      * bottom end of the range.
109      *
110      * @return A <code>boolean</code>.
111      */

112     public boolean isLowFarOut() {
113         return this.lowFarOut;
114     }
115
116     /**
117      * Sets the flag that indicates the presence of one or more far out values
118      * at the bottom end of the range.
119      *
120      * @param farOut the flag.
121      */

122     public void setLowFarOut(boolean farOut) {
123         this.lowFarOut = farOut;
124     }
125     /**
126      * Appends the specified element as a new <code>OutlierList</code> to the
127      * end of this list if it does not overlap an outlier in an existing list.
128      *
129      * If it does overlap, it is appended to the outlier list which it overlaps
130      * and that list is updated.
131      *
132      * @param outlier element to be appended to this list.
133      *
134      * @return <tt>true</tt> (as per the general contract of Collection.add).
135      */

136     public boolean add(Outlier outlier) {
137
138         if (this.outlierLists.isEmpty()) {
139             return this.outlierLists.add(new OutlierList(outlier));
140         }
141         else {
142             boolean updated = false;
143             for (Iterator JavaDoc iterator = this.outlierLists.iterator();
144                  iterator.hasNext();) {
145                 OutlierList list = (OutlierList) iterator.next();
146                 if (list.isOverlapped(outlier)) {
147                     updated = updateOutlierList(list, outlier);
148                 }
149             }
150             if (!updated) {
151                 //System.err.print(" creating new outlier list ");
152
updated = this.outlierLists.add(new OutlierList(outlier));
153             }
154             return updated;
155         }
156
157     }
158
159     /**
160      * Returns an iterator for the outlier lists.
161      *
162      * @return An iterator.
163      */

164     public Iterator JavaDoc iterator() {
165         return this.outlierLists.iterator();
166     }
167     
168     
169     /**
170      * Updates the outlier list by adding the outlier to the end of the list and
171      * setting the averaged outlier to the average x and y coordinnate values
172      * of the outliers in the list.
173      *
174      * @param list the outlier list to be updated.
175      * @param outlier the outlier to be added
176      *
177      * @return <tt>true</tt> (as per the general contract of Collection.add).
178      */

179     private boolean updateOutlierList(OutlierList list, Outlier outlier) {
180         boolean result = false;
181         result = list.add(outlier);
182         list.updateAveragedOutlier();
183         list.setMultiple(true);
184         return result;
185     }
186
187 }
188
Popular Tags