author | rriggs |
Fri, 30 Aug 2013 11:43:57 +0100 | |
changeset 20518 | dde564773845 |
parent 19841 | 15c8e97d6a14 |
child 20519 | eee7a92074fd |
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.ThaiBuddhistChronology.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; |
15658 | 68 |
import java.io.Serializable; |
69 |
import java.time.Clock; |
|
70 |
import java.time.DateTimeException; |
|
71 |
import java.time.LocalDate; |
|
72 |
import java.time.LocalTime; |
|
73 |
import java.time.Period; |
|
74 |
import java.time.ZoneId; |
|
75 |
import java.time.temporal.ChronoField; |
|
76 |
import java.time.temporal.TemporalAccessor; |
|
77 |
import java.time.temporal.TemporalAdjuster; |
|
78 |
import java.time.temporal.TemporalAmount; |
|
79 |
import java.time.temporal.TemporalField; |
|
16852 | 80 |
import java.time.temporal.TemporalQuery; |
15658 | 81 |
import java.time.temporal.TemporalUnit; |
16852 | 82 |
import java.time.temporal.UnsupportedTemporalTypeException; |
15658 | 83 |
import java.time.temporal.ValueRange; |
84 |
import java.util.Objects; |
|
85 |
||
86 |
/** |
|
87 |
* A date in the Thai Buddhist calendar system. |
|
88 |
* <p> |
|
89 |
* This date operates using the {@linkplain ThaiBuddhistChronology Thai Buddhist calendar}. |
|
90 |
* This calendar system is primarily used in Thailand. |
|
91 |
* Dates are aligned such that {@code 2484-01-01 (Buddhist)} is {@code 1941-01-01 (ISO)}. |
|
92 |
* |
|
17474 | 93 |
* @implSpec |
15658 | 94 |
* This class is immutable and thread-safe. |
95 |
* |
|
96 |
* @since 1.8 |
|
97 |
*/ |
|
98 |
public final class ThaiBuddhistDate |
|
20518 | 99 |
extends ChronoLocalDateImpl<ThaiBuddhistDate> |
19030 | 100 |
implements ChronoLocalDate, Serializable { |
15658 | 101 |
|
102 |
/** |
|
103 |
* Serialization version. |
|
104 |
*/ |
|
105 |
private static final long serialVersionUID = -8722293800195731463L; |
|
106 |
||
107 |
/** |
|
108 |
* The underlying date. |
|
109 |
*/ |
|
19841
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
110 |
private final transient LocalDate isoDate; |
15658 | 111 |
|
112 |
//----------------------------------------------------------------------- |
|
113 |
/** |
|
114 |
* Obtains the current {@code ThaiBuddhistDate} from the system clock in the default time-zone. |
|
115 |
* <p> |
|
116 |
* This will query the {@link Clock#systemDefaultZone() system clock} in the default |
|
117 |
* time-zone to obtain the current date. |
|
118 |
* <p> |
|
119 |
* Using this method will prevent the ability to use an alternate clock for testing |
|
120 |
* because the clock is hard-coded. |
|
121 |
* |
|
122 |
* @return the current date using the system clock and default time-zone, not null |
|
123 |
*/ |
|
124 |
public static ThaiBuddhistDate now() { |
|
125 |
return now(Clock.systemDefaultZone()); |
|
126 |
} |
|
127 |
||
128 |
/** |
|
129 |
* Obtains the current {@code ThaiBuddhistDate} from the system clock in the specified time-zone. |
|
130 |
* <p> |
|
131 |
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date. |
|
132 |
* Specifying the time-zone avoids dependence on the default time-zone. |
|
133 |
* <p> |
|
134 |
* Using this method will prevent the ability to use an alternate clock for testing |
|
135 |
* because the clock is hard-coded. |
|
136 |
* |
|
137 |
* @param zone the zone ID to use, not null |
|
138 |
* @return the current date using the system clock, not null |
|
139 |
*/ |
|
140 |
public static ThaiBuddhistDate now(ZoneId zone) { |
|
141 |
return now(Clock.system(zone)); |
|
142 |
} |
|
143 |
||
144 |
/** |
|
145 |
* Obtains the current {@code ThaiBuddhistDate} from the specified clock. |
|
146 |
* <p> |
|
147 |
* This will query the specified clock to obtain the current date - today. |
|
148 |
* Using this method allows the use of an alternate clock for testing. |
|
149 |
* The alternate clock may be introduced using {@linkplain Clock dependency injection}. |
|
150 |
* |
|
151 |
* @param clock the clock to use, not null |
|
152 |
* @return the current date, not null |
|
153 |
* @throws DateTimeException if the current date cannot be obtained |
|
154 |
*/ |
|
155 |
public static ThaiBuddhistDate now(Clock clock) { |
|
19030 | 156 |
return new ThaiBuddhistDate(LocalDate.now(clock)); |
15658 | 157 |
} |
158 |
||
159 |
/** |
|
160 |
* Obtains a {@code ThaiBuddhistDate} representing a date in the Thai Buddhist calendar |
|
161 |
* system from the proleptic-year, month-of-year and day-of-month fields. |
|
162 |
* <p> |
|
163 |
* This returns a {@code ThaiBuddhistDate} with the specified fields. |
|
164 |
* The day must be valid for the year and month, otherwise an exception will be thrown. |
|
165 |
* |
|
166 |
* @param prolepticYear the Thai Buddhist proleptic-year |
|
167 |
* @param month the Thai Buddhist month-of-year, from 1 to 12 |
|
168 |
* @param dayOfMonth the Thai Buddhist day-of-month, from 1 to 31 |
|
169 |
* @return the date in Thai Buddhist calendar system, not null |
|
170 |
* @throws DateTimeException if the value of any field is out of range, |
|
171 |
* or if the day-of-month is invalid for the month-year |
|
172 |
*/ |
|
173 |
public static ThaiBuddhistDate of(int prolepticYear, int month, int dayOfMonth) { |
|
174 |
return new ThaiBuddhistDate(LocalDate.of(prolepticYear - YEARS_DIFFERENCE, month, dayOfMonth)); |
|
175 |
} |
|
176 |
||
177 |
/** |
|
178 |
* Obtains a {@code ThaiBuddhistDate} from a temporal object. |
|
179 |
* <p> |
|
180 |
* This obtains a date in the Thai Buddhist calendar system based on the specified temporal. |
|
181 |
* A {@code TemporalAccessor} represents an arbitrary set of date and time information, |
|
182 |
* which this factory converts to an instance of {@code ThaiBuddhistDate}. |
|
183 |
* <p> |
|
184 |
* The conversion typically uses the {@link ChronoField#EPOCH_DAY EPOCH_DAY} |
|
185 |
* field, which is standardized across calendar systems. |
|
186 |
* <p> |
|
187 |
* This method matches the signature of the functional interface {@link TemporalQuery} |
|
188 |
* allowing it to be used as a query via method reference, {@code ThaiBuddhistDate::from}. |
|
189 |
* |
|
190 |
* @param temporal the temporal object to convert, not null |
|
191 |
* @return the date in Thai Buddhist calendar system, not null |
|
192 |
* @throws DateTimeException if unable to convert to a {@code ThaiBuddhistDate} |
|
193 |
*/ |
|
194 |
public static ThaiBuddhistDate from(TemporalAccessor temporal) { |
|
195 |
return ThaiBuddhistChronology.INSTANCE.date(temporal); |
|
196 |
} |
|
197 |
||
198 |
//----------------------------------------------------------------------- |
|
199 |
/** |
|
200 |
* Creates an instance from an ISO date. |
|
201 |
* |
|
202 |
* @param isoDate the standard local date, validated not null |
|
203 |
*/ |
|
204 |
ThaiBuddhistDate(LocalDate isoDate) { |
|
205 |
Objects.requireNonNull(isoDate, "isoDate"); |
|
206 |
this.isoDate = isoDate; |
|
207 |
} |
|
208 |
||
209 |
//----------------------------------------------------------------------- |
|
16852 | 210 |
/** |
211 |
* Gets the chronology of this date, which is the Thai Buddhist calendar system. |
|
212 |
* <p> |
|
213 |
* The {@code Chronology} represents the calendar system in use. |
|
214 |
* The era and other fields in {@link ChronoField} are defined by the chronology. |
|
215 |
* |
|
216 |
* @return the Thai Buddhist chronology, not null |
|
217 |
*/ |
|
15658 | 218 |
@Override |
219 |
public ThaiBuddhistChronology getChronology() { |
|
220 |
return ThaiBuddhistChronology.INSTANCE; |
|
221 |
} |
|
222 |
||
16852 | 223 |
/** |
224 |
* Gets the era applicable at this date. |
|
225 |
* <p> |
|
226 |
* The Thai Buddhist calendar system has two eras, 'BE' and 'BEFORE_BE', |
|
227 |
* defined by {@link ThaiBuddhistEra}. |
|
228 |
* |
|
229 |
* @return the era applicable at this date, not null |
|
230 |
*/ |
|
231 |
@Override |
|
232 |
public ThaiBuddhistEra getEra() { |
|
233 |
return (getProlepticYear() >= 1 ? ThaiBuddhistEra.BE : ThaiBuddhistEra.BEFORE_BE); |
|
234 |
} |
|
235 |
||
236 |
/** |
|
237 |
* Returns the length of the month represented by this date. |
|
238 |
* <p> |
|
239 |
* This returns the length of the month in days. |
|
240 |
* Month lengths match those of the ISO calendar system. |
|
241 |
* |
|
242 |
* @return the length of the month in days |
|
243 |
*/ |
|
15658 | 244 |
@Override |
245 |
public int lengthOfMonth() { |
|
246 |
return isoDate.lengthOfMonth(); |
|
247 |
} |
|
248 |
||
16852 | 249 |
//----------------------------------------------------------------------- |
15658 | 250 |
@Override |
251 |
public ValueRange range(TemporalField field) { |
|
252 |
if (field instanceof ChronoField) { |
|
253 |
if (isSupported(field)) { |
|
254 |
ChronoField f = (ChronoField) field; |
|
255 |
switch (f) { |
|
256 |
case DAY_OF_MONTH: |
|
257 |
case DAY_OF_YEAR: |
|
258 |
case ALIGNED_WEEK_OF_MONTH: |
|
259 |
return isoDate.range(field); |
|
260 |
case YEAR_OF_ERA: { |
|
261 |
ValueRange range = YEAR.range(); |
|
262 |
long max = (getProlepticYear() <= 0 ? -(range.getMinimum() + YEARS_DIFFERENCE) + 1 : range.getMaximum() + YEARS_DIFFERENCE); |
|
263 |
return ValueRange.of(1, max); |
|
264 |
} |
|
265 |
} |
|
266 |
return getChronology().range(f); |
|
267 |
} |
|
19030 | 268 |
throw new UnsupportedTemporalTypeException("Unsupported field: " + field); |
15658 | 269 |
} |
270 |
return field.rangeRefinedBy(this); |
|
271 |
} |
|
272 |
||
273 |
@Override |
|
274 |
public long getLong(TemporalField field) { |
|
275 |
if (field instanceof ChronoField) { |
|
276 |
switch ((ChronoField) field) { |
|
16852 | 277 |
case PROLEPTIC_MONTH: |
278 |
return getProlepticMonth(); |
|
15658 | 279 |
case YEAR_OF_ERA: { |
280 |
int prolepticYear = getProlepticYear(); |
|
281 |
return (prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear); |
|
282 |
} |
|
283 |
case YEAR: |
|
284 |
return getProlepticYear(); |
|
285 |
case ERA: |
|
286 |
return (getProlepticYear() >= 1 ? 1 : 0); |
|
287 |
} |
|
288 |
return isoDate.getLong(field); |
|
289 |
} |
|
290 |
return field.getFrom(this); |
|
291 |
} |
|
292 |
||
16852 | 293 |
private long getProlepticMonth() { |
294 |
return getProlepticYear() * 12L + isoDate.getMonthValue() - 1; |
|
295 |
} |
|
296 |
||
15658 | 297 |
private int getProlepticYear() { |
298 |
return isoDate.getYear() + YEARS_DIFFERENCE; |
|
299 |
} |
|
300 |
||
301 |
//----------------------------------------------------------------------- |
|
302 |
@Override |
|
303 |
public ThaiBuddhistDate with(TemporalField field, long newValue) { |
|
304 |
if (field instanceof ChronoField) { |
|
305 |
ChronoField f = (ChronoField) field; |
|
306 |
if (getLong(f) == newValue) { |
|
307 |
return this; |
|
308 |
} |
|
309 |
switch (f) { |
|
16852 | 310 |
case PROLEPTIC_MONTH: |
311 |
getChronology().range(f).checkValidValue(newValue, f); |
|
312 |
return plusMonths(newValue - getProlepticMonth()); |
|
15658 | 313 |
case YEAR_OF_ERA: |
314 |
case YEAR: |
|
315 |
case ERA: { |
|
16852 | 316 |
int nvalue = getChronology().range(f).checkValidIntValue(newValue, f); |
15658 | 317 |
switch (f) { |
318 |
case YEAR_OF_ERA: |
|
319 |
return with(isoDate.withYear((getProlepticYear() >= 1 ? nvalue : 1 - nvalue) - YEARS_DIFFERENCE)); |
|
320 |
case YEAR: |
|
321 |
return with(isoDate.withYear(nvalue - YEARS_DIFFERENCE)); |
|
322 |
case ERA: |
|
323 |
return with(isoDate.withYear((1 - getProlepticYear()) - YEARS_DIFFERENCE)); |
|
324 |
} |
|
325 |
} |
|
326 |
} |
|
327 |
return with(isoDate.with(field, newValue)); |
|
328 |
} |
|
19030 | 329 |
return super.with(field, newValue); |
15658 | 330 |
} |
331 |
||
332 |
/** |
|
333 |
* {@inheritDoc} |
|
334 |
* @throws DateTimeException {@inheritDoc} |
|
335 |
* @throws ArithmeticException {@inheritDoc} |
|
336 |
*/ |
|
337 |
@Override |
|
338 |
public ThaiBuddhistDate with(TemporalAdjuster adjuster) { |
|
16852 | 339 |
return super.with(adjuster); |
15658 | 340 |
} |
341 |
||
342 |
/** |
|
343 |
* {@inheritDoc} |
|
344 |
* @throws DateTimeException {@inheritDoc} |
|
345 |
* @throws ArithmeticException {@inheritDoc} |
|
346 |
*/ |
|
347 |
@Override |
|
348 |
public ThaiBuddhistDate plus(TemporalAmount amount) { |
|
16852 | 349 |
return super.plus(amount); |
15658 | 350 |
} |
351 |
||
352 |
/** |
|
353 |
* {@inheritDoc} |
|
354 |
* @throws DateTimeException {@inheritDoc} |
|
355 |
* @throws ArithmeticException {@inheritDoc} |
|
356 |
*/ |
|
357 |
@Override |
|
358 |
public ThaiBuddhistDate minus(TemporalAmount amount) { |
|
16852 | 359 |
return super.minus(amount); |
15658 | 360 |
} |
361 |
||
362 |
//----------------------------------------------------------------------- |
|
363 |
@Override |
|
364 |
ThaiBuddhistDate plusYears(long years) { |
|
365 |
return with(isoDate.plusYears(years)); |
|
366 |
} |
|
367 |
||
368 |
@Override |
|
369 |
ThaiBuddhistDate plusMonths(long months) { |
|
370 |
return with(isoDate.plusMonths(months)); |
|
371 |
} |
|
372 |
||
373 |
@Override |
|
374 |
ThaiBuddhistDate plusWeeks(long weeksToAdd) { |
|
16852 | 375 |
return super.plusWeeks(weeksToAdd); |
15658 | 376 |
} |
377 |
||
378 |
@Override |
|
379 |
ThaiBuddhistDate plusDays(long days) { |
|
380 |
return with(isoDate.plusDays(days)); |
|
381 |
} |
|
382 |
||
383 |
@Override |
|
384 |
public ThaiBuddhistDate plus(long amountToAdd, TemporalUnit unit) { |
|
16852 | 385 |
return super.plus(amountToAdd, unit); |
15658 | 386 |
} |
387 |
||
388 |
@Override |
|
389 |
public ThaiBuddhistDate minus(long amountToAdd, TemporalUnit unit) { |
|
16852 | 390 |
return super.minus(amountToAdd, unit); |
15658 | 391 |
} |
392 |
||
393 |
@Override |
|
394 |
ThaiBuddhistDate minusYears(long yearsToSubtract) { |
|
16852 | 395 |
return super.minusYears(yearsToSubtract); |
15658 | 396 |
} |
397 |
||
398 |
@Override |
|
399 |
ThaiBuddhistDate minusMonths(long monthsToSubtract) { |
|
16852 | 400 |
return super.minusMonths(monthsToSubtract); |
15658 | 401 |
} |
402 |
||
403 |
@Override |
|
404 |
ThaiBuddhistDate minusWeeks(long weeksToSubtract) { |
|
16852 | 405 |
return super.minusWeeks(weeksToSubtract); |
15658 | 406 |
} |
407 |
||
408 |
@Override |
|
409 |
ThaiBuddhistDate minusDays(long daysToSubtract) { |
|
16852 | 410 |
return super.minusDays(daysToSubtract); |
15658 | 411 |
} |
412 |
||
413 |
private ThaiBuddhistDate with(LocalDate newDate) { |
|
414 |
return (newDate.equals(isoDate) ? this : new ThaiBuddhistDate(newDate)); |
|
415 |
} |
|
416 |
||
417 |
@Override // for javadoc and covariant return type |
|
19030 | 418 |
@SuppressWarnings("unchecked") |
15658 | 419 |
public final ChronoLocalDateTime<ThaiBuddhistDate> atTime(LocalTime localTime) { |
19030 | 420 |
return (ChronoLocalDateTime<ThaiBuddhistDate>) super.atTime(localTime); |
15658 | 421 |
} |
422 |
||
423 |
@Override |
|
19030 | 424 |
public Period until(ChronoLocalDate endDate) { |
425 |
return isoDate.until(endDate); |
|
15658 | 426 |
} |
427 |
||
428 |
@Override // override for performance |
|
429 |
public long toEpochDay() { |
|
430 |
return isoDate.toEpochDay(); |
|
431 |
} |
|
432 |
||
433 |
//------------------------------------------------------------------------- |
|
434 |
@Override // override for performance |
|
435 |
public boolean equals(Object obj) { |
|
436 |
if (this == obj) { |
|
437 |
return true; |
|
438 |
} |
|
439 |
if (obj instanceof ThaiBuddhistDate) { |
|
440 |
ThaiBuddhistDate otherDate = (ThaiBuddhistDate) obj; |
|
441 |
return this.isoDate.equals(otherDate.isoDate); |
|
442 |
} |
|
443 |
return false; |
|
444 |
} |
|
445 |
||
446 |
@Override // override for performance |
|
447 |
public int hashCode() { |
|
448 |
return getChronology().getId().hashCode() ^ isoDate.hashCode(); |
|
449 |
} |
|
450 |
||
451 |
//----------------------------------------------------------------------- |
|
19841
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
452 |
/** |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
453 |
* Defend against malicious streams. |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
454 |
* @return never |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
455 |
* @throws InvalidObjectException always |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
456 |
*/ |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
457 |
private Object readResolve() throws InvalidObjectException { |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
458 |
throw new InvalidObjectException("Deserialization via serialization delegate"); |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
459 |
} |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
460 |
|
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 |
* Writes the object using a |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
463 |
* <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
|
464 |
* @serialData |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
465 |
* <pre> |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
466 |
* out.writeByte(10); // identifies a ThaiBuddhistDate |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
467 |
* out.writeInt(get(YEAR)); |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
468 |
* out.writeByte(get(MONTH_OF_YEAR)); |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
469 |
* out.writeByte(get(DAY_OF_MONTH)); |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
470 |
* </pre> |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
471 |
* |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
472 |
* @return the instance of {@code Ser}, not null |
15c8e97d6a14
8024164: JSR310 serialization should be described in details
rriggs
parents:
19030
diff
changeset
|
473 |
*/ |
15658 | 474 |
private Object writeReplace() { |
475 |
return new Ser(Ser.THAIBUDDHIST_DATE_TYPE, this); |
|
476 |
} |
|
477 |
||
478 |
void writeExternal(DataOutput out) throws IOException { |
|
479 |
// ThaiBuddhistChronology is implicit in the THAIBUDDHIST_DATE_TYPE |
|
480 |
out.writeInt(this.get(YEAR)); |
|
481 |
out.writeByte(this.get(MONTH_OF_YEAR)); |
|
482 |
out.writeByte(this.get(DAY_OF_MONTH)); |
|
483 |
} |
|
484 |
||
485 |
static ThaiBuddhistDate readExternal(DataInput in) throws IOException { |
|
486 |
int year = in.readInt(); |
|
487 |
int month = in.readByte(); |
|
488 |
int dayOfMonth = in.readByte(); |
|
489 |
return ThaiBuddhistChronology.INSTANCE.date(year, month, dayOfMonth); |
|
490 |
} |
|
491 |
||
492 |
} |