96 * Information about the local-time can be obtained using methods on the time-zone. |
96 * Information about the local-time can be obtained using methods on the time-zone. |
97 * |
97 * |
98 * @implSpec |
98 * @implSpec |
99 * This class is immutable and thread-safe. |
99 * This class is immutable and thread-safe. |
100 * |
100 * |
|
101 * @serial Document the delegation of this class in the serialized-form specification. |
101 * @param <D> the concrete type for the date of this date-time |
102 * @param <D> the concrete type for the date of this date-time |
102 * @since 1.8 |
103 * @since 1.8 |
103 */ |
104 */ |
104 final class ChronoZonedDateTimeImpl<D extends ChronoLocalDate> |
105 final class ChronoZonedDateTimeImpl<D extends ChronoLocalDate> |
105 implements ChronoZonedDateTime<D>, Serializable { |
106 implements ChronoZonedDateTime<D>, Serializable { |
110 private static final long serialVersionUID = -5261813987200935591L; |
111 private static final long serialVersionUID = -5261813987200935591L; |
111 |
112 |
112 /** |
113 /** |
113 * The local date-time. |
114 * The local date-time. |
114 */ |
115 */ |
115 private final ChronoLocalDateTimeImpl<D> dateTime; |
116 private final transient ChronoLocalDateTimeImpl<D> dateTime; |
116 /** |
117 /** |
117 * The zone offset. |
118 * The zone offset. |
118 */ |
119 */ |
119 private final ZoneOffset offset; |
120 private final transient ZoneOffset offset; |
120 /** |
121 /** |
121 * The zone ID. |
122 * The zone ID. |
122 */ |
123 */ |
123 private final ZoneId zone; |
124 private final transient ZoneId zone; |
124 |
125 |
125 //----------------------------------------------------------------------- |
126 //----------------------------------------------------------------------- |
126 /** |
127 /** |
127 * Obtains an instance from a local date-time using the preferred offset if possible. |
128 * Obtains an instance from a local date-time using the preferred offset if possible. |
128 * |
129 * |
220 this.offset = Objects.requireNonNull(offset, "offset"); |
221 this.offset = Objects.requireNonNull(offset, "offset"); |
221 this.zone = Objects.requireNonNull(zone, "zone"); |
222 this.zone = Objects.requireNonNull(zone, "zone"); |
222 } |
223 } |
223 |
224 |
224 //----------------------------------------------------------------------- |
225 //----------------------------------------------------------------------- |
|
226 @Override |
225 public ZoneOffset getOffset() { |
227 public ZoneOffset getOffset() { |
226 return offset; |
228 return offset; |
227 } |
229 } |
228 |
230 |
229 @Override |
231 @Override |
254 @Override |
256 @Override |
255 public ChronoLocalDateTime<D> toLocalDateTime() { |
257 public ChronoLocalDateTime<D> toLocalDateTime() { |
256 return dateTime; |
258 return dateTime; |
257 } |
259 } |
258 |
260 |
|
261 @Override |
259 public ZoneId getZone() { |
262 public ZoneId getZone() { |
260 return zone; |
263 return zone; |
261 } |
264 } |
262 |
265 |
|
266 @Override |
263 public ChronoZonedDateTime<D> withZoneSameLocal(ZoneId zone) { |
267 public ChronoZonedDateTime<D> withZoneSameLocal(ZoneId zone) { |
264 return ofBest(dateTime, zone, offset); |
268 return ofBest(dateTime, zone, offset); |
265 } |
269 } |
266 |
270 |
267 @Override |
271 @Override |
319 } |
323 } |
320 return unit.between(this, endDateTime); |
324 return unit.between(this, endDateTime); |
321 } |
325 } |
322 |
326 |
323 //----------------------------------------------------------------------- |
327 //----------------------------------------------------------------------- |
|
328 /** |
|
329 * Writes the ChronoZonedDateTime using a |
|
330 * <a href="../../../serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>. |
|
331 * @serialData |
|
332 * <pre> |
|
333 * out.writeByte(3); // identifies a ChronoZonedDateTime |
|
334 * out.writeObject(toLocalDateTime()); |
|
335 * out.writeObject(getOffset()); |
|
336 * out.writeObject(getZone()); |
|
337 * </pre> |
|
338 * |
|
339 * @return the instance of {@code Ser}, not null |
|
340 */ |
324 private Object writeReplace() { |
341 private Object writeReplace() { |
325 return new Ser(Ser.CHRONO_ZONE_DATE_TIME_TYPE, this); |
342 return new Ser(Ser.CHRONO_ZONE_DATE_TIME_TYPE, this); |
326 } |
343 } |
327 |
344 |
328 /** |
345 /** |
329 * Defend against malicious streams. |
346 * Defend against malicious streams. |
330 * @return never |
347 * @return never |
331 * @throws InvalidObjectException always |
348 * @throws InvalidObjectException always |
332 */ |
349 */ |
333 private Object readResolve() throws ObjectStreamException { |
350 private Object readResolve() throws InvalidObjectException { |
334 throw new InvalidObjectException("Deserialization via serialization delegate"); |
351 throw new InvalidObjectException("Deserialization via serialization delegate"); |
335 } |
352 } |
336 |
353 |
337 void writeExternal(ObjectOutput out) throws IOException { |
354 void writeExternal(ObjectOutput out) throws IOException { |
338 out.writeObject(dateTime); |
355 out.writeObject(dateTime); |