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