Merge from the pain train
[official-gcc.git] / libjava / javax / xml / datatype / XMLGregorianCalendar.java
blob48280381c9c8dd500cbfd2551d07ac0926d187a3
1 /* XMLGregorianCalendar.java --
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.xml.datatype;
40 import java.math.BigDecimal;
41 import java.math.BigInteger;
42 import java.util.GregorianCalendar;
43 import java.util.Locale;
44 import java.util.TimeZone;
45 import javax.xml.namespace.QName;
47 /**
48 * An XML Schema 1.0 date/time data type.
50 * @author (a href='mailto:dog@gnu.org'>Chris Burdess</a)
51 * @since 1.3
53 public abstract class XMLGregorianCalendar
54 implements Cloneable
57 /**
58 * Resets all fields to undefined.
60 public abstract void clear();
62 /**
63 * Resets all fields to their original values.
65 public abstract void reset();
67 public abstract void setYear(BigInteger year);
69 public abstract void setYear(int year);
71 public abstract void setMonth(int month);
73 public abstract void setDay(int day);
75 public abstract void setTimezone(int offset);
77 public void setTime(int hour, int minute, int second)
79 setHour(hour);
80 setMinute(minute);
81 setSecond(second);
84 public abstract void setHour(int hour);
86 public abstract void setMinute(int minute);
88 public abstract void setSecond(int second);
90 public abstract void setMillisecond(int millisecond);
92 public abstract void setFractionalSecond(BigDecimal fractional);
94 public void setTime(int hour, int minute, int second, BigDecimal fractional)
96 setHour(hour);
97 setMinute(minute);
98 setSecond(second);
99 setFractionalSecond(fractional);
102 public void setTime(int hour, int minute, int second, int millisecond)
104 setHour(hour);
105 setMinute(minute);
106 setSecond(second);
107 setMillisecond(millisecond);
110 public abstract BigInteger getEon();
112 public abstract int getYear();
114 public abstract BigInteger getEonAndYear();
116 public abstract int getMonth();
118 public abstract int getDay();
120 public abstract int getTimezone();
122 public abstract int getHour();
124 public abstract int getMinute();
126 public abstract int getSecond();
128 public int getMillisecond()
130 BigDecimal factor = BigDecimal.valueOf(1000L);
131 BigDecimal val = getFractionalSecond().multiply(factor);
132 return val.intValue();
135 public abstract BigDecimal getFractionalSecond();
137 public abstract int compare(XMLGregorianCalendar xmlGregorianCalendar);
139 public abstract XMLGregorianCalendar normalize();
141 public boolean equals(Object obj)
143 if (obj instanceof XMLGregorianCalendar)
145 XMLGregorianCalendar xgc = (XMLGregorianCalendar) obj;
146 BigInteger y1 = getEonAndYear();
147 BigInteger y2 = xgc.getEonAndYear();
148 BigDecimal f1 = getFractionalSecond();
149 BigDecimal f2 = xgc.getFractionalSecond();
150 return ((y1 == null && y2 == null) || (y1 != null && y1.equals(y2))) &&
151 getMonth() == xgc.getMonth() &&
152 getDay() == xgc.getDay() &&
153 getTimezone() == xgc.getTimezone() &&
154 getHour() == xgc.getHour() &&
155 getMinute() == xgc.getMinute() &&
156 getSecond() == xgc.getSecond() &&
157 ((f1 == null && f2 == null) || (f1 != null && f1.equals(f2)));
159 return false;
162 public int hashCode()
164 int hash = 0;
165 BigInteger y = getEonAndYear();
166 BigDecimal f = getFractionalSecond();
167 if (y != null)
169 hash *= 31 + y.hashCode();
171 hash *= 31 + getMonth();
172 hash *= 31 + getDay();
173 hash *= 31 + getTimezone();
174 hash *= 31 + getHour();
175 hash *= 31 + getMinute();
176 hash *= 31 + getSecond();
177 if (f != null)
179 hash *= 31 + f.hashCode();
181 return hash;
185 * Returns the XML Schema lexical representation of this calendar.
187 public abstract String toXMLFormat();
189 public abstract QName getXMLSchemaType();
191 public String toString()
193 return toXMLFormat();
197 * Determines the validity of this calendar by
198 * <code>getXMLSchemaType</code> constraints.
200 public abstract boolean isValid();
203 * Adds the specified duration to this calendar.
205 public abstract void add(Duration duration);
207 public abstract GregorianCalendar toGregorianCalendar();
209 public abstract GregorianCalendar toGregorianCalendar(TimeZone timezone,
210 Locale locale,
211 XMLGregorianCalendar defaults);
213 public abstract TimeZone getTimeZone(int defaultZoneoffset);
215 public abstract Object clone();