1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2005, 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 under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * -----------------
  25. * HistogramBin.java
  26. * -----------------
  27. * (C) Copyright 2003-2005, by Jelai Wang and Contributors.
  28. *
  29. * Original Author: Jelai Wang (jelaiw AT mindspring.com);
  30. * Contributor(s): David Gilbert (for Object Refinery Limited);
  31. *
  32. * $Id: HistogramBin.java,v 1.2 2005/01/14 17:30:46 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 06-Jul-2003 : Version 1, contributed by Jelai Wang (DG);
  37. * 07-Jul-2003 : Changed package and added Javadocs (DG);
  38. * 01-Mar-2004 : Moved from org.jfree.data --> org.jfree.data.statistics (DG);
  39. *
  40. */
  41. package org.jfree.data.statistics;
  42. import java.io.Serializable;
  43. /**
  44. * A bin for the {@link HistogramDataset} class.
  45. *
  46. * @author Jelai Wang, jelaiw AT mindspring.com
  47. */
  48. public class HistogramBin implements Cloneable, Serializable {
  49. /** The number of items in the bin. */
  50. private int count;
  51. /** The start boundary. */
  52. private double startBoundary;
  53. /** The end boundary. */
  54. private double endBoundary;
  55. /**
  56. * Creates a new bin.
  57. *
  58. * @param startBoundary the start boundary.
  59. * @param endBoundary the end boundary.
  60. */
  61. public HistogramBin(double startBoundary, double endBoundary) {
  62. if (startBoundary > endBoundary) {
  63. throw new IllegalArgumentException(
  64. "HistogramBin(): startBoundary > endBoundary."
  65. );
  66. }
  67. this.count = 0;
  68. this.startBoundary = startBoundary;
  69. this.endBoundary = endBoundary;
  70. }
  71. /**
  72. * Returns the number of items in the bin.
  73. *
  74. * @return The item count.
  75. */
  76. public int getCount() {
  77. return this.count;
  78. }
  79. /**
  80. * Increments the item count.
  81. */
  82. public void incrementCount() {
  83. this.count++;
  84. }
  85. /**
  86. * Returns the start boundary.
  87. *
  88. * @return The start boundary.
  89. */
  90. public double getStartBoundary() {
  91. return this.startBoundary;
  92. }
  93. /**
  94. * Returns the end boundary.
  95. *
  96. * @return The end boundary.
  97. */
  98. public double getEndBoundary() {
  99. return this.endBoundary;
  100. }
  101. /**
  102. * Returns the bin width.
  103. *
  104. * @return The bin width.
  105. */
  106. public double getBinWidth() {
  107. return this.endBoundary - this.startBoundary;
  108. }
  109. /**
  110. * Tests this object for equality with an arbitrary object.
  111. *
  112. * @param obj the object to test against.
  113. *
  114. * @return A boolean.
  115. */
  116. public boolean equals(Object obj) {
  117. if (obj == null) {
  118. return false;
  119. }
  120. if (obj == this) {
  121. return true;
  122. }
  123. if (obj instanceof HistogramBin) {
  124. HistogramBin bin = (HistogramBin) obj;
  125. boolean b0 = bin.startBoundary == this.startBoundary;
  126. boolean b1 = bin.endBoundary == this.endBoundary;
  127. boolean b2 = bin.count == this.count;
  128. return b0 && b1 && b2;
  129. }
  130. return false;
  131. }
  132. /**
  133. * Returns a clone of the bin.
  134. *
  135. * @return A clone.
  136. *
  137. * @throws CloneNotSupportedException not thrown by this class.
  138. */
  139. public Object clone() throws CloneNotSupportedException {
  140. return super.clone();
  141. }
  142. }