author | rriggs |
Fri, 20 Dec 2013 13:06:23 -0500 | |
changeset 22081 | 86eb26ff8f2b |
parent 20519 | eee7a92074fd |
child 22082 | 31eb413d0153 |
permissions | -rw-r--r-- |
15658 | 1 |
/* |
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
/* |
|
27 |
* Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos |
|
28 |
* |
|
29 |
* All rights reserved. |
|
30 |
* |
|
31 |
* Redistribution and use in source and binary forms, with or without |
|
32 |
* modification, are permitted provided that the following conditions are met: |
|
33 |
* |
|
34 |
* * Redistributions of source code must retain the above copyright notice, |
|
35 |
* this list of conditions and the following disclaimer. |
|
36 |
* |
|
37 |
* * Redistributions in binary form must reproduce the above copyright notice, |
|
38 |
* this list of conditions and the following disclaimer in the documentation |
|
39 |
* and/or other materials provided with the distribution. |
|
40 |
* |
|
41 |
* * Neither the name of JSR-310 nor the names of its contributors |
|
42 |
* may be used to endorse or promote products derived from this software |
|
43 |
* without specific prior written permission. |
|
44 |
* |
|
45 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
46 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
47 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
48 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
49 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
50 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
51 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
52 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
53 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
54 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
55 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
56 |
*/ |
|
57 |
package java.time.chrono; |
|
58 |
||
59 |
import static java.time.chrono.MinguoChronology.YEARS_DIFFERENCE; |
|
60 |
import static java.time.temporal.ChronoField.DAY_OF_MONTH; |
|
61 |
import static java.time.temporal.ChronoField.MONTH_OF_YEAR; |
|
62 |
import static java.time.temporal.ChronoField.YEAR; |
|
63 |
||
64 |
import java.io.DataInput; |
|
65 |
import java.io.DataOutput; |
|
66 |
import java.io.IOException; |
|
19841
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
67 |
import java.io.InvalidObjectException; |
22081 | 68 |
import java.io.ObjectInputStream; |
15658 | 69 |
import java.io.Serializable; |
70 |
import java.time.Clock; |
|
71 |
import java.time.DateTimeException; |
|
72 |
import java.time.LocalDate; |
|
73 |
import java.time.LocalTime; |
|
74 |
import java.time.Period; |
|
75 |
import java.time.ZoneId; |
|
76 |
import java.time.temporal.ChronoField; |
|
77 |
import java.time.temporal.TemporalAccessor; |
|
78 |
import java.time.temporal.TemporalAdjuster; |
|
79 |
import java.time.temporal.TemporalAmount; |
|
80 |
import java.time.temporal.TemporalField; |
|
16852 | 81 |
import java.time.temporal.TemporalQuery; |
15658 | 82 |
import java.time.temporal.TemporalUnit; |
16852 | 83 |
import java.time.temporal.UnsupportedTemporalTypeException; |
15658 | 84 |
import java.time.temporal.ValueRange; |
85 |
import java.util.Objects; |
|
86 |
||
87 |
/** |
|
88 |
* A date in the Minguo calendar system. |
|
89 |
* <p> |
|
90 |
* This date operates using the {@linkplain MinguoChronology Minguo calendar}. |
|
91 |
* This calendar system is primarily used in the Republic of China, often known as Taiwan. |
|
92 |
* Dates are aligned such that {@code 0001-01-01 (Minguo)} is {@code 1912-01-01 (ISO)}. |
|
93 |
* |
|
17474 | 94 |
* @implSpec |
15658 | 95 |
* This class is immutable and thread-safe. |
96 |
* |
|
97 |
* @since 1.8 |
|
98 |
*/ |
|
99 |
public final class MinguoDate |
|
20518 | 100 |
extends ChronoLocalDateImpl<MinguoDate> |
19030 | 101 |
implements ChronoLocalDate, Serializable { |
15658 | 102 |
|
103 |
/** |
|
104 |
* Serialization version. |
|
105 |
*/ |
|
106 |
private static final long serialVersionUID = 1300372329181994526L; |
|
107 |
||
108 |
/** |
|
109 |
* The underlying date. |
|
110 |
*/ |
|
19841
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
111 |
private final transient LocalDate isoDate; |
15658 | 112 |
|
113 |
//----------------------------------------------------------------------- |
|
114 |
/** |
|
115 |
* Obtains the current {@code MinguoDate} from the system clock in the default time-zone. |
|
116 |
* <p> |
|
117 |
* This will query the {@link Clock#systemDefaultZone() system clock} in the default |
|
118 |
* time-zone to obtain the current date. |
|
119 |
* <p> |
|
120 |
* Using this method will prevent the ability to use an alternate clock for testing |
|
121 |
* because the clock is hard-coded. |
|
122 |
* |
|
123 |
* @return the current date using the system clock and default time-zone, not null |
|
124 |
*/ |
|
125 |
public static MinguoDate now() { |
|
126 |
return now(Clock.systemDefaultZone()); |
|
127 |
} |
|
128 |
||
129 |
/** |
|
130 |
* Obtains the current {@code MinguoDate} from the system clock in the specified time-zone. |
|
131 |
* <p> |
|
132 |
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date. |
|
133 |
* Specifying the time-zone avoids dependence on the default time-zone. |
|
134 |
* <p> |
|
135 |
* Using this method will prevent the ability to use an alternate clock for testing |
|
136 |
* because the clock is hard-coded. |
|
137 |
* |
|
138 |
* @param zone the zone ID to use, not null |
|
139 |
* @return the current date using the system clock, not null |
|
140 |
*/ |
|
141 |
public static MinguoDate now(ZoneId zone) { |
|
142 |
return now(Clock.system(zone)); |
|
143 |
} |
|
144 |
||
145 |
/** |
|
146 |
* Obtains the current {@code MinguoDate} from the specified clock. |
|
147 |
* <p> |
|
148 |
* This will query the specified clock to obtain the current date - today. |
|
149 |
* Using this method allows the use of an alternate clock for testing. |
|
150 |
* The alternate clock may be introduced using {@linkplain Clock dependency injection}. |
|
151 |
* |
|
152 |
* @param clock the clock to use, not null |
|
153 |
* @return the current date, not null |
|
154 |
* @throws DateTimeException if the current date cannot be obtained |
|
155 |
*/ |
|
156 |
public static MinguoDate now(Clock clock) { |
|
19030 | 157 |
return new MinguoDate(LocalDate.now(clock)); |
15658 | 158 |
} |
159 |
||
160 |
/** |
|
161 |
* Obtains a {@code MinguoDate} representing a date in the Minguo calendar |
|
162 |
* system from the proleptic-year, month-of-year and day-of-month fields. |
|
163 |
* <p> |
|
164 |
* This returns a {@code MinguoDate} with the specified fields. |
|
165 |
* The day must be valid for the year and month, otherwise an exception will be thrown. |
|
166 |
* |
|
167 |
* @param prolepticYear the Minguo proleptic-year |
|
168 |
* @param month the Minguo month-of-year, from 1 to 12 |
|
169 |
* @param dayOfMonth the Minguo day-of-month, from 1 to 31 |
|
170 |
* @return the date in Minguo calendar system, not null |
|
171 |
* @throws DateTimeException if the value of any field is out of range, |
|
172 |
* or if the day-of-month is invalid for the month-year |
|
173 |
*/ |
|
174 |
public static MinguoDate of(int prolepticYear, int month, int dayOfMonth) { |
|
175 |
return new MinguoDate(LocalDate.of(prolepticYear + YEARS_DIFFERENCE, month, dayOfMonth)); |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* Obtains a {@code MinguoDate} from a temporal object. |
|
180 |
* <p> |
|
181 |
* This obtains a date in the Minguo calendar system based on the specified temporal. |
|
182 |
* A {@code TemporalAccessor} represents an arbitrary set of date and time information, |
|
183 |
* which this factory converts to an instance of {@code MinguoDate}. |
|
184 |
* <p> |
|
185 |
* The conversion typically uses the {@link ChronoField#EPOCH_DAY EPOCH_DAY} |
|
186 |
* field, which is standardized across calendar systems. |
|
187 |
* <p> |
|
188 |
* This method matches the signature of the functional interface {@link TemporalQuery} |
|
189 |
* allowing it to be used as a query via method reference, {@code MinguoDate::from}. |
|
190 |
* |
|
191 |
* @param temporal the temporal object to convert, not null |
|
192 |
* @return the date in Minguo calendar system, not null |
|
193 |
* @throws DateTimeException if unable to convert to a {@code MinguoDate} |
|
194 |
*/ |
|
195 |
public static MinguoDate from(TemporalAccessor temporal) { |
|
196 |
return MinguoChronology.INSTANCE.date(temporal); |
|
197 |
} |
|
198 |
||
199 |
//----------------------------------------------------------------------- |
|
200 |
/** |
|
201 |
* Creates an instance from an ISO date. |
|
202 |
* |
|
203 |
* @param isoDate the standard local date, validated not null |
|
204 |
*/ |
|
205 |
MinguoDate(LocalDate isoDate) { |
|
206 |
Objects.requireNonNull(isoDate, "isoDate"); |
|
207 |
this.isoDate = isoDate; |
|
208 |
} |
|
209 |
||
210 |
//----------------------------------------------------------------------- |
|
16852 | 211 |
/** |
212 |
* Gets the chronology of this date, which is the Minguo calendar system. |
|
213 |
* <p> |
|
214 |
* The {@code Chronology} represents the calendar system in use. |
|
215 |
* The era and other fields in {@link ChronoField} are defined by the chronology. |
|
216 |
* |
|
217 |
* @return the Minguo chronology, not null |
|
218 |
*/ |
|
15658 | 219 |
@Override |
220 |
public MinguoChronology getChronology() { |
|
221 |
return MinguoChronology.INSTANCE; |
|
222 |
} |
|
223 |
||
16852 | 224 |
/** |
225 |
* Gets the era applicable at this date. |
|
226 |
* <p> |
|
227 |
* The Minguo calendar system has two eras, 'ROC' and 'BEFORE_ROC', |
|
228 |
* defined by {@link MinguoEra}. |
|
229 |
* |
|
230 |
* @return the era applicable at this date, not null |
|
231 |
*/ |
|
232 |
@Override |
|
233 |
public MinguoEra getEra() { |
|
234 |
return (getProlepticYear() >= 1 ? MinguoEra.ROC : MinguoEra.BEFORE_ROC); |
|
235 |
} |
|
236 |
||
237 |
/** |
|
238 |
* Returns the length of the month represented by this date. |
|
239 |
* <p> |
|
240 |
* This returns the length of the month in days. |
|
241 |
* Month lengths match those of the ISO calendar system. |
|
242 |
* |
|
243 |
* @return the length of the month in days |
|
244 |
*/ |
|
15658 | 245 |
@Override |
246 |
public int lengthOfMonth() { |
|
247 |
return isoDate.lengthOfMonth(); |
|
248 |
} |
|
249 |
||
16852 | 250 |
//----------------------------------------------------------------------- |
15658 | 251 |
@Override |
252 |
public ValueRange range(TemporalField field) { |
|
253 |
if (field instanceof ChronoField) { |
|
254 |
if (isSupported(field)) { |
|
255 |
ChronoField f = (ChronoField) field; |
|
256 |
switch (f) { |
|
257 |
case DAY_OF_MONTH: |
|
258 |
case DAY_OF_YEAR: |
|
259 |
case ALIGNED_WEEK_OF_MONTH: |
|
260 |
return isoDate.range(field); |
|
261 |
case YEAR_OF_ERA: { |
|
262 |
ValueRange range = YEAR.range(); |
|
263 |
long max = (getProlepticYear() <= 0 ? -range.getMinimum() + 1 + YEARS_DIFFERENCE : range.getMaximum() - YEARS_DIFFERENCE); |
|
264 |
return ValueRange.of(1, max); |
|
265 |
} |
|
266 |
} |
|
267 |
return getChronology().range(f); |
|
268 |
} |
|
19030 | 269 |
throw new UnsupportedTemporalTypeException("Unsupported field: " + field); |
15658 | 270 |
} |
271 |
return field.rangeRefinedBy(this); |
|
272 |
} |
|
273 |
||
274 |
@Override |
|
275 |
public long getLong(TemporalField field) { |
|
276 |
if (field instanceof ChronoField) { |
|
277 |
switch ((ChronoField) field) { |
|
16852 | 278 |
case PROLEPTIC_MONTH: |
279 |
return getProlepticMonth(); |
|
15658 | 280 |
case YEAR_OF_ERA: { |
281 |
int prolepticYear = getProlepticYear(); |
|
282 |
return (prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear); |
|
283 |
} |
|
284 |
case YEAR: |
|
285 |
return getProlepticYear(); |
|
286 |
case ERA: |
|
287 |
return (getProlepticYear() >= 1 ? 1 : 0); |
|
288 |
} |
|
289 |
return isoDate.getLong(field); |
|
290 |
} |
|
291 |
return field.getFrom(this); |
|
292 |
} |
|
293 |
||
16852 | 294 |
private long getProlepticMonth() { |
295 |
return getProlepticYear() * 12L + isoDate.getMonthValue() - 1; |
|
296 |
} |
|
297 |
||
15658 | 298 |
private int getProlepticYear() { |
299 |
return isoDate.getYear() - YEARS_DIFFERENCE; |
|
300 |
} |
|
301 |
||
302 |
//----------------------------------------------------------------------- |
|
303 |
@Override |
|
304 |
public MinguoDate with(TemporalField field, long newValue) { |
|
305 |
if (field instanceof ChronoField) { |
|
306 |
ChronoField f = (ChronoField) field; |
|
307 |
if (getLong(f) == newValue) { |
|
308 |
return this; |
|
309 |
} |
|
310 |
switch (f) { |
|
16852 | 311 |
case PROLEPTIC_MONTH: |
312 |
getChronology().range(f).checkValidValue(newValue, f); |
|
313 |
return plusMonths(newValue - getProlepticMonth()); |
|
15658 | 314 |
case YEAR_OF_ERA: |
315 |
case YEAR: |
|
316 |
case ERA: { |
|
16852 | 317 |
int nvalue = getChronology().range(f).checkValidIntValue(newValue, f); |
15658 | 318 |
switch (f) { |
319 |
case YEAR_OF_ERA: |
|
320 |
return with(isoDate.withYear(getProlepticYear() >= 1 ? nvalue + YEARS_DIFFERENCE : (1 - nvalue) + YEARS_DIFFERENCE)); |
|
321 |
case YEAR: |
|
322 |
return with(isoDate.withYear(nvalue + YEARS_DIFFERENCE)); |
|
323 |
case ERA: |
|
324 |
return with(isoDate.withYear((1 - getProlepticYear()) + YEARS_DIFFERENCE)); |
|
325 |
} |
|
326 |
} |
|
327 |
} |
|
328 |
return with(isoDate.with(field, newValue)); |
|
329 |
} |
|
19030 | 330 |
return super.with(field, newValue); |
15658 | 331 |
} |
332 |
||
333 |
/** |
|
334 |
* {@inheritDoc} |
|
335 |
* @throws DateTimeException {@inheritDoc} |
|
336 |
* @throws ArithmeticException {@inheritDoc} |
|
337 |
*/ |
|
338 |
@Override |
|
339 |
public MinguoDate with(TemporalAdjuster adjuster) { |
|
16852 | 340 |
return super.with(adjuster); |
15658 | 341 |
} |
342 |
||
343 |
/** |
|
344 |
* {@inheritDoc} |
|
345 |
* @throws DateTimeException {@inheritDoc} |
|
346 |
* @throws ArithmeticException {@inheritDoc} |
|
347 |
*/ |
|
348 |
@Override |
|
349 |
public MinguoDate plus(TemporalAmount amount) { |
|
16852 | 350 |
return super.plus(amount); |
15658 | 351 |
} |
352 |
||
353 |
/** |
|
354 |
* {@inheritDoc} |
|
355 |
* @throws DateTimeException {@inheritDoc} |
|
356 |
* @throws ArithmeticException {@inheritDoc} |
|
357 |
*/ |
|
358 |
@Override |
|
359 |
public MinguoDate minus(TemporalAmount amount) { |
|
16852 | 360 |
return super.minus(amount); |
15658 | 361 |
} |
362 |
||
363 |
//----------------------------------------------------------------------- |
|
364 |
@Override |
|
365 |
MinguoDate plusYears(long years) { |
|
366 |
return with(isoDate.plusYears(years)); |
|
367 |
} |
|
368 |
||
369 |
@Override |
|
370 |
MinguoDate plusMonths(long months) { |
|
371 |
return with(isoDate.plusMonths(months)); |
|
372 |
} |
|
373 |
||
374 |
@Override |
|
19030 | 375 |
MinguoDate plusWeeks(long weeksToAdd) { |
376 |
return super.plusWeeks(weeksToAdd); |
|
377 |
} |
|
378 |
||
379 |
@Override |
|
15658 | 380 |
MinguoDate plusDays(long days) { |
381 |
return with(isoDate.plusDays(days)); |
|
382 |
} |
|
383 |
||
384 |
@Override |
|
385 |
public MinguoDate plus(long amountToAdd, TemporalUnit unit) { |
|
16852 | 386 |
return super.plus(amountToAdd, unit); |
15658 | 387 |
} |
388 |
||
389 |
@Override |
|
390 |
public MinguoDate minus(long amountToAdd, TemporalUnit unit) { |
|
16852 | 391 |
return super.minus(amountToAdd, unit); |
15658 | 392 |
} |
393 |
||
394 |
@Override |
|
395 |
MinguoDate minusYears(long yearsToSubtract) { |
|
16852 | 396 |
return super.minusYears(yearsToSubtract); |
15658 | 397 |
} |
398 |
||
399 |
@Override |
|
400 |
MinguoDate minusMonths(long monthsToSubtract) { |
|
16852 | 401 |
return super.minusMonths(monthsToSubtract); |
15658 | 402 |
} |
403 |
||
404 |
@Override |
|
405 |
MinguoDate minusWeeks(long weeksToSubtract) { |
|
16852 | 406 |
return super.minusWeeks(weeksToSubtract); |
15658 | 407 |
} |
408 |
||
409 |
@Override |
|
410 |
MinguoDate minusDays(long daysToSubtract) { |
|
16852 | 411 |
return super.minusDays(daysToSubtract); |
15658 | 412 |
} |
413 |
||
414 |
private MinguoDate with(LocalDate newDate) { |
|
415 |
return (newDate.equals(isoDate) ? this : new MinguoDate(newDate)); |
|
416 |
} |
|
417 |
||
418 |
@Override // for javadoc and covariant return type |
|
19030 | 419 |
@SuppressWarnings("unchecked") |
15658 | 420 |
public final ChronoLocalDateTime<MinguoDate> atTime(LocalTime localTime) { |
19030 | 421 |
return (ChronoLocalDateTime<MinguoDate>)super.atTime(localTime); |
15658 | 422 |
} |
423 |
||
424 |
@Override |
|
20519
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
20518
diff
changeset
|
425 |
public ChronoPeriod until(ChronoLocalDate endDate) { |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
20518
diff
changeset
|
426 |
Period period = isoDate.until(endDate); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
20518
diff
changeset
|
427 |
return getChronology().period(period.getYears(), period.getMonths(), period.getDays()); |
15658 | 428 |
} |
429 |
||
430 |
@Override // override for performance |
|
431 |
public long toEpochDay() { |
|
432 |
return isoDate.toEpochDay(); |
|
433 |
} |
|
434 |
||
435 |
//------------------------------------------------------------------------- |
|
436 |
@Override // override for performance |
|
437 |
public boolean equals(Object obj) { |
|
438 |
if (this == obj) { |
|
439 |
return true; |
|
440 |
} |
|
441 |
if (obj instanceof MinguoDate) { |
|
442 |
MinguoDate otherDate = (MinguoDate) obj; |
|
443 |
return this.isoDate.equals(otherDate.isoDate); |
|
444 |
} |
|
445 |
return false; |
|
446 |
} |
|
447 |
||
448 |
@Override // override for performance |
|
449 |
public int hashCode() { |
|
450 |
return getChronology().getId().hashCode() ^ isoDate.hashCode(); |
|
451 |
} |
|
452 |
||
453 |
//----------------------------------------------------------------------- |
|
19841
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
454 |
/** |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
455 |
* Defend against malicious streams. |
22081 | 456 |
* |
19841
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
457 |
* @throws InvalidObjectException always |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
458 |
*/ |
22081 | 459 |
private void readObject(ObjectInputStream s) throws InvalidObjectException { |
19841
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
460 |
throw new InvalidObjectException("Deserialization via serialization delegate"); |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
461 |
} |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
462 |
|
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
463 |
/** |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
464 |
* Writes the object using a |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
465 |
* <a href="../../../serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>. |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
466 |
* @serialData |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
467 |
* <pre> |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
468 |
* out.writeByte(8); // identifies a MinguoDate |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
469 |
* out.writeInt(get(YEAR)); |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
470 |
* out.writeByte(get(MONTH_OF_YEAR)); |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
471 |
* out.writeByte(get(DAY_OF_MONTH)); |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
472 |
* </pre> |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
473 |
* |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
474 |
* @return the instance of {@code Ser}, not null |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
475 |
*/ |
15658 | 476 |
private Object writeReplace() { |
477 |
return new Ser(Ser.MINGUO_DATE_TYPE, this); |
|
478 |
} |
|
479 |
||
480 |
void writeExternal(DataOutput out) throws IOException { |
|
481 |
// MinguoChronology is implicit in the MINGUO_DATE_TYPE |
|
482 |
out.writeInt(get(YEAR)); |
|
483 |
out.writeByte(get(MONTH_OF_YEAR)); |
|
484 |
out.writeByte(get(DAY_OF_MONTH)); |
|
485 |
} |
|
486 |
||
19030 | 487 |
static MinguoDate readExternal(DataInput in) throws IOException { |
15658 | 488 |
int year = in.readInt(); |
489 |
int month = in.readByte(); |
|
490 |
int dayOfMonth = in.readByte(); |
|
491 |
return MinguoChronology.INSTANCE.date(year, month, dayOfMonth); |
|
492 |
} |
|
493 |
||
494 |
} |