Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, 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 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * -------------------------- 28: * OutlierListCollection.java 29: * -------------------------- 30: * (C) Copyright 2003, 2004, 2007, by David Browning and Contributors. 31: * 32: * Original Author: David Browning (for Australian Institute of Marine 33: * Science); 34: * Contributor(s): -; 35: * 36: * $Id: OutlierListCollection.java,v 1.2.2.2 2007/02/02 15:52:24 mungady Exp $ 37: * 38: * Changes 39: * ------- 40: * 05-Aug-2003 : Version 1, contributed by David Browning (DG); 41: * 01-Sep-2003 : Made storage internal rather than extending ArrayList (DG); 42: * ------------- JFREECHART 1.0.x --------------------------------------------- 43: * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG); 44: * 45: */ 46: 47: package org.jfree.chart.renderer; 48: 49: import java.util.ArrayList; 50: import java.util.Iterator; 51: import java.util.List; 52: 53: /** 54: * A collection of outlier lists for a box and whisker plot. Each collection is 55: * associated with a single box and whisker entity. 56: * 57: * Outliers are grouped in lists for each entity. Lists contain 58: * one or more outliers, determined by whether overlaps have 59: * occurred. Overlapping outliers are grouped in the same list. 60: * 61: * @see org.jfree.chart.renderer.OutlierList 62: */ 63: public class OutlierListCollection { 64: 65: /** Storage for the outlier lists. */ 66: private List outlierLists; 67: 68: /** 69: * Unbelievably, outliers which are more than 2 * interquartile range are 70: * called far outs... See Tukey EDA (a classic one of a kind...) 71: */ 72: private boolean highFarOut = false; 73: 74: /** 75: * A flag that indicates whether or not the collection contains low far 76: * out values. 77: */ 78: private boolean lowFarOut = false; 79: 80: /** 81: * Creates a new empty collection. 82: */ 83: public OutlierListCollection() { 84: this.outlierLists = new ArrayList(); 85: } 86: 87: /** 88: * A flag to indicate the presence of one or more far out values at the 89: * top end of the range. 90: * 91: * @return A <code>boolean</code>. 92: */ 93: public boolean isHighFarOut() { 94: return this.highFarOut; 95: } 96: 97: /** 98: * Sets the flag that indicates the presence of one or more far out values 99: * at the top end of the range. 100: * 101: * @param farOut the flag. 102: */ 103: public void setHighFarOut(boolean farOut) { 104: this.highFarOut = farOut; 105: } 106: 107: /** 108: * A flag to indicate the presence of one or more far out values at the 109: * bottom end of the range. 110: * 111: * @return A <code>boolean</code>. 112: */ 113: public boolean isLowFarOut() { 114: return this.lowFarOut; 115: } 116: 117: /** 118: * Sets the flag that indicates the presence of one or more far out values 119: * at the bottom end of the range. 120: * 121: * @param farOut the flag. 122: */ 123: public void setLowFarOut(boolean farOut) { 124: this.lowFarOut = farOut; 125: } 126: /** 127: * Appends the specified element as a new <code>OutlierList</code> to the 128: * end of this list if it does not overlap an outlier in an existing list. 129: * 130: * If it does overlap, it is appended to the outlier list which it overlaps 131: * and that list is updated. 132: * 133: * @param outlier element to be appended to this list. 134: * 135: * @return <tt>true</tt> (as per the general contract of Collection.add). 136: */ 137: public boolean add(Outlier outlier) { 138: 139: if (this.outlierLists.isEmpty()) { 140: return this.outlierLists.add(new OutlierList(outlier)); 141: } 142: else { 143: boolean updated = false; 144: for (Iterator iterator = this.outlierLists.iterator(); 145: iterator.hasNext();) { 146: OutlierList list = (OutlierList) iterator.next(); 147: if (list.isOverlapped(outlier)) { 148: updated = updateOutlierList(list, outlier); 149: } 150: } 151: if (!updated) { 152: //System.err.print(" creating new outlier list "); 153: updated = this.outlierLists.add(new OutlierList(outlier)); 154: } 155: return updated; 156: } 157: 158: } 159: 160: /** 161: * Returns an iterator for the outlier lists. 162: * 163: * @return An iterator. 164: */ 165: public Iterator iterator() { 166: return this.outlierLists.iterator(); 167: } 168: 169: 170: /** 171: * Updates the outlier list by adding the outlier to the end of the list and 172: * setting the averaged outlier to the average x and y coordinnate values 173: * of the outliers in the list. 174: * 175: * @param list the outlier list to be updated. 176: * @param outlier the outlier to be added 177: * 178: * @return <tt>true</tt> (as per the general contract of Collection.add). 179: */ 180: private boolean updateOutlierList(OutlierList list, Outlier outlier) { 181: boolean result = false; 182: result = list.add(outlier); 183: list.updateAveragedOutlier(); 184: list.setMultiple(true); 185: return result; 186: } 187: 188: }