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
  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 License
  20. * along with this library; if not, write to the Free Software Foundation,
  21. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  24. * in the United States and other countries.]
  25. *
  26. * --------------
  27. * RangeType.java
  28. * --------------
  29. * (C) Copyright 2005, by Object Refinery Limited.
  30. *
  31. * Original Author: David Gilbert (for Object Refinery Limited);
  32. * Contributor(s): -;
  33. *
  34. * $Id: RangeType.java,v 1.1 2005/02/24 23:30:54 mungady Exp $
  35. *
  36. * Changes:
  37. * --------
  38. * 24-Feb-2005 : Version 1 (DG);
  39. *
  40. */
  41. package org.jfree.data;
  42. import java.io.ObjectStreamException;
  43. import java.io.Serializable;
  44. /**
  45. * Used to indicate sorting order if any (ascending, descending or none).
  46. */
  47. public final class RangeType implements Serializable {
  48. /** Full range (positive and negative). */
  49. public static final RangeType FULL = new RangeType("RangeType.FULL");
  50. /** Positive range. */
  51. public static final RangeType POSITIVE
  52. = new RangeType("RangeType.POSITIVE");
  53. /** Negative range. */
  54. public static final RangeType NEGATIVE
  55. = new RangeType("RangeType.NEGATIVE");
  56. /** The name. */
  57. private String name;
  58. /**
  59. * Private constructor.
  60. *
  61. * @param name the name.
  62. */
  63. private RangeType(String name) {
  64. this.name = name;
  65. }
  66. /**
  67. * Returns a string representing the object.
  68. *
  69. * @return The string.
  70. */
  71. public String toString() {
  72. return this.name;
  73. }
  74. /**
  75. * Returns <code>true</code> if this object is equal to the specified
  76. * object, and <code>false</code> otherwise.
  77. *
  78. * @param obj the other object.
  79. *
  80. * @return A boolean.
  81. */
  82. public boolean equals(Object obj) {
  83. if (this == obj) {
  84. return true;
  85. }
  86. if (!(obj instanceof RangeType)) {
  87. return false;
  88. }
  89. RangeType that = (RangeType) obj;
  90. if (!this.name.equals(that.toString())) {
  91. return false;
  92. }
  93. return true;
  94. }
  95. /**
  96. * Returns a hash code value for the object.
  97. *
  98. * @return The hashcode
  99. */
  100. public int hashCode() {
  101. return this.name.hashCode();
  102. }
  103. /**
  104. * Ensures that serialization returns the unique instances.
  105. *
  106. * @return The object.
  107. *
  108. * @throws ObjectStreamException if there is a problem.
  109. */
  110. private Object readResolve() throws ObjectStreamException {
  111. if (this.equals(RangeType.FULL)) {
  112. return RangeType.FULL;
  113. }
  114. else if (this.equals(RangeType.POSITIVE)) {
  115. return RangeType.POSITIVE;
  116. }
  117. else if (this.equals(RangeType.NEGATIVE)) {
  118. return RangeType.NEGATIVE;
  119. }
  120. return null;
  121. }
  122. }