KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > time > TimePeriodAnchor


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  * TimePeriodAnchor.java
28  * ---------------------
29  * (C) Copyright 2003, 2005, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: TimePeriodAnchor.java,v 1.5 2005/05/19 10:35:27 mungady Exp $
35  *
36  * Changes:
37  * --------
38  * 30-Jul-2003 : Version 1 (DG);
39  * 01-Mar-2004 : Added readResolve() method (DG);
40  *
41  */

42
43 package org.jfree.data.time;
44
45 import java.io.ObjectStreamException JavaDoc;
46 import java.io.Serializable JavaDoc;
47
48 /**
49  * Used to indicate one of three positions in a time period:
50  * <code>START</code>, <code>MIDDLE</code> and <code>END</code>.
51  */

52 public final class TimePeriodAnchor implements Serializable JavaDoc {
53
54     /** For serialization. */
55     private static final long serialVersionUID = 2011955697457548862L;
56     
57     /** Start of period. */
58     public static final TimePeriodAnchor START
59         = new TimePeriodAnchor("TimePeriodAnchor.START");
60
61     /** Middle of period. */
62     public static final TimePeriodAnchor MIDDLE
63         = new TimePeriodAnchor("TimePeriodAnchor.MIDDLE");
64
65     /** End of period. */
66     public static final TimePeriodAnchor END
67         = new TimePeriodAnchor("TimePeriodAnchor.END");
68
69     /** The name. */
70     private String JavaDoc name;
71
72     /**
73      * Private constructor.
74      *
75      * @param name the name.
76      */

77     private TimePeriodAnchor(String JavaDoc name) {
78         this.name = name;
79     }
80
81     /**
82      * Returns a string representing the object.
83      *
84      * @return The string.
85      */

86     public String JavaDoc toString() {
87         return this.name;
88     }
89
90     /**
91      * Returns <code>true</code> if this object is equal to the specified
92      * object, and <code>false</code> otherwise.
93      *
94      * @param obj the other object.
95      *
96      * @return A boolean.
97      */

98     public boolean equals(Object JavaDoc obj) {
99
100         if (this == obj) {
101             return true;
102         }
103         if (!(obj instanceof TimePeriodAnchor)) {
104             return false;
105         }
106
107         TimePeriodAnchor position = (TimePeriodAnchor) obj;
108         if (!this.name.equals(position.name)) {
109             return false;
110         }
111
112         return true;
113     }
114
115     /**
116      * Returns a hash code value for the object.
117      *
118      * @return The hashcode
119      */

120     public int hashCode() {
121         return this.name.hashCode();
122     }
123     
124     /**
125      * Ensures that serialization returns the unique instances.
126      *
127      * @return The object.
128      *
129      * @throws ObjectStreamException if there is a problem.
130      */

131     private Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
132         if (this.equals(TimePeriodAnchor.START)) {
133             return TimePeriodAnchor.START;
134         }
135         else if (this.equals(TimePeriodAnchor.MIDDLE)) {
136             return TimePeriodAnchor.MIDDLE;
137         }
138         else if (this.equals(TimePeriodAnchor.END)) {
139             return TimePeriodAnchor.END;
140         }
141         return null;
142     }
143
144 }
145
Popular Tags