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. package org.jfree.chart.renderer;
  44. import java.util.ArrayList;
  45. import java.util.Iterator;
  46. import java.util.List;
  47. /**
  48. * A collection of outlier lists for a box and whisker plot. Each collection is
  49. * associated with a single box and whisker entity.
  50. *
  51. * Outliers are grouped in lists for each entity. Lists contain
  52. * one or more outliers, determined by whether overlaps have
  53. * occurred. Overlapping outliers are grouped in the same list.
  54. *
  55. * @see org.jfree.chart.renderer.OutlierList
  56. *
  57. * @author David Browning
  58. */
  59. public class OutlierListCollection {
  60. /** Storage for the outlier lists. */
  61. private List outlierLists;
  62. /**
  63. * Unbelievably, outliers which are more than 2 * interquartile range are
  64. * called far outs... See Tukey EDA (a classic one of a kind...)
  65. */
  66. private boolean highFarOut = false;
  67. /**
  68. * A flag that indicates whether or not the collection contains low far
  69. * out values.
  70. */
  71. private boolean lowFarOut = false;
  72. /**
  73. * Creates a new empty collection.
  74. */
  75. public OutlierListCollection() {
  76. this.outlierLists = new ArrayList();
  77. }
  78. /**
  79. * A flag to indicate the presence of one or more far out values at the
  80. * top end of the range.
  81. *
  82. * @return A <code>boolean</code>.
  83. */
  84. public boolean isHighFarOut() {
  85. return this.highFarOut;
  86. }
  87. /**
  88. * Sets the flag that indicates the presence of one or more far out values
  89. * at the top end of the range.
  90. *
  91. * @param farOut the flag.
  92. */
  93. public void setHighFarOut(boolean farOut) {
  94. this.highFarOut = farOut;
  95. }
  96. /**
  97. * A flag to indicate the presence of one or more far out values at the
  98. * bottom end of the range.
  99. *
  100. * @return A <code>boolean</code>.
  101. */
  102. public boolean isLowFarOut() {
  103. return this.lowFarOut;
  104. }
  105. /**
  106. * Sets the flag that indicates the presence of one or more far out values
  107. * at the bottom end of the range.
  108. *
  109. * @param farOut the flag.
  110. */
  111. public void setLowFarOut(boolean farOut) {
  112. this.lowFarOut = farOut;
  113. }
  114. /**
  115. * Appends the specified element as a new <code>OutlierList</code> to the
  116. * end of this list if it does not overlap an outlier in an existing list.
  117. *
  118. * If it does overlap, it is appended to the outlier list which it overlaps
  119. * and that list is updated.
  120. *
  121. * @param outlier element to be appended to this list.
  122. *
  123. * @return <tt>true</tt> (as per the general contract of Collection.add).
  124. */
  125. public boolean add(Outlier outlier) {
  126. if (this.outlierLists.isEmpty()) {
  127. return this.outlierLists.add(new OutlierList(outlier));
  128. }
  129. else {
  130. boolean updated = false;
  131. for (Iterator iterator = this.outlierLists.iterator();
  132. iterator.hasNext();) {
  133. OutlierList list = (OutlierList) iterator.next();
  134. if (list.isOverlapped(outlier)) {
  135. updated = updateOutlierList(list, outlier);
  136. }
  137. }
  138. if (!updated) {
  139. //System.err.print(" creating new outlier list ");
  140. updated = this.outlierLists.add(new OutlierList(outlier));
  141. }
  142. return updated;
  143. }
  144. }
  145. /**
  146. * Returns an iterator for the outlier lists.
  147. *
  148. * @return An iterator.
  149. */
  150. public Iterator iterator() {
  151. return this.outlierLists.iterator();
  152. }
  153. /**
  154. * Updates the outlier list by adding the outlier to the end of the list and
  155. * setting the averaged outlier to the average x and y coordinnate values
  156. * of the outliers in the list.
  157. *
  158. * @param list the outlier list to be updated.
  159. * @param outlier the outlier to be added
  160. *
  161. * @return <tt>true</tt> (as per the general contract of Collection.add).
  162. */
  163. private boolean updateOutlierList(OutlierList list, Outlier outlier) {
  164. boolean result = false;
  165. result = list.add(outlier);
  166. list.updateAveragedOutlier();
  167. list.setMultiple(true);
  168. return result;
  169. }
  170. }