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. * OutlierList.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): David Gilbert (for Object Refinery Limited);
  34. *
  35. * $Id: OutlierList.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. * 28-Aug-2003 : Minor tidy-up including Javadocs (DG);
  41. *
  42. */
  43. package org.jfree.chart.renderer;
  44. import java.awt.geom.Point2D;
  45. import java.util.ArrayList;
  46. import java.util.Iterator;
  47. import java.util.List;
  48. /**
  49. * A collection of outliers for a single entity in a box and whisker plot.
  50. *
  51. * Outliers are grouped in lists for each entity. Lists contain
  52. * one or more outliers, determined by whether overlaps have
  53. * occured. Overlapping outliers are grouped in the same list.
  54. *
  55. * Each list contains an averaged outlier, which is the same as a single
  56. * outlier if there is only one outlier in the list, but the average of
  57. * all the outliers in the list if there is more than one.
  58. *
  59. * NB This is simply my scheme for displaying outliers, and might not be
  60. * acceptable by the wider community.
  61. *
  62. * @author David Browning
  63. */
  64. public class OutlierList {
  65. /** Storage for the outliers. */
  66. private List outliers;
  67. /** The averaged outlier. */
  68. private Outlier averagedOutlier;
  69. /**
  70. * A flag that indicates whether or not there are multiple outliers in the
  71. * list.
  72. */
  73. private boolean multiple = false;
  74. /**
  75. * Creates a new list containing a single outlier.
  76. *
  77. * @param outlier the outlier.
  78. */
  79. public OutlierList(Outlier outlier) {
  80. this.outliers = new ArrayList();
  81. setAveragedOutlier(outlier);
  82. }
  83. /**
  84. * Adds an outlier to the list.
  85. *
  86. * @param outlier the outlier.
  87. *
  88. * @return A boolean.
  89. */
  90. public boolean add(Outlier outlier) {
  91. return this.outliers.add(outlier);
  92. }
  93. /**
  94. * Returns the number of outliers in the list.
  95. *
  96. * @return The item count.
  97. */
  98. public int getItemCount() {
  99. return this.outliers.size();
  100. }
  101. /**
  102. * Returns the averaged outlier.
  103. *
  104. * @return The averaged outlier.
  105. */
  106. public Outlier getAveragedOutlier() {
  107. return this.averagedOutlier;
  108. }
  109. /**
  110. * Sets the averaged outlier.
  111. *
  112. * @param averagedOutlier the averaged outlier.
  113. */
  114. public void setAveragedOutlier(Outlier averagedOutlier) {
  115. this.averagedOutlier = averagedOutlier;
  116. }
  117. /**
  118. * Returns <code>true</code> if the list contains multiple outliers, and
  119. * <code>false</code> otherwise.
  120. *
  121. * @return A boolean.
  122. */
  123. public boolean isMultiple() {
  124. return this.multiple;
  125. }
  126. /**
  127. * Sets the flag that indicates whether or not this list represents
  128. * multiple outliers.
  129. *
  130. * @param multiple the flag.
  131. */
  132. public void setMultiple(boolean multiple) {
  133. this.multiple = multiple;
  134. }
  135. /**
  136. * Returns <code>true</code> if the outlier overlaps, and
  137. * <code>false</code> otherwise.
  138. *
  139. * @param other the outlier.
  140. *
  141. * @return A boolean.
  142. */
  143. public boolean isOverlapped(Outlier other) {
  144. if (other == null) {
  145. return false;
  146. }
  147. boolean result = other.overlaps(getAveragedOutlier());
  148. return result;
  149. }
  150. /**
  151. * Updates the averaged outlier.
  152. *
  153. */
  154. public void updateAveragedOutlier() {
  155. double totalXCoords = 0.0;
  156. double totalYCoords = 0.0;
  157. int size = getItemCount();
  158. for (Iterator iterator = this.outliers.iterator();
  159. iterator.hasNext();) {
  160. Outlier o = (Outlier) iterator.next();
  161. totalXCoords += o.getX();
  162. totalYCoords += o.getY();
  163. }
  164. getAveragedOutlier().getPoint().setLocation(
  165. new Point2D.Double(totalXCoords / size, totalYCoords / size)
  166. );
  167. }
  168. }