/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2020, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/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.
 *
 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
 * Other names may be trademarks of their respective owners.]
 *
 * --------------------------
 * OutlierListCollection.java
 * --------------------------
 * (C) Copyright 2003-2020, by David Browning and Contributors.
 *
 * Original Author:  David Browning (for Australian Institute of Marine
 *                   Science);
 * Contributor(s):   -;
 *
 */

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}.
     */
    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}.
     */
    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} 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;
        result = list.add(outlier);
        list.updateAveragedOutlier();
        list.setMultiple(true);
        return result;
    }

}

@@ -2155,16 +2155,29 @@
 ate List
+%3COutlierList%3E
  outlier
@@ -2184,16 +2184,16 @@
 Lists;%0D%0A
-
 %0D%0A    /*
@@ -2692,16 +2692,18 @@
 rrayList
+%3C%3E
 ();%0D%0A   
@@ -4230,26 +4230,24 @@
 outlier) %7B%0D%0A
-%0D%0A
         if (
@@ -4356,25 +4356,16 @@
        %7D
-%0D%0A       
  else %7B%0D
@@ -4424,137 +4424,33 @@
 or (
-Iterator iterator = this.outlierLists.iterator();%0D%0A                 iterator.hasNext();) %7B%0D%0A                OutlierList list = (O
+OutlierList list : this.o
 utli
@@ -4459,26 +4459,12 @@
 List
+s
 ) 
-iterator.next();
+%7B
 %0D%0A  
@@ -4644,76 +4644,8 @@
  %7B%0D%0A
-                //System.err.print(%22 creating new outlier list %22);%0D%0A
     
@@ -4767,26 +4767,24 @@
 %0A        %7D%0D%0A
-%0D%0A
     %7D%0D%0A%0D%0A   
@@ -4905,16 +4905,29 @@
 Iterator
+%3COutlierList%3E
  iterato
@@ -5147,17 +5147,16 @@
  coordin
-n
 ate valu
@@ -5469,32 +5469,32 @@
 ier outlier) %7B%0D%0A
+
         boolean 
@@ -5497,25 +5497,8 @@
 ean 
-result;%0D%0A        
 resu

Add generics.