diff --git a/src/java.base/share/classes/sun/util/calendar/AbstractCalendar.java b/src/java.base/share/classes/sun/util/calendar/AbstractCalendar.java
index fa7667c2f48..0362db82cec 100644
--- a/src/java.base/share/classes/sun/util/calendar/AbstractCalendar.java
+++ b/src/java.base/share/classes/sun/util/calendar/AbstractCalendar.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
package sun.util.calendar;
-import java.util.Locale;
import java.util.TimeZone;
/**
@@ -81,20 +80,6 @@ public abstract class AbstractCalendar extends CalendarSystem {
return e;
}
- public void setEra(CalendarDate date, String eraName) {
- if (eras == null) {
- return; // should report an error???
- }
- for (int i = 0; i < eras.length; i++) {
- Era e = eras[i];
- if (e != null && e.getName().equals(eraName)) {
- date.setEra(e);
- return;
- }
- }
- throw new IllegalArgumentException("unknown era name: " + eraName);
- }
-
protected void setEras(Era[] eras) {
this.eras = eras;
}
@@ -258,15 +243,6 @@ public abstract class AbstractCalendar extends CalendarSystem {
return cdate;
}
- /**
- * Returns 7 in this default implementation.
- *
- * @return 7
- */
- public int getWeekLength() {
- return 7;
- }
-
protected abstract boolean isLeapYear(CalendarDate date);
public CalendarDate getNthDayOfWeek(int nth, int dayOfWeek, CalendarDate date) {
@@ -341,7 +317,7 @@ public abstract class AbstractCalendar extends CalendarSystem {
* method stores the calculated calendar field values in the specified
* CalendarDate
.
*
- * @param date a CalendarDate
to stored the
+ * @param date a CalendarDate
to store the
* calculated calendar fields.
* @param fixedDate a fixed date to calculate calendar fields
* @see AbstractCalendar.html#fixed_date
diff --git a/src/java.base/share/classes/sun/util/calendar/BaseCalendar.java b/src/java.base/share/classes/sun/util/calendar/BaseCalendar.java
index b4fdb8140b0..efe1b85fc21 100644
--- a/src/java.base/share/classes/sun/util/calendar/BaseCalendar.java
+++ b/src/java.base/share/classes/sun/util/calendar/BaseCalendar.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -307,10 +307,6 @@ public abstract class BaseCalendar extends AbstractCalendar {
return isLeapYear(((Date)date).getNormalizedYear()) ? 366 : 365;
}
- public int getYearLengthInMonths(CalendarDate date) {
- return 12;
- }
-
static final int[] DAYS_IN_MONTH
// 12 1 2 3 4 5 6 7 8 9 10 11 12
= { 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
@@ -527,7 +523,7 @@ public abstract class BaseCalendar extends AbstractCalendar {
/**
* @return true if the specified year is a Gregorian leap year, or
* false otherwise.
- * @see BaseCalendar#isGregorianLeapYear
+ * @see CalendarUtils#isGregorianLeapYear
*/
protected boolean isLeapYear(CalendarDate date) {
return isLeapYear(((Date)date).getNormalizedYear());
diff --git a/src/java.base/share/classes/sun/util/calendar/CalendarDate.java b/src/java.base/share/classes/sun/util/calendar/CalendarDate.java
index b8e736ca194..5ecde812607 100644
--- a/src/java.base/share/classes/sun/util/calendar/CalendarDate.java
+++ b/src/java.base/share/classes/sun/util/calendar/CalendarDate.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -152,7 +152,7 @@ public abstract class CalendarDate implements Cloneable {
* @return true
if this CalendarDate
is
* normalized and the year of this CalendarDate
is a
* leap year, or false
otherwise.
- * @see BaseCalendar#isGregorianLeapYear
+ * @see CalendarUtils#isGregorianLeapYear
*/
public boolean isLeapYear() {
return leapYear;
@@ -194,14 +194,6 @@ public abstract class CalendarDate implements Cloneable {
return this;
}
- public CalendarDate addDayOfMonth(int n) {
- if (n != 0) {
- dayOfMonth += n;
- normalized = false;
- }
- return this;
- }
-
/**
* Returns the day of week value. If this CalendarDate is not
* normalized, {@link #FIELD_UNDEFINED} is returned.
@@ -247,14 +239,6 @@ public abstract class CalendarDate implements Cloneable {
return this;
}
- public CalendarDate addMinutes(int n) {
- if (n != 0) {
- minutes += n;
- normalized = false;
- }
- return this;
- }
-
public int getSeconds() {
return seconds;
}
@@ -267,14 +251,6 @@ public abstract class CalendarDate implements Cloneable {
return this;
}
- public CalendarDate addSeconds(int n) {
- if (n != 0) {
- seconds += n;
- normalized = false;
- }
- return this;
- }
-
public int getMillis() {
return millis;
}
@@ -287,14 +263,6 @@ public abstract class CalendarDate implements Cloneable {
return this;
}
- public CalendarDate addMillis(int n) {
- if (n != 0) {
- millis += n;
- normalized = false;
- }
- return this;
- }
-
public long getTimeOfDay() {
if (!isNormalized()) {
return fraction = TIME_UNDEFINED;
@@ -309,13 +277,6 @@ public abstract class CalendarDate implements Cloneable {
return this;
}
- public CalendarDate addDate(int year, int month, int dayOfMonth) {
- addYear(year);
- addMonth(month);
- addDayOfMonth(dayOfMonth);
- return this;
- }
-
public CalendarDate setTimeOfDay(int hours, int minutes, int seconds, int millis) {
setHours(hours);
setMinutes(minutes);
@@ -324,14 +285,6 @@ public abstract class CalendarDate implements Cloneable {
return this;
}
- public CalendarDate addTimeOfDay(int hours, int minutes, int seconds, int millis) {
- addHours(hours);
- addMinutes(minutes);
- addSeconds(seconds);
- addMillis(millis);
- return this;
- }
-
protected void setTimeOfDay(long fraction) {
this.fraction = fraction;
}
@@ -345,10 +298,6 @@ public abstract class CalendarDate implements Cloneable {
return forceStandardTime;
}
- public void setStandardTime(boolean standardTime) {
- forceStandardTime = standardTime;
- }
-
public boolean isDaylightTime() {
if (isStandardTime()) {
return false;
@@ -382,10 +331,9 @@ public abstract class CalendarDate implements Cloneable {
}
public boolean equals(Object obj) {
- if (!(obj instanceof CalendarDate)) {
+ if (!(obj instanceof CalendarDate that)) {
return false;
}
- CalendarDate that = (CalendarDate) obj;
if (isNormalized() != that.isNormalized()) {
return false;
}
diff --git a/src/java.base/share/classes/sun/util/calendar/CalendarSystem.java b/src/java.base/share/classes/sun/util/calendar/CalendarSystem.java
index 91a689f5f03..885150fc0a4 100644
--- a/src/java.base/share/classes/sun/util/calendar/CalendarSystem.java
+++ b/src/java.base/share/classes/sun/util/calendar/CalendarSystem.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -234,14 +234,6 @@ public abstract class CalendarSystem {
*/
public abstract int getYearLength(CalendarDate date);
- /**
- * Returns the number of months of the specified year. This method
- * does not perform the normalization with the specified
- * CalendarDate
. The CalendarDate
must
- * be normalized to get a correct value.
- */
- public abstract int getYearLengthInMonths(CalendarDate date);
-
/**
* Returns the length in days of the month specified by the calendar
* date. This method does not perform the normalization with the
@@ -255,13 +247,6 @@ public abstract class CalendarSystem {
*/
public abstract int getMonthLength(CalendarDate date); // no setter
- /**
- * Returns the length in days of a week in this calendar
- * system. If this calendar system has multiple radix weeks, this
- * method returns only one of them.
- */
- public abstract int getWeekLength();
-
/**
* Returns the Era
designated by the era name that
* has to be known to this calendar system. If no Era is
@@ -287,13 +272,6 @@ public abstract class CalendarSystem {
*/
public abstract Era[] getEras();
- /**
- * @throws IllegalArgumentException if the specified era name is
- * unknown to this calendar system.
- * @see Era
- */
- public abstract void setEra(CalendarDate date, String eraName);
-
/**
* Returns a CalendarDate
of the n-th day of week
* which is on, after or before the specified date. For example, the
diff --git a/src/java.base/share/classes/sun/util/calendar/CalendarUtils.java b/src/java.base/share/classes/sun/util/calendar/CalendarUtils.java
index 917dbbe657f..5723ebcbee0 100644
--- a/src/java.base/share/classes/sun/util/calendar/CalendarUtils.java
+++ b/src/java.base/share/classes/sun/util/calendar/CalendarUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,9 +25,6 @@
package sun.util.calendar;
-import java.util.HashMap;
-import java.util.Map;
-
public class CalendarUtils {
/**
@@ -109,29 +106,6 @@ public class CalendarUtils {
return q;
}
- /**
- * Divides two integers and returns the floor of the quotient and
- * the modulus remainder. For example,
- * floorDivide(-1,4)
returns -1
with
- * 3
as its remainder, while -1/4
is
- * 0
and -1%4
is -1
.
- *
- * @param n the numerator
- * @param d a divisor which must be {@literal > 0}
- * @param r an array of at least one element in which the value
- * mod(n, d)
is returned.
- * @return the floor of the quotient.
- */
- public static final int floorDivide(long n, int d, int[] r) {
- if (n >= 0) {
- r[0] = (int)(n % d);
- return (int)(n / d);
- }
- int q = (int)(((n + 1) / d) - 1);
- r[0] = (int)(n - (q * d));
- return q;
- }
-
public static final long mod(long x, long y) {
return (x - y * floorDivide(x, y));
}
diff --git a/src/java.base/share/classes/sun/util/calendar/Era.java b/src/java.base/share/classes/sun/util/calendar/Era.java
index 1bc9a89340f..bcafbdeb474 100644
--- a/src/java.base/share/classes/sun/util/calendar/Era.java
+++ b/src/java.base/share/classes/sun/util/calendar/Era.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -79,9 +79,9 @@ public final class Era {
this.abbr = abbr;
this.since = since;
this.localTime = localTime;
- Gregorian gcal = CalendarSystem.getGregorianCalendar();
- BaseCalendar.Date d = gcal.newCalendarDate(null);
- gcal.getCalendarDate(since, d);
+ Gregorian gCal = CalendarSystem.getGregorianCalendar();
+ BaseCalendar.Date d = gCal.newCalendarDate(null);
+ gCal.getCalendarDate(since, d);
sinceDate = new ImmutableGregorianDate(d);
}
@@ -97,10 +97,6 @@ public final class Era {
return abbr;
}
- public String getDiaplayAbbreviation(Locale locale) {
- return abbr;
- }
-
public long getSince(TimeZone zone) {
if (zone == null || !localTime) {
return since;
@@ -118,10 +114,9 @@ public final class Era {
}
public boolean equals(Object o) {
- if (!(o instanceof Era)) {
+ if (!(o instanceof Era that)) {
return false;
}
- Era that = (Era) o;
return name.equals(that.name)
&& abbr.equals(that.abbr)
&& since == that.since
diff --git a/src/java.base/share/classes/sun/util/calendar/ImmutableGregorianDate.java b/src/java.base/share/classes/sun/util/calendar/ImmutableGregorianDate.java
index a06b53e5147..77fa4609397 100644
--- a/src/java.base/share/classes/sun/util/calendar/ImmutableGregorianDate.java
+++ b/src/java.base/share/classes/sun/util/calendar/ImmutableGregorianDate.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -86,10 +86,6 @@ class ImmutableGregorianDate extends BaseCalendar.Date {
unsupported(); return this;
}
- public CalendarDate addDayOfMonth(int n) {
- unsupported(); return this;
- }
-
public int getDayOfWeek() {
return date.getDayOfWeek();
}
@@ -114,10 +110,6 @@ class ImmutableGregorianDate extends BaseCalendar.Date {
unsupported(); return this;
}
- public CalendarDate addMinutes(int n) {
- unsupported(); return this;
- }
-
public int getSeconds() {
return date.getSeconds();
}
@@ -126,10 +118,6 @@ class ImmutableGregorianDate extends BaseCalendar.Date {
unsupported(); return this;
}
- public CalendarDate addSeconds(int n) {
- unsupported(); return this;
- }
-
public int getMillis() {
return date.getMillis();
}
@@ -138,10 +126,6 @@ class ImmutableGregorianDate extends BaseCalendar.Date {
unsupported(); return this;
}
- public CalendarDate addMillis(int n) {
- unsupported(); return this;
- }
-
public long getTimeOfDay() {
return date.getTimeOfDay();
}
@@ -150,18 +134,10 @@ class ImmutableGregorianDate extends BaseCalendar.Date {
unsupported(); return this;
}
- public CalendarDate addDate(int year, int month, int dayOfMonth) {
- unsupported(); return this;
- }
-
public CalendarDate setTimeOfDay(int hours, int minutes, int seconds, int millis) {
unsupported(); return this;
}
- public CalendarDate addTimeOfDay(int hours, int minutes, int seconds, int millis) {
- unsupported(); return this;
- }
-
protected void setTimeOfDay(long fraction) {
unsupported();
}
@@ -174,10 +150,6 @@ class ImmutableGregorianDate extends BaseCalendar.Date {
return date.isStandardTime();
}
- public void setStandardTime(boolean standardTime) {
- unsupported();
- }
-
public boolean isDaylightTime() {
return date.isDaylightTime();
}
diff --git a/src/java.base/share/classes/sun/util/calendar/LocalGregorianCalendar.java b/src/java.base/share/classes/sun/util/calendar/LocalGregorianCalendar.java
index 8fd582938dd..283adca6b59 100644
--- a/src/java.base/share/classes/sun/util/calendar/LocalGregorianCalendar.java
+++ b/src/java.base/share/classes/sun/util/calendar/LocalGregorianCalendar.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
package sun.util.calendar;
-import java.security.AccessController;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
diff --git a/src/java.base/share/classes/sun/util/calendar/ZoneInfo.java b/src/java.base/share/classes/sun/util/calendar/ZoneInfo.java
index e04b769e915..f14c98a77c3 100644
--- a/src/java.base/share/classes/sun/util/calendar/ZoneInfo.java
+++ b/src/java.base/share/classes/sun/util/calendar/ZoneInfo.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -70,7 +70,6 @@ public class ZoneInfo extends TimeZone {
private static final long DST_MASK = 0xf0L;
private static final int DST_NSHIFT = 4;
// this bit field is reserved for abbreviation support
- private static final long ABBR_MASK = 0xf00L;
private static final int TRANSITION_NSHIFT = 12;
/**
@@ -394,7 +393,7 @@ public class ZoneInfo extends TimeZone {
}
long dateInMillis = gcal.getTime(date) + milliseconds;
- dateInMillis -= (long) rawOffset; // make it UTC
+ dateInMillis -= rawOffset; // make it UTC
return getOffsets(dateInMillis, null, UTC_TIME);
}
@@ -404,7 +403,7 @@ public class ZoneInfo extends TimeZone {
* historical ones, if applicable.
*
* @param offsetMillis the base time zone offset to GMT.
- * @see getRawOffset
+ * @see #getRawOffset
*/
public synchronized void setRawOffset(int offsetMillis) {
if (offsetMillis == rawOffset + rawOffsetDiff) {
@@ -525,20 +524,6 @@ public class ZoneInfo extends TimeZone {
return dstSavings;
}
-// /**
-// * @return the last year in the transition table or -1 if this
-// * time zone doesn't observe any daylight saving time.
-// */
-// public int getMaxTransitionYear() {
-// if (transitions == null) {
-// return -1;
-// }
-// long val = transitions[transitions.length - 1];
-// int offset = this.offsets[(int)(val & OFFSET_MASK)] + rawOffsetDiff;
-// val = (val >> TRANSITION_NSHIFT) + offset;
-// CalendarDate lastDate = Gregorian.getCalendarDate(val);
-// return lastDate.getYear();
-// }
/**
* Returns a string representation of this time zone.
@@ -669,10 +654,9 @@ public class ZoneInfo extends TimeZone {
if (this == obj) {
return true;
}
- if (!(obj instanceof ZoneInfo)) {
+ if (!(obj instanceof ZoneInfo that)) {
return false;
}
- ZoneInfo that = (ZoneInfo) obj;
return (getID().equals(that.getID())
&& (getLastRawOffset() == that.getLastRawOffset())
&& (checksum == that.checksum));
diff --git a/src/java.base/share/classes/sun/util/calendar/ZoneInfoFile.java b/src/java.base/share/classes/sun/util/calendar/ZoneInfoFile.java
index 40f2b987e28..9ecef759c94 100644
--- a/src/java.base/share/classes/sun/util/calendar/ZoneInfoFile.java
+++ b/src/java.base/share/classes/sun/util/calendar/ZoneInfoFile.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -297,9 +297,9 @@ public final class ZoneInfoFile {
* Loads the rules from a DateInputStream
*
* @param dis the DateInputStream to load, not null
- * @throws Exception if an error occurs
+ * @throws IOException if an error occurs
*/
- private static void load(DataInputStream dis) throws ClassNotFoundException, IOException {
+ private static void load(DataInputStream dis) throws IOException {
if (dis.readByte() != 1) {
throw new StreamCorruptedException("File format not recognised");
}
@@ -418,7 +418,8 @@ public final class ZoneInfoFile {
//Current time. Used to determine future GMToffset transitions
private static final long CURRT = System.currentTimeMillis()/1000;
- /* Get a ZoneInfo instance.
+ /**
+ * Get a ZoneInfo instance.
*
* @param standardTransitions the standard transitions, not null
* @param standardOffsets the standard offsets, not null
@@ -711,9 +712,7 @@ public final class ZoneInfoFile {
for (i = 0; i < transitions.length; i++) {
long val = transitions[i];
int dst = (int)((val >>> DST_NSHIFT) & 0xfL);
- int saving = (dst == 0) ? 0 : offsets[dst];
int index = (int)(val & OFFSET_MASK);
- int offset = offsets[index];
long second = (val >> TRANSITION_NSHIFT);
// javazic uses "index of the offset in offsets",
// instead of the real offset value itself to
@@ -780,13 +779,11 @@ public final class ZoneInfoFile {
int marchDoy0 = (int) doyEst;
// convert march-based values back to january-based
int marchMonth0 = (marchDoy0 * 5 + 2) / 153;
- int month = (marchMonth0 + 2) % 12 + 1;
- int dom = marchDoy0 - (marchMonth0 * 306 + 5) / 10 + 1;
yearEst += marchMonth0 / 10;
return (int)yearEst;
}
- private static final int toCalendarDOW[] = new int[] {
+ private static final int[] toCalendarDOW = new int[] {
-1,
Calendar.MONDAY,
Calendar.TUESDAY,
@@ -797,7 +794,7 @@ public final class ZoneInfoFile {
Calendar.SUNDAY
};
- private static final int toSTZTime[] = new int[] {
+ private static final int[] toSTZTime = new int[] {
SimpleTimeZone.UTC_TIME,
SimpleTimeZone.WALL_TIME,
SimpleTimeZone.STANDARD_TIME,
@@ -821,8 +818,8 @@ public final class ZoneInfoFile {
}
// return updated nOffsets
- private static int addTrans(long transitions[], int nTrans,
- int offsets[], int nOffsets,
+ private static int addTrans(long[] transitions, int nTrans,
+ int[] offsets, int nOffsets,
long trans, int offset, int stdOffset) {
int offsetIndex = indexOf(offsets, 0, nOffsets, offset);
if (offsetIndex == nOffsets)