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. * HistogramType.java
  26. * ------------------
  27. * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): -;
  31. *
  32. * $Id: HistogramType.java,v 1.2 2005/01/14 17:31:00 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 05-Mar-2004 : Version 1 (DG);
  37. *
  38. */
  39. package org.jfree.data.statistics;
  40. import java.io.ObjectStreamException;
  41. import java.io.Serializable;
  42. /**
  43. * A class for creating constants to represent the histogram type. See Bloch's enum tip in
  44. * 'Effective Java'
  45. */
  46. public class HistogramType implements Serializable {
  47. /** Frequency histogram. */
  48. public static final HistogramType FREQUENCY = new HistogramType("FREQUENCY");
  49. /** Relative frequency. */
  50. public static final HistogramType RELATIVE_FREQUENCY = new HistogramType("RELATIVE_FREQUENCY");
  51. /** Scale area to one. */
  52. public static final HistogramType SCALE_AREA_TO_1 = new HistogramType("SCALE_AREA_TO_1");
  53. /** The type name. */
  54. private String name;
  55. /**
  56. * Creates a new type.
  57. *
  58. * @param name the name.
  59. */
  60. private HistogramType(String name) {
  61. this.name = name;
  62. }
  63. /**
  64. * Returns a string representing the object.
  65. *
  66. * @return The string.
  67. */
  68. public String toString() {
  69. return this.name;
  70. }
  71. /**
  72. * Tests this type for equality with an arbitrary object.
  73. *
  74. * @param obj the object to test against.
  75. *
  76. * @return A boolean.
  77. */
  78. public boolean equals(Object obj) {
  79. if (obj == null) {
  80. return false;
  81. }
  82. if (obj == this) {
  83. return true;
  84. }
  85. if (!(obj instanceof HistogramType)) {
  86. return false;
  87. }
  88. HistogramType t = (HistogramType) obj;
  89. if (!this.name.equals(t.name)) {
  90. return false;
  91. }
  92. return true;
  93. }
  94. /**
  95. * Returns a hash code value for the object.
  96. *
  97. * @return The hashcode
  98. */
  99. public int hashCode() {
  100. return this.name.hashCode();
  101. }
  102. /**
  103. * Ensures that serialization returns the unique instances.
  104. *
  105. * @return The object.
  106. *
  107. * @throws ObjectStreamException if there is a problem.
  108. */
  109. private Object readResolve() throws ObjectStreamException {
  110. if (this.equals(HistogramType.FREQUENCY)) {
  111. return HistogramType.FREQUENCY;
  112. }
  113. else if (this.equals(HistogramType.RELATIVE_FREQUENCY)) {
  114. return HistogramType.RELATIVE_FREQUENCY;
  115. }
  116. else if (this.equals(HistogramType.SCALE_AREA_TO_1)) {
  117. return HistogramType.SCALE_AREA_TO_1;
  118. }
  119. return null;
  120. }
  121. }