KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > statistics > HistogramBin


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, 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-2006, 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  * $Id: HistogramBin.java,v 1.4.2.2 2006/08/03 09:36:18 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 06-Jul-2003 : Version 1, contributed by Jelai Wang (DG);
40  * 07-Jul-2003 : Changed package and added Javadocs (DG);
41  * 01-Mar-2004 : Moved from org.jfree.data --> org.jfree.data.statistics (DG);
42  *
43  */

44
45 package org.jfree.data.statistics;
46
47 import java.io.Serializable JavaDoc;
48
49 /**
50  * A bin for the {@link HistogramDataset} class.
51  *
52  * @author Jelai Wang, jelaiw AT mindspring.com
53  */

54 public class HistogramBin implements Cloneable JavaDoc, Serializable JavaDoc {
55     
56     /** For serialization. */
57     private static final long serialVersionUID = 7614685080015589931L;
58     
59     /** The number of items in the bin. */
60     private int count;
61     
62     /** The start boundary. */
63     private double startBoundary;
64     
65     /** The end boundary. */
66     private double endBoundary;
67
68     /**
69      * Creates a new bin.
70      *
71      * @param startBoundary the start boundary.
72      * @param endBoundary the end boundary.
73      */

74     public HistogramBin(double startBoundary, double endBoundary) {
75         if (startBoundary > endBoundary) {
76             throw new IllegalArgumentException JavaDoc(
77                     "HistogramBin(): startBoundary > endBoundary.");
78         }
79         this.count = 0;
80         this.startBoundary = startBoundary;
81         this.endBoundary = endBoundary;
82     }
83
84     /**
85      * Returns the number of items in the bin.
86      *
87      * @return The item count.
88      */

89     public int getCount() {
90         return this.count;
91     }
92     
93     /**
94      * Increments the item count.
95      */

96     public void incrementCount() {
97         this.count++;
98     }
99     
100     /**
101      * Returns the start boundary.
102      *
103      * @return The start boundary.
104      */

105     public double getStartBoundary() {
106         return this.startBoundary;
107     }
108     
109     /**
110      * Returns the end boundary.
111      *
112      * @return The end boundary.
113      */

114     public double getEndBoundary() {
115         return this.endBoundary;
116     }
117     
118     /**
119      * Returns the bin width.
120      *
121      * @return The bin width.
122      */

123     public double getBinWidth() {
124         return this.endBoundary - this.startBoundary;
125     }
126     
127     /**
128      * Tests this object for equality with an arbitrary object.
129      *
130      * @param obj the object to test against.
131      *
132      * @return A boolean.
133      */

134     public boolean equals(Object JavaDoc obj) {
135         if (obj == null) {
136             return false;
137         }
138         if (obj == this) {
139             return true;
140         }
141         if (obj instanceof HistogramBin) {
142             HistogramBin bin = (HistogramBin) obj;
143             boolean b0 = bin.startBoundary == this.startBoundary;
144             boolean b1 = bin.endBoundary == this.endBoundary;
145             boolean b2 = bin.count == this.count;
146             return b0 && b1 && b2;
147         }
148         return false;
149     }
150     
151     /**
152      * Returns a clone of the bin.
153      *
154      * @return A clone.
155      *
156      * @throws CloneNotSupportedException not thrown by this class.
157      */

158     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
159         return super.clone();
160     }
161     
162 }
163
Popular Tags