Source for org.jfree.data.statistics.HistogramBin

   1: /* ===========================================================
   2:  * JFreeChart : a free chart library for the Java(tm) platform
   3:  * ===========================================================
   4:  *
   5:  * (C) Copyright 2000-2007, 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
  20:  * License along with this library; if not, write to the Free Software
  21:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
  22:  * USA.  
  23:  *
  24:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
  25:  * in the United States and other countries.]
  26:  *
  27:  * -----------------
  28:  * HistogramBin.java
  29:  * -----------------
  30:  * (C) Copyright 2003-2007, by Jelai Wang and Contributors.
  31:  *
  32:  * Original Author:  Jelai Wang (jelaiw AT mindspring.com);
  33:  * Contributor(s):   David Gilbert (for Object Refinery Limited);
  34:  *
  35:  * Changes
  36:  * -------
  37:  * 06-Jul-2003 : Version 1, contributed by Jelai Wang (DG);
  38:  * 07-Jul-2003 : Changed package and added Javadocs (DG);
  39:  * 01-Mar-2004 : Moved from org.jfree.data --> org.jfree.data.statistics (DG);
  40:  * ------------- JFREECHART 1.0.x ---------------------------------------------
  41:  * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG);
  42:  * 
  43:  */
  44: 
  45: package org.jfree.data.statistics;
  46: 
  47: import java.io.Serializable;
  48: 
  49: /**
  50:  * A bin for the {@link HistogramDataset} class.
  51:  */
  52: public class HistogramBin implements Cloneable, Serializable {
  53:     
  54:     /** For serialization. */
  55:     private static final long serialVersionUID = 7614685080015589931L;
  56:     
  57:     /** The number of items in the bin. */
  58:     private int count;
  59:     
  60:     /** The start boundary. */
  61:     private double startBoundary;
  62:     
  63:     /** The end boundary. */
  64:     private double endBoundary;
  65: 
  66:     /**
  67:      * Creates a new bin.
  68:      * 
  69:      * @param startBoundary  the start boundary.
  70:      * @param endBoundary  the end boundary.
  71:      */
  72:     public HistogramBin(double startBoundary, double endBoundary) {
  73:         if (startBoundary > endBoundary) {
  74:             throw new IllegalArgumentException(
  75:                     "HistogramBin():  startBoundary > endBoundary.");
  76:         }
  77:         this.count = 0;
  78:         this.startBoundary = startBoundary;
  79:         this.endBoundary = endBoundary;
  80:     }
  81: 
  82:     /**
  83:      * Returns the number of items in the bin.
  84:      * 
  85:      * @return The item count.
  86:      */
  87:     public int getCount() {
  88:         return this.count;
  89:     }
  90:     
  91:     /**
  92:      * Increments the item count.
  93:      */
  94:     public void incrementCount() {
  95:         this.count++;
  96:     }
  97:     
  98:     /**
  99:      * 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: }