Skip to content

Commit f1f4e1d

Browse files
Justin Lunaotoj
authored andcommitted
6453901: (cal) clean up sun.util.calendar classes
Reviewed-by: naoto, lancea
1 parent acf8996 commit f1f4e1d

File tree

10 files changed

+29
-210
lines changed

10 files changed

+29
-210
lines changed

src/java.base/share/classes/sun/util/calendar/AbstractCalendar.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
2525

2626
package sun.util.calendar;
2727

28-
import java.util.Locale;
2928
import java.util.TimeZone;
3029

3130
/**
@@ -81,20 +80,6 @@ public Era[] getEras() {
8180
return e;
8281
}
8382

84-
public void setEra(CalendarDate date, String eraName) {
85-
if (eras == null) {
86-
return; // should report an error???
87-
}
88-
for (int i = 0; i < eras.length; i++) {
89-
Era e = eras[i];
90-
if (e != null && e.getName().equals(eraName)) {
91-
date.setEra(e);
92-
return;
93-
}
94-
}
95-
throw new IllegalArgumentException("unknown era name: " + eraName);
96-
}
97-
9883
protected void setEras(Era[] eras) {
9984
this.eras = eras;
10085
}
@@ -258,15 +243,6 @@ public CalendarDate setTimeOfDay(CalendarDate cdate, int fraction) {
258243
return cdate;
259244
}
260245

261-
/**
262-
* Returns 7 in this default implementation.
263-
*
264-
* @return 7
265-
*/
266-
public int getWeekLength() {
267-
return 7;
268-
}
269-
270246
protected abstract boolean isLeapYear(CalendarDate date);
271247

272248
public CalendarDate getNthDayOfWeek(int nth, int dayOfWeek, CalendarDate date) {
@@ -341,7 +317,7 @@ public static long getDayOfWeekDateOnOrBefore(long fixedDate, int dayOfWeek) {
341317
* method stores the calculated calendar field values in the specified
342318
* <code>CalendarDate</code>.
343319
*
344-
* @param date a <code>CalendarDate</code> to stored the
320+
* @param date a <code>CalendarDate</code> to store the
345321
* calculated calendar fields.
346322
* @param fixedDate a fixed date to calculate calendar fields
347323
* @see AbstractCalendar.html#fixed_date

src/java.base/share/classes/sun/util/calendar/BaseCalendar.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -307,10 +307,6 @@ public int getYearLength(CalendarDate date) {
307307
return isLeapYear(((Date)date).getNormalizedYear()) ? 366 : 365;
308308
}
309309

310-
public int getYearLengthInMonths(CalendarDate date) {
311-
return 12;
312-
}
313-
314310
static final int[] DAYS_IN_MONTH
315311
// 12 1 2 3 4 5 6 7 8 9 10 11 12
316312
= { 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
@@ -527,7 +523,7 @@ final int getGregorianYearFromFixedDate(long fixedDate) {
527523
/**
528524
* @return true if the specified year is a Gregorian leap year, or
529525
* false otherwise.
530-
* @see BaseCalendar#isGregorianLeapYear
526+
* @see CalendarUtils#isGregorianLeapYear
531527
*/
532528
protected boolean isLeapYear(CalendarDate date) {
533529
return isLeapYear(((Date)date).getNormalizedYear());

src/java.base/share/classes/sun/util/calendar/CalendarDate.java

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -152,7 +152,7 @@ public CalendarDate addYear(int n) {
152152
* @return <code>true</code> if this <code>CalendarDate</code> is
153153
* normalized and the year of this <code>CalendarDate</code> is a
154154
* leap year, or <code>false</code> otherwise.
155-
* @see BaseCalendar#isGregorianLeapYear
155+
* @see CalendarUtils#isGregorianLeapYear
156156
*/
157157
public boolean isLeapYear() {
158158
return leapYear;
@@ -194,14 +194,6 @@ public CalendarDate setDayOfMonth(int date) {
194194
return this;
195195
}
196196

197-
public CalendarDate addDayOfMonth(int n) {
198-
if (n != 0) {
199-
dayOfMonth += n;
200-
normalized = false;
201-
}
202-
return this;
203-
}
204-
205197
/**
206198
* Returns the day of week value. If this CalendarDate is not
207199
* normalized, {@link #FIELD_UNDEFINED} is returned.
@@ -247,14 +239,6 @@ public CalendarDate setMinutes(int minutes) {
247239
return this;
248240
}
249241

250-
public CalendarDate addMinutes(int n) {
251-
if (n != 0) {
252-
minutes += n;
253-
normalized = false;
254-
}
255-
return this;
256-
}
257-
258242
public int getSeconds() {
259243
return seconds;
260244
}
@@ -267,14 +251,6 @@ public CalendarDate setSeconds(int seconds) {
267251
return this;
268252
}
269253

270-
public CalendarDate addSeconds(int n) {
271-
if (n != 0) {
272-
seconds += n;
273-
normalized = false;
274-
}
275-
return this;
276-
}
277-
278254
public int getMillis() {
279255
return millis;
280256
}
@@ -287,14 +263,6 @@ public CalendarDate setMillis(int millis) {
287263
return this;
288264
}
289265

290-
public CalendarDate addMillis(int n) {
291-
if (n != 0) {
292-
millis += n;
293-
normalized = false;
294-
}
295-
return this;
296-
}
297-
298266
public long getTimeOfDay() {
299267
if (!isNormalized()) {
300268
return fraction = TIME_UNDEFINED;
@@ -309,13 +277,6 @@ public CalendarDate setDate(int year, int month, int dayOfMonth) {
309277
return this;
310278
}
311279

312-
public CalendarDate addDate(int year, int month, int dayOfMonth) {
313-
addYear(year);
314-
addMonth(month);
315-
addDayOfMonth(dayOfMonth);
316-
return this;
317-
}
318-
319280
public CalendarDate setTimeOfDay(int hours, int minutes, int seconds, int millis) {
320281
setHours(hours);
321282
setMinutes(minutes);
@@ -324,14 +285,6 @@ public CalendarDate setTimeOfDay(int hours, int minutes, int seconds, int millis
324285
return this;
325286
}
326287

327-
public CalendarDate addTimeOfDay(int hours, int minutes, int seconds, int millis) {
328-
addHours(hours);
329-
addMinutes(minutes);
330-
addSeconds(seconds);
331-
addMillis(millis);
332-
return this;
333-
}
334-
335288
protected void setTimeOfDay(long fraction) {
336289
this.fraction = fraction;
337290
}
@@ -345,10 +298,6 @@ public boolean isStandardTime() {
345298
return forceStandardTime;
346299
}
347300

348-
public void setStandardTime(boolean standardTime) {
349-
forceStandardTime = standardTime;
350-
}
351-
352301
public boolean isDaylightTime() {
353302
if (isStandardTime()) {
354303
return false;
@@ -382,10 +331,9 @@ && getYear() == date.getYear()
382331
}
383332

384333
public boolean equals(Object obj) {
385-
if (!(obj instanceof CalendarDate)) {
334+
if (!(obj instanceof CalendarDate that)) {
386335
return false;
387336
}
388-
CalendarDate that = (CalendarDate) obj;
389337
if (isNormalized() != that.isNormalized()) {
390338
return false;
391339
}

src/java.base/share/classes/sun/util/calendar/CalendarSystem.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -234,14 +234,6 @@ public static CalendarSystem forName(String calendarName) {
234234
*/
235235
public abstract int getYearLength(CalendarDate date);
236236

237-
/**
238-
* Returns the number of months of the specified year. This method
239-
* does not perform the normalization with the specified
240-
* <code>CalendarDate</code>. The <code>CalendarDate</code> must
241-
* be normalized to get a correct value.
242-
*/
243-
public abstract int getYearLengthInMonths(CalendarDate date);
244-
245237
/**
246238
* Returns the length in days of the month specified by the calendar
247239
* date. This method does not perform the normalization with the
@@ -255,13 +247,6 @@ public static CalendarSystem forName(String calendarName) {
255247
*/
256248
public abstract int getMonthLength(CalendarDate date); // no setter
257249

258-
/**
259-
* Returns the length in days of a week in this calendar
260-
* system. If this calendar system has multiple radix weeks, this
261-
* method returns only one of them.
262-
*/
263-
public abstract int getWeekLength();
264-
265250
/**
266251
* Returns the <code>Era</code> designated by the era name that
267252
* has to be known to this calendar system. If no Era is
@@ -287,13 +272,6 @@ public static CalendarSystem forName(String calendarName) {
287272
*/
288273
public abstract Era[] getEras();
289274

290-
/**
291-
* @throws IllegalArgumentException if the specified era name is
292-
* unknown to this calendar system.
293-
* @see Era
294-
*/
295-
public abstract void setEra(CalendarDate date, String eraName);
296-
297275
/**
298276
* Returns a <code>CalendarDate</code> of the n-th day of week
299277
* which is on, after or before the specified date. For example, the

src/java.base/share/classes/sun/util/calendar/CalendarUtils.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,9 +25,6 @@
2525

2626
package sun.util.calendar;
2727

28-
import java.util.HashMap;
29-
import java.util.Map;
30-
3128
public class CalendarUtils {
3229

3330
/**
@@ -109,29 +106,6 @@ public static final int floorDivide(int n, int d, int[] r) {
109106
return q;
110107
}
111108

112-
/**
113-
* Divides two integers and returns the floor of the quotient and
114-
* the modulus remainder. For example,
115-
* <code>floorDivide(-1,4)</code> returns <code>-1</code> with
116-
* <code>3</code> as its remainder, while <code>-1/4</code> is
117-
* <code>0</code> and <code>-1%4</code> is <code>-1</code>.
118-
*
119-
* @param n the numerator
120-
* @param d a divisor which must be {@literal > 0}
121-
* @param r an array of at least one element in which the value
122-
* <code>mod(n, d)</code> is returned.
123-
* @return the floor of the quotient.
124-
*/
125-
public static final int floorDivide(long n, int d, int[] r) {
126-
if (n >= 0) {
127-
r[0] = (int)(n % d);
128-
return (int)(n / d);
129-
}
130-
int q = (int)(((n + 1) / d) - 1);
131-
r[0] = (int)(n - (q * d));
132-
return q;
133-
}
134-
135109
public static final long mod(long x, long y) {
136110
return (x - y * floorDivide(x, y));
137111
}

src/java.base/share/classes/sun/util/calendar/Era.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -79,9 +79,9 @@ public Era(String name, String abbr, long since, boolean localTime) {
7979
this.abbr = abbr;
8080
this.since = since;
8181
this.localTime = localTime;
82-
Gregorian gcal = CalendarSystem.getGregorianCalendar();
83-
BaseCalendar.Date d = gcal.newCalendarDate(null);
84-
gcal.getCalendarDate(since, d);
82+
Gregorian gCal = CalendarSystem.getGregorianCalendar();
83+
BaseCalendar.Date d = gCal.newCalendarDate(null);
84+
gCal.getCalendarDate(since, d);
8585
sinceDate = new ImmutableGregorianDate(d);
8686
}
8787

@@ -97,10 +97,6 @@ public String getAbbreviation() {
9797
return abbr;
9898
}
9999

100-
public String getDiaplayAbbreviation(Locale locale) {
101-
return abbr;
102-
}
103-
104100
public long getSince(TimeZone zone) {
105101
if (zone == null || !localTime) {
106102
return since;
@@ -118,10 +114,9 @@ public boolean isLocalTime() {
118114
}
119115

120116
public boolean equals(Object o) {
121-
if (!(o instanceof Era)) {
117+
if (!(o instanceof Era that)) {
122118
return false;
123119
}
124-
Era that = (Era) o;
125120
return name.equals(that.name)
126121
&& abbr.equals(that.abbr)
127122
&& since == that.since

0 commit comments

Comments
 (0)