8024686: Cleanup of java.time serialization source
Summary: optimize serialized form of OffsetTime, OffsetDateTime; correct order of modifiers
Reviewed-by: sherman
--- a/jdk/src/share/classes/java/time/Duration.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/src/share/classes/java/time/Duration.java Tue Oct 22 15:03:12 2013 -0400
@@ -141,7 +141,7 @@
/**
* The pattern for parsing.
*/
- private final static Pattern PATTERN =
+ private static final Pattern PATTERN =
Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)D)?" +
"(T(?:([-+]?[0-9]+)H)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)(?:[.,]([0-9]{0,9}))?S)?)?",
Pattern.CASE_INSENSITIVE);
@@ -554,7 +554,7 @@
* the simple initialization in Duration.
*/
private static class DurationUnits {
- final static List<TemporalUnit> UNITS =
+ static final List<TemporalUnit> UNITS =
Collections.unmodifiableList(Arrays.<TemporalUnit>asList(SECONDS, NANOS));
}
--- a/jdk/src/share/classes/java/time/OffsetDateTime.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/src/share/classes/java/time/OffsetDateTime.java Tue Oct 22 15:03:12 2013 -0400
@@ -1903,9 +1903,9 @@
* <a href="../../serialized-form.html#java.time.Ser">dedicated serialized form</a>.
* @serialData
* <pre>
- * out.writeByte(10); // identifies a OffsetDateTime
- * out.writeObject(dateTime);
- * out.writeObject(offset);
+ * out.writeByte(10); // identifies an OffsetDateTime
+ * // the <a href="../../serialized-form.html#java.time.LocalDateTime">datetime</a> excluding the one byte header
+ * // the <a href="../../serialized-form.html#java.time.ZoneOffset">offset</a> excluding the one byte header
* </pre>
*
* @return the instance of {@code Ser}, not null
@@ -1924,13 +1924,13 @@
}
void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(dateTime);
- out.writeObject(offset);
+ dateTime.writeExternal(out);
+ offset.writeExternal(out);
}
static OffsetDateTime readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- LocalDateTime dateTime = (LocalDateTime) in.readObject();
- ZoneOffset offset = (ZoneOffset) in.readObject();
+ LocalDateTime dateTime = LocalDateTime.readExternal(in);
+ ZoneOffset offset = ZoneOffset.readExternal(in);
return OffsetDateTime.of(dateTime, offset);
}
--- a/jdk/src/share/classes/java/time/OffsetTime.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/src/share/classes/java/time/OffsetTime.java Tue Oct 22 15:03:12 2013 -0400
@@ -1374,9 +1374,9 @@
* <a href="../../serialized-form.html#java.time.Ser">dedicated serialized form</a>.
* @serialData
* <pre>
- * out.writeByte(9); // identifies a OffsetTime
- * out.writeObject(time);
- * out.writeObject(offset);
+ * out.writeByte(9); // identifies an OffsetTime
+ * // the <a href="../../serialized-form.html#java.time.LocalTime">time</a> excluding the one byte header
+ * // the <a href="../../serialized-form.html#java.time.ZoneOffset">offset</a> excluding the one byte header
* </pre>
*
* @return the instance of {@code Ser}, not null
@@ -1395,13 +1395,13 @@
}
void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(time);
- out.writeObject(offset);
+ time.writeExternal(out);
+ offset.writeExternal(out);
}
static OffsetTime readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- LocalTime time = (LocalTime) in.readObject();
- ZoneOffset offset = (ZoneOffset) in.readObject();
+ LocalTime time = LocalTime.readExternal(in);
+ ZoneOffset offset = ZoneOffset.readExternal(in);
return OffsetTime.of(time, offset);
}
--- a/jdk/src/share/classes/java/time/Period.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/src/share/classes/java/time/Period.java Tue Oct 22 15:03:12 2013 -0400
@@ -138,13 +138,13 @@
/**
* The pattern for parsing.
*/
- private final static Pattern PATTERN =
+ private static final Pattern PATTERN =
Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)Y)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)W)?(?:([-+]?[0-9]+)D)?", Pattern.CASE_INSENSITIVE);
/**
* The set of supported units.
*/
- private final static List<TemporalUnit> SUPPORTED_UNITS =
+ private static final List<TemporalUnit> SUPPORTED_UNITS =
Collections.unmodifiableList(Arrays.<TemporalUnit>asList(YEARS, MONTHS, DAYS));
/**
--- a/jdk/src/share/classes/java/time/chrono/ChronoPeriodImpl.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/src/share/classes/java/time/chrono/ChronoPeriodImpl.java Tue Oct 22 15:03:12 2013 -0400
@@ -104,7 +104,7 @@
/**
* The set of supported units.
*/
- private final static List<TemporalUnit> SUPPORTED_UNITS =
+ private static final List<TemporalUnit> SUPPORTED_UNITS =
Collections.unmodifiableList(Arrays.<TemporalUnit>asList(YEARS, MONTHS, DAYS));
/**
--- a/jdk/src/share/classes/java/time/chrono/JapaneseDate.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/src/share/classes/java/time/chrono/JapaneseDate.java Tue Oct 22 15:03:12 2013 -0400
@@ -140,7 +140,7 @@
/**
* The first day supported by the JapaneseChronology is Meiji 6, January 1st.
*/
- final static LocalDate MEIJI_6_ISODATE = LocalDate.of(1873, 1, 1);
+ static final LocalDate MEIJI_6_ISODATE = LocalDate.of(1873, 1, 1);
//-----------------------------------------------------------------------
/**
--- a/jdk/src/share/classes/java/time/temporal/WeekFields.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/src/share/classes/java/time/temporal/WeekFields.java Tue Oct 22 15:03:12 2013 -0400
@@ -245,15 +245,15 @@
/**
* The field used to access the computed DayOfWeek.
*/
- private transient final TemporalField dayOfWeek = ComputedDayOfField.ofDayOfWeekField(this);
+ private final transient TemporalField dayOfWeek = ComputedDayOfField.ofDayOfWeekField(this);
/**
* The field used to access the computed WeekOfMonth.
*/
- private transient final TemporalField weekOfMonth = ComputedDayOfField.ofWeekOfMonthField(this);
+ private final transient TemporalField weekOfMonth = ComputedDayOfField.ofWeekOfMonthField(this);
/**
* The field used to access the computed WeekOfYear.
*/
- private transient final TemporalField weekOfYear = ComputedDayOfField.ofWeekOfYearField(this);
+ private final transient TemporalField weekOfYear = ComputedDayOfField.ofWeekOfYearField(this);
/**
* The field that represents the week-of-week-based-year.
* <p>
@@ -261,7 +261,7 @@
* <p>
* This unit is an immutable and thread-safe singleton.
*/
- private transient final TemporalField weekOfWeekBasedYear = ComputedDayOfField.ofWeekOfWeekBasedYearField(this);
+ private final transient TemporalField weekOfWeekBasedYear = ComputedDayOfField.ofWeekOfWeekBasedYearField(this);
/**
* The field that represents the week-based-year.
* <p>
@@ -269,7 +269,7 @@
* <p>
* This unit is an immutable and thread-safe singleton.
*/
- private transient final TemporalField weekBasedYear = ComputedDayOfField.ofWeekBasedYearField(this);
+ private final transient TemporalField weekBasedYear = ComputedDayOfField.ofWeekBasedYearField(this);
//-----------------------------------------------------------------------
/**
--- a/jdk/src/share/classes/java/time/zone/Ser.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/src/share/classes/java/time/zone/Ser.java Tue Oct 22 15:03:12 2013 -0400
@@ -171,9 +171,9 @@
* <li><a href="../../../serialized-form.html#java.time.zone.ZoneRules">ZoneRules</a>
* - {@code ZoneRules.of(standardTransitions, standardOffsets, savingsInstantTransitions, wallOffsets, lastRules);}
* <li><a href="../../../serialized-form.html#java.time.zone.ZoneOffsetTransition">ZoneOffsetTransition</a>
- * - {@code ;}
+ * - {@code ZoneOffsetTransition of(LocalDateTime.ofEpochSecond(epochSecond), offsetBefore, offsetAfter);}
* <li><a href="../../../serialized-form.html#java.time.zone.ZoneOffsetTransitionRule">ZoneOffsetTransitionRule</a>
- * - {@code ;}
+ * - {@code ZoneOffsetTransitionRule.of(month, dom, dow, time, timeEndOfDay, timeDefinition, standardOffset, offsetBefore, offsetAfter);}
* </ul>
* @param in the data to read, not null
*/
--- a/jdk/src/share/classes/java/time/zone/ZoneOffsetTransition.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/src/share/classes/java/time/zone/ZoneOffsetTransition.java Tue Oct 22 15:03:12 2013 -0400
@@ -191,7 +191,7 @@
* out.writeByte(2); // identifies a ZoneOffsetTransition
* out.writeEpochSec(toEpochSecond);
* out.writeOffset(offsetBefore);
- * out.writeOfset(offsetAfter);
+ * out.writeOffset(offsetAfter);
* }
* </pre>
* @return the replacing object, not null
--- a/jdk/test/java/time/tck/java/time/serial/TCKOffsetDateTimeSerialization.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/test/java/time/tck/java/time/serial/TCKOffsetDateTimeSerialization.java Tue Oct 22 15:03:12 2013 -0400
@@ -59,9 +59,6 @@
*/
package tck.java.time.serial;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import tck.java.time.AbstractTCKTest;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@@ -69,6 +66,10 @@
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import tck.java.time.AbstractTCKTest;
+
/**
* Test OffsetDateTime serialization.
*/
@@ -96,11 +97,6 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (DataOutputStream dos = new DataOutputStream(baos) ) {
dos.writeByte(10); // java.time.Ser.OFFSET_DATE_TIME_TYPE
- }
- byte[] bytes = baos.toByteArray();
- ByteArrayOutputStream baosDateTime = new ByteArrayOutputStream();
- try (DataOutputStream dos = new DataOutputStream(baosDateTime) ) {
- dos.writeByte(5);
dos.writeInt(2012);
dos.writeByte(9);
dos.writeByte(16);
@@ -108,17 +104,11 @@
dos.writeByte(17);
dos.writeByte(59);
dos.writeInt(464_000_000);
- }
- byte[] bytesDateTime = baosDateTime.toByteArray();
- ByteArrayOutputStream baosOffset = new ByteArrayOutputStream();
- try (DataOutputStream dos = new DataOutputStream(baosOffset) ) {
- dos.writeByte(8);
dos.writeByte(4); // quarter hours stored: 3600 / 900
}
- byte[] bytesOffset = baosOffset.toByteArray();
+ byte[] bytes = baos.toByteArray();
LocalDateTime ldt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 464_000_000);
- assertSerializedBySer(OffsetDateTime.of(ldt, ZoneOffset.ofHours(1)), bytes, bytesDateTime, bytesOffset);
+ assertSerializedBySer(OffsetDateTime.of(ldt, ZoneOffset.ofHours(1)), bytes);
}
-
}
--- a/jdk/test/java/time/tck/java/time/serial/TCKOffsetTimeSerialization.java Tue Oct 22 22:18:52 2013 +0400
+++ b/jdk/test/java/time/tck/java/time/serial/TCKOffsetTimeSerialization.java Tue Oct 22 15:03:12 2013 -0400
@@ -97,25 +97,14 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (DataOutputStream dos = new DataOutputStream(baos) ) {
dos.writeByte(9); // java.time.Ser.OFFSET_TIME_TYPE
- }
- byte[] bytes = baos.toByteArray();
- ByteArrayOutputStream baosTime = new ByteArrayOutputStream();
- try (DataOutputStream dos = new DataOutputStream(baosTime) ) {
- dos.writeByte(4);
dos.writeByte(22);
dos.writeByte(17);
dos.writeByte(59);
dos.writeInt(464_000_000);
- }
- byte[] bytesTime = baosTime.toByteArray();
- ByteArrayOutputStream baosOffset = new ByteArrayOutputStream();
- try (DataOutputStream dos = new DataOutputStream(baosOffset) ) {
- dos.writeByte(8);
dos.writeByte(4); // quarter hours stored: 3600 / 900
}
- byte[] bytesOffset = baosOffset.toByteArray();
- assertSerializedBySer(OffsetTime.of(22, 17, 59, 464_000_000, ZoneOffset.ofHours(1)), bytes,
- bytesTime, bytesOffset);
+ byte[] bytes = baos.toByteArray();
+ assertSerializedBySer(OffsetTime.of(22, 17, 59, 464_000_000, ZoneOffset.ofHours(1)), bytes);
}