001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2005, 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     * HistogramBin.java
029     * -----------------
030     * (C) Copyright 2003-2005, by Jelai Wang and Contributors.
031     *
032     * Original Author:  Jelai Wang (jelaiw AT mindspring.com);
033     * Contributor(s):   David Gilbert (for Object Refinery Limited);
034     *
035     * $Id: HistogramBin.java,v 1.4.2.1 2005/10/25 21:34:46 mungady Exp $
036     *
037     * Changes
038     * -------
039     * 06-Jul-2003 : Version 1, contributed by Jelai Wang (DG);
040     * 07-Jul-2003 : Changed package and added Javadocs (DG);
041     * 01-Mar-2004 : Moved from org.jfree.data --> org.jfree.data.statistics (DG);
042     * 
043     */
044    
045    package org.jfree.data.statistics;
046    
047    import java.io.Serializable;
048    
049    /**
050     * A bin for the {@link HistogramDataset} class.
051     *
052     * @author Jelai Wang, jelaiw AT mindspring.com
053     */
054    public class HistogramBin implements Cloneable, Serializable {
055        
056        /** For serialization. */
057        private static final long serialVersionUID = 7614685080015589931L;
058        
059        /** The number of items in the bin. */
060        private int count;
061        
062        /** The start boundary. */
063        private double startBoundary;
064        
065        /** The end boundary. */
066        private double endBoundary;
067    
068        /**
069         * Creates a new bin.
070         * 
071         * @param startBoundary  the start boundary.
072         * @param endBoundary  the end boundary.
073         */
074        public HistogramBin(double startBoundary, double endBoundary) {
075            if (startBoundary > endBoundary) {
076                throw new IllegalArgumentException(
077                    "HistogramBin():  startBoundary > endBoundary."
078                );
079            }
080            this.count = 0;
081            this.startBoundary = startBoundary;
082            this.endBoundary = endBoundary;
083        }
084    
085        /**
086         * Returns the number of items in the bin.
087         * 
088         * @return The item count.
089         */
090        public int getCount() {
091            return this.count;
092        }
093        
094        /**
095         * Increments the item count.
096         */
097        public void incrementCount() {
098            this.count++;
099        }
100        
101        /**
102         * Returns the start boundary.
103         * 
104         * @return The start boundary.
105         */
106        public double getStartBoundary() {
107            return this.startBoundary;
108        }
109        
110        /**
111         * Returns the end boundary.
112         * 
113         * @return The end boundary.
114         */
115        public double getEndBoundary() {
116            return this.endBoundary;
117        }
118        
119        /**
120         * Returns the bin width.
121         * 
122         * @return The bin width.
123         */
124        public double getBinWidth() {
125            return this.endBoundary - this.startBoundary;
126        }
127        
128        /**
129         * Tests this object for equality with an arbitrary object.
130         * 
131         * @param obj  the object to test against.
132         * 
133         * @return A boolean.
134         */
135        public boolean equals(Object obj) {
136            if (obj == null) {
137                return false;   
138            }
139            if (obj == this) {
140                return true;   
141            }
142            if (obj instanceof HistogramBin) {
143                HistogramBin bin = (HistogramBin) obj;
144                boolean b0 = bin.startBoundary == this.startBoundary;
145                boolean b1 = bin.endBoundary == this.endBoundary;
146                boolean b2 = bin.count == this.count;
147                return b0 && b1 && b2;
148            }
149            return false;
150        }
151        
152        /**
153         * Returns a clone of the bin.
154         * 
155         * @return A clone.
156         * 
157         * @throws CloneNotSupportedException not thrown by this class.
158         */
159        public Object clone() throws CloneNotSupportedException {
160            return super.clone();   
161        }
162        
163    }