Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/print/attribute/DateTimeSyntax.java
38918 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526package javax.print.attribute;2728import java.io.Serializable;2930import java.util.Date;3132/**33* Class DateTimeSyntax is an abstract base class providing the common34* implementation of all attributes whose value is a date and time.35* <P>36* Under the hood, a date-time attribute is stored as a value of class <code>37* java.util.Date</code>. You can get a date-time attribute's Date value by38* calling {@link #getValue() getValue()}. A date-time attribute's39* Date value is established when it is constructed (see {@link40* #DateTimeSyntax(Date) DateTimeSyntax(Date)}). Once41* constructed, a date-time attribute's value is immutable.42* <P>43* To construct a date-time attribute from separate values of the year, month,44* day, hour, minute, and so on, use a <code>java.util.Calendar</code>45* object to construct a <code>java.util.Date</code> object, then use the46* <code>java.util.Date</code> object to construct the date-time attribute.47* To convert48* a date-time attribute to separate values of the year, month, day, hour,49* minute, and so on, create a <code>java.util.Calendar</code> object and50* set it to the <code>java.util.Date</code> from the date-time attribute. Class51* DateTimeSyntax stores its value in the form of a <code>java.util.Date52* </code>53* rather than a <code>java.util.Calendar</code> because it typically takes54* less memory to store and less time to compare a <code>java.util.Date</code>55* than a <code>java.util.Calendar</code>.56* <P>57*58* @author Alan Kaminsky59*/60public abstract class DateTimeSyntax implements Serializable, Cloneable {6162private static final long serialVersionUID = -1400819079791208582L;6364// Hidden data members.6566/**67* This date-time attribute's<code>java.util.Date</code> value.68* @serial69*/70private Date value;7172// Hidden constructors.7374/**75* Construct a new date-time attribute with the given76* <code>java.util.Date </code> value.77*78* @param value <code>java.util.Date</code> value.79*80* @exception NullPointerException81* (unchecked exception) Thrown if <CODE>theValue</CODE> is null.82*/83protected DateTimeSyntax(Date value) {84if (value == null) {85throw new NullPointerException("value is null");86}87this.value = value;88}8990// Exported operations.9192/**93* Returns this date-time attribute's <code>java.util.Date</code>94* value.95* @return the Date.96*/97public Date getValue() {98return new Date (value.getTime());99}100101// Exported operations inherited and overridden from class Object.102103/**104* Returns whether this date-time attribute is equivalent to the passed in105* object. To be equivalent, all of the following conditions must be true:106* <OL TYPE=1>107* <LI>108* <CODE>object</CODE> is not null.109* <LI>110* <CODE>object</CODE> is an instance of class DateTimeSyntax.111* <LI>112* This date-time attribute's <code>java.util.Date</code> value and113* <CODE>object</CODE>'s <code>java.util.Date</code> value are114* equal. </OL>115*116* @param object Object to compare to.117*118* @return True if <CODE>object</CODE> is equivalent to this date-time119* attribute, false otherwise.120*/121public boolean equals(Object object) {122return (object != null &&123object instanceof DateTimeSyntax &&124value.equals(((DateTimeSyntax) object).value));125}126127/**128* Returns a hash code value for this date-time attribute. The hashcode is129* that of this attribute's <code>java.util.Date</code> value.130*/131public int hashCode() {132return value.hashCode();133}134135/**136* Returns a string value corresponding to this date-time attribute.137* The string value is just this attribute's138* <code>java.util.Date</code> value139* converted to a string.140*/141public String toString() {142return "" + value;143}144145}146147148