001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
006     *
007     * Project Info:  http://www.jfree.org/jfreechart/index.html
008     *
009     * This library is free software; you can redistribute it and/or modify it
010     * under the terms of the GNU Lesser General Public License as published by
011     * the Free Software Foundation; either version 2.1 of the License, or
012     * (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but
015     * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016     * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017     * License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this library; if not, write to the Free Software
021     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022     * USA.
023     *
024     * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025     * in the United States and other countries.]
026     *
027     * ------------
028     * Outlier.java
029     * ------------
030     * (C) Copyright 2003-2008, by David Browning and Contributors.
031     *
032     * Original Author:  David Browning (for Australian Institute of Marine
033     *                   Science);
034     * Contributor(s):   David Gilbert (for Object Refinery Limited);
035     *
036     * Changes
037     * -------
038     * 05-Aug-2003 : Version 1, contributed by David Browning (DG);
039     * 28-Aug-2003 : Minor tidy-up (DG);
040     * ------------- JFREECHART 1.0.x ---------------------------------------------
041     * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG);
042     * 21-Nov-2007 : Implemented equals() to shut up FindBugs (DG);
043     *
044     */
045    
046    package org.jfree.chart.renderer;
047    
048    import java.awt.geom.Point2D;
049    
050    /**
051     * Represents one outlier in the box and whisker plot.
052     * <P>
053     * All the coordinates in this class are in Java2D space.
054     */
055    public class Outlier implements Comparable {
056    
057        /**
058         * The xy coordinates of the bounding box containing the outlier ellipse.
059         */
060        private Point2D point;
061    
062        /** The radius of the ellipse */
063        private double radius;
064    
065        /**
066         * Constructs an outlier item consisting of a point and the radius of the
067         * outlier ellipse
068         *
069         * @param xCoord  the x coordinate of the point.
070         * @param yCoord  the y coordinate of the point.
071         * @param radius  the radius of the ellipse.
072         */
073        public Outlier(double xCoord, double yCoord, double radius) {
074            this.point = new Point2D.Double(xCoord - radius, yCoord - radius);
075            this.radius = radius;
076        }
077    
078        /**
079         * Returns the xy coordinates of the bounding box containing the outlier
080         * ellipse.
081         *
082         * @return The location of the outlier ellipse.
083         */
084        public Point2D getPoint() {
085            return this.point;
086        }
087    
088        /**
089         * Sets the xy coordinates of the bounding box containing the outlier
090         * ellipse.
091         *
092         * @param point  the location.
093         */
094        public void setPoint(Point2D point) {
095            this.point = point;
096        }
097    
098        /**
099         * Returns the x coordinate of the bounding box containing the outlier
100         * ellipse.
101         *
102         * @return The x coordinate.
103         */
104        public double getX() {
105            return getPoint().getX();
106        }
107    
108        /**
109         * Returns the y coordinate of the bounding box containing the outlier
110         * ellipse.
111         *
112         * @return The y coordinate.
113         */
114        public double getY() {
115            return getPoint().getY();
116        }
117    
118        /**
119         * Returns the radius of the outlier ellipse.
120         *
121         * @return The radius.
122         */
123        public double getRadius() {
124            return this.radius;
125        }
126    
127        /**
128         * Sets the radius of the outlier ellipse.
129         *
130         * @param radius  the new radius.
131         */
132        public void setRadius(double radius) {
133            this.radius = radius;
134        }
135    
136        /**
137         * Compares this object with the specified object for order, based on
138         * the outlier's point.
139         *
140         * @param   o the Object to be compared.
141         * @return A negative integer, zero, or a positive integer as this object
142         *      is less than, equal to, or greater than the specified object.
143         *
144         */
145        public int compareTo(Object o) {
146            Outlier outlier = (Outlier) o;
147            Point2D p1 = getPoint();
148            Point2D p2 = outlier.getPoint();
149            if (p1.equals(p2)) {
150                return 0;
151            }
152            else if ((p1.getX() < p2.getX()) || (p1.getY() < p2.getY())) {
153                return -1;
154            }
155            else {
156                return 1;
157            }
158        }
159    
160        /**
161         * Returns a true if outlier is overlapped and false if it is not.
162         * Overlapping is determined by the respective bounding boxes plus
163         * a small margin.
164         *
165         * @param other  the other outlier.
166         *
167         * @return A <code>boolean</code> indicating whether or not an overlap has
168         *         occurred.
169         */
170        public boolean overlaps(Outlier other) {
171            return ((other.getX() >= getX() - (this.radius * 1.1))
172                    && (other.getX() <= getX() + (this.radius * 1.1))
173                    && (other.getY() >= getY() - (this.radius * 1.1))
174                    && (other.getY() <= getY() + (this.radius * 1.1)));
175        }
176    
177        /**
178         * Tests this outlier for equality with an arbitrary object.
179         *
180         * @param obj  the object (<code>null</code> permitted).
181         *
182         * @return A boolean.
183         */
184        public boolean equals(Object obj) {
185            if (obj == this) {
186                return true;
187            }
188            if (!(obj instanceof Outlier)) {
189                return false;
190            }
191            Outlier that = (Outlier) obj;
192            if (!this.point.equals(that.point)) {
193                return false;
194            }
195            if (this.radius != that.radius) {
196                return false;
197            }
198            return true;
199        }
200    
201        /**
202         * Returns a textual representation of the outlier.
203         *
204         * @return A <code>String</code> representing the outlier.
205         */
206        public String toString() {
207            return "{" + getX() + "," + getY() + "}";
208        }
209    
210    }