8347955: TimeZone methods to stream the available timezone IDs#23251
8347955: TimeZone methods to stream the available timezone IDs#23251justin-curtis-lu wants to merge 6 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back jlu! A progress list of the required criteria for merging this PR into |
|
@justin-curtis-lu This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 67 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
@justin-curtis-lu The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
naotoj
left a comment
There was a problem hiding this comment.
Looks good. Some files need copyright year bump
| * not create a copy of the {@code TimeZone} IDs array. | ||
| * | ||
| * @param rawOffset the given time zone GMT offset in milliseconds. | ||
| * @return an array of IDs, where the time zone for that ID has |
There was a problem hiding this comment.
Thanks for the catch. Fixed this and bumped those Zone* file copyright years in 48956fd. I double checked that all the test files have 2025 copyright years.
| // specify it. Keep the same behavior for better | ||
| // compatibility. | ||
| String[] list = ids.toArray(new String[ids.size()]); | ||
| String[] list = ids.toArray(new String[0]); |
There was a problem hiding this comment.
Why is this change? Since the array has correct size, no extra array allocation is needed?
There was a problem hiding this comment.
Regarding the switch from toArray(new T[size]) to toArray(new T[0]), based off https://shipilev.net/blog/2016/arrays-wisdom-ancients/#_conclusion, the JVM performs the latter faster. I believe the article data/results still hold true now.
| public static Stream<String> zoneIds(int rawOffset) { | ||
| return zoneIds() | ||
| .filter(id -> getZoneInfo(id).getRawOffset() == rawOffset) | ||
| .sorted(); // Sort the IDs, see getZoneIds(int) |
There was a problem hiding this comment.
This is interesting. one with rawOffset is soreted, but the other is not. It is inconsistent but probably we should align as you did here.
There was a problem hiding this comment.
Noticed that too. There is also the argument that since these stream methods are new, we can leave it un-sorted but we would have to specify the deviation. Although I agree it is best to align for consistency.
There was a problem hiding this comment.
Actually I'm wondering if we should specify these rawOffset methods with an @implNote that states they are sorted.
There was a problem hiding this comment.
I'd rather not. If we did, users would wonder why no-arg return is not sorted, which might be a mere overlook (and if we sort it, it would be costly (num of tzids are not small))
| * @see #getAvailableIDs(int) | ||
| * @since 25 | ||
| */ | ||
| public static synchronized Stream<String> availableIDs(int rawOffset) { |
There was a problem hiding this comment.
Why are these new methods synchronized? I think the streams and the spliterators are late-binding, so the synchronization does not synchronize the access to the underlying arrays. synchronized modifier also does not appear in Javadoc and is not part of the API surface, so it can be safely removed.
There was a problem hiding this comment.
Right, it can be removed. Actually, I think getAvailableIDs() and getAvailableIDs(int) also do not need to be synchronized. The internal IDs are eagerly initialized in the static block of ZoneInfoFile.java and are effectively final and not modified.
There was a problem hiding this comment.
Yep; their synchronized are incorrect. The object monitor lock should have been on ZoneInfoFile.class to be effective.
|
Thanks for the reviews. |
|
Going to push as commit 3a564ed.
Your commit was automatically rebased without conflicts. |
|
@justin-curtis-lu Pushed as commit 3a564ed. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review this PR and CSR which add a pair of methods to java.util.TimeZone that return a stream of the available IDs. See the CSR for the motivation.
A number of existing tests are modified to use the new methods. See test/jdk/java/util/TimeZone/AvailableIDsTest.java which tests the new methods.
Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23251/head:pull/23251$ git checkout pull/23251Update a local copy of the PR:
$ git checkout pull/23251$ git pull https://git.openjdk.org/jdk.git pull/23251/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 23251View PR using the GUI difftool:
$ git pr show -t 23251Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23251.diff
Using Webrev
Link to Webrev Comment