KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > print > attribute > DateTimeSyntax


1 /*
2  * @(#)DateTimeSyntax.java 1.5 04/01/07
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8
9 package javax.print.attribute;
10
11 import java.io.Serializable JavaDoc;
12
13 import java.util.Date JavaDoc;
14
15 /**
16  * Class DateTimeSyntax is an abstract base class providing the common
17  * implementation of all attributes whose value is a date and time.
18  * <P>
19  * Under the hood, a date-time attribute is stored as a value of class <code>
20  * java.util.Date</code>}. You can get a date-time attribute's Date value by
21  * calling {@link #getValue() <CODE>getValue()</CODE>}. A date-time attribute's
22  * Date value is established when it is constructed (see {@link
23  * #DateTimeSyntax(Date) <CODE>DateTimeSyntax(Date)</CODE>}). Once
24  * constructed, a date-time attribute's value is immutable.
25  * <P>
26  * To construct a date-time attribute from separate values of the year, month,
27  * day, hour, minute, and so on, use a <code>java.util.Calendar</code>
28  * object to construct a <code>java.util.Date</code> object, then use the
29  * <code>java.util.Date</code >object to construct the date-time attribute.
30  * To convert
31  * a date-time attribute to separate values of the year, month, day, hour,
32  * minute, and so on, create a <code>java.util.Calendar</code> object and
33  * set it to the <code>java.util.Date</code> from the date-time attribute. Class
34  * DateTimeSyntax stores its value in the form of a <code>java.util.Date
35  * </code>
36  * rather than a <code>java.util.Calendar</code> because it typically takes
37  * less memory to store and less time to compare a <code>java.util.Date</code>
38  * than a <code>java.util.Calendar</code>.
39  * <P>
40  *
41  * @author Alan Kaminsky
42  */

43 public abstract class DateTimeSyntax implements Serializable JavaDoc, Cloneable JavaDoc {
44
45     private static final long serialVersionUID = -1400819079791208582L;
46
47     // Hidden data members.
48

49     /**
50      * This date-time attribute's<code>java.util.Date</code> value.
51      * @serial
52      */

53     private Date JavaDoc value;
54
55     // Hidden constructors.
56

57     /**
58      * Construct a new date-time attribute with the given
59      * <code>java.util.Date </code> value.
60      *
61      * @param value <code>java.util.Date</code> value.
62      *
63      * @exception NullPointerException
64      * (unchecked exception) Thrown if <CODE>theValue</CODE> is null.
65      */

66     protected DateTimeSyntax(Date JavaDoc value) {
67     if (value == null) {
68         throw new NullPointerException JavaDoc("value is null");
69     }
70     this.value = value;
71     }
72     
73     // Exported operations.
74

75     /**
76      * Returns this date-time attribute's <code>java.util.Date</code>
77      * value.
78      * @return the Date.
79      */

80     public Date JavaDoc getValue() {
81     return new Date JavaDoc (value.getTime());
82     }
83     
84     // Exported operations inherited and overridden from class Object.
85

86     /**
87      * Returns whether this date-time attribute is equivalent to the passed in
88      * object. To be equivalent, all of the following conditions must be true:
89      * <OL TYPE=1>
90      * <LI>
91      * <CODE>object</CODE> is not null.
92      * <LI>
93      * <CODE>object</CODE> is an instance of class DateTimeSyntax.
94      * <LI>
95      * This date-time attribute's <code>java.util.Date</code> value and
96      * <CODE>object</CODE>'s <code>java.util.Date</code> value are
97      * equal. </OL>
98      *
99      * @param object Object to compare to.
100      *
101      * @return True if <CODE>object</CODE> is equivalent to this date-time
102      * attribute, false otherwise.
103      */

104     public boolean equals(Object JavaDoc object) {
105     return (object != null &&
106             object instanceof DateTimeSyntax JavaDoc &&
107         value.equals(((DateTimeSyntax JavaDoc) object).value));
108     }
109     
110     /**
111      * Returns a hash code value for this date-time attribute. The hashcode is
112      * that of this attribute's <code>java.util.Date</code> value.
113      */

114     public int hashCode() {
115     return value.hashCode();
116     }
117     
118     /**
119      * Returns a string value corresponding to this date-time attribute.
120      * The string value is just this attribute's
121      * <code>java.util.Date</code> value
122      * converted to a string.
123      */

124     public String JavaDoc toString() {
125     return "" + value;
126     }
127
128 }
129
Popular Tags