1195 public String toString() {
1196 int absYear = Math.abs(year);
1197 StringBuilder buf = new StringBuilder(9);
1198 if (absYear < 1000) {
1199 if (year < 0) {
1200 buf.append(year - 10000).deleteCharAt(1);
1201 } else {
1202 buf.append(year + 10000).deleteCharAt(0);
1203 }
1204 } else {
1205 buf.append(year);
1206 }
1207 return buf.append(month < 10 ? "-0" : "-")
1208 .append(month)
1209 .toString();
1210 }
1211
1212 //-----------------------------------------------------------------------
1213 /**
1214 * Writes the object using a
1215 * <a href="../../serialized-form.html#java.time.Ser">dedicated serialized form</a>.
1216 * @serialData
1217 * <pre>
1218 * out.writeByte(12); // identifies a YearMonth
1219 * out.writeInt(year);
1220 * out.writeByte(month);
1221 * </pre>
1222 *
1223 * @return the instance of {@code Ser}, not null
1224 */
1225 private Object writeReplace() {
1226 return new Ser(Ser.YEAR_MONTH_TYPE, this);
1227 }
1228
1229 /**
1230 * Defend against malicious streams.
1231 *
1232 * @param s the stream to read
1233 * @throws InvalidObjectException always
1234 */
1235 private void readObject(ObjectInputStream s) throws InvalidObjectException {
|
1195 public String toString() {
1196 int absYear = Math.abs(year);
1197 StringBuilder buf = new StringBuilder(9);
1198 if (absYear < 1000) {
1199 if (year < 0) {
1200 buf.append(year - 10000).deleteCharAt(1);
1201 } else {
1202 buf.append(year + 10000).deleteCharAt(0);
1203 }
1204 } else {
1205 buf.append(year);
1206 }
1207 return buf.append(month < 10 ? "-0" : "-")
1208 .append(month)
1209 .toString();
1210 }
1211
1212 //-----------------------------------------------------------------------
1213 /**
1214 * Writes the object using a
1215 * <a href="{@docRoot}/serialized-form.html#java.time.Ser">dedicated serialized form</a>.
1216 * @serialData
1217 * <pre>
1218 * out.writeByte(12); // identifies a YearMonth
1219 * out.writeInt(year);
1220 * out.writeByte(month);
1221 * </pre>
1222 *
1223 * @return the instance of {@code Ser}, not null
1224 */
1225 private Object writeReplace() {
1226 return new Ser(Ser.YEAR_MONTH_TYPE, this);
1227 }
1228
1229 /**
1230 * Defend against malicious streams.
1231 *
1232 * @param s the stream to read
1233 * @throws InvalidObjectException always
1234 */
1235 private void readObject(ObjectInputStream s) throws InvalidObjectException {
|