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. * TimePeriodAnchor.java
  26. * ---------------------
  27. * (C) Copyright 2003, 2005, by Object Refinery Limited.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): -;
  31. *
  32. * $Id: TimePeriodAnchor.java,v 1.2 2005/01/13 22:09:34 mungady Exp $
  33. *
  34. * Changes:
  35. * --------
  36. * 30-Jul-2003 : Version 1 (DG);
  37. * 01-Mar-2004 : Added readResolve() method (DG);
  38. *
  39. */
  40. package org.jfree.data.time;
  41. import java.io.ObjectStreamException;
  42. import java.io.Serializable;
  43. /**
  44. * Used to indicate one of three positions in a time period: <code>START</code>,
  45. * <code>MIDDLE</code> and <code>END</code>.
  46. */
  47. public final class TimePeriodAnchor implements Serializable {
  48. /** Start of period. */
  49. public static final TimePeriodAnchor START = new TimePeriodAnchor("TimePeriodAnchor.START");
  50. /** Middle of period. */
  51. public static final TimePeriodAnchor MIDDLE = new TimePeriodAnchor("TimePeriodAnchor.MIDDLE");
  52. /** End of period. */
  53. public static final TimePeriodAnchor END = new TimePeriodAnchor("TimePeriodAnchor.END");
  54. /** The name. */
  55. private String name;
  56. /**
  57. * Private constructor.
  58. *
  59. * @param name the name.
  60. */
  61. private TimePeriodAnchor(String name) {
  62. this.name = name;
  63. }
  64. /**
  65. * Returns a string representing the object.
  66. *
  67. * @return The string.
  68. */
  69. public String toString() {
  70. return this.name;
  71. }
  72. /**
  73. * Returns <code>true</code> if this object is equal to the specified object, and
  74. * <code>false</code> otherwise.
  75. *
  76. * @param obj the other object.
  77. *
  78. * @return A boolean.
  79. */
  80. public boolean equals(Object obj) {
  81. if (this == obj) {
  82. return true;
  83. }
  84. if (!(obj instanceof TimePeriodAnchor)) {
  85. return false;
  86. }
  87. TimePeriodAnchor position = (TimePeriodAnchor) obj;
  88. if (!this.name.equals(position.name)) {
  89. return false;
  90. }
  91. return true;
  92. }
  93. /**
  94. * Returns a hash code value for the object.
  95. *
  96. * @return The hashcode
  97. */
  98. public int hashCode() {
  99. return this.name.hashCode();
  100. }
  101. /**
  102. * Ensures that serialization returns the unique instances.
  103. *
  104. * @return The object.
  105. *
  106. * @throws ObjectStreamException if there is a problem.
  107. */
  108. private Object readResolve() throws ObjectStreamException {
  109. if (this.equals(TimePeriodAnchor.START)) {
  110. return TimePeriodAnchor.START;
  111. }
  112. else if (this.equals(TimePeriodAnchor.MIDDLE)) {
  113. return TimePeriodAnchor.MIDDLE;
  114. }
  115. else if (this.equals(TimePeriodAnchor.END)) {
  116. return TimePeriodAnchor.END;
  117. }
  118. return null;
  119. }
  120. }