Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8348325

TimeZone methods to stream the available timezone IDs

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 25
    • core-libs
    • None
    • source
    • low
    • Adding a pair of methods to an abstract class. There is low risk that an existing subclass has already defined methods with such a name.
    • Java API
    • SE

      Summary

      In java.util.TimeZone, provide methods that return a stream of time zone IDs.

      Problem

      java.util.TimeZone provides getAvailableIDs() which return an array of time zone IDs. Providing a method which returns a stream of time zone IDs allows for greater processing capabilities. While apps can make the array to stream conversion themselves, such a method would act as a convenience but also bypass the overhead of creating a copy of the time zone IDs.

      In fact, there are existing use cases within JDK tests that perform the array to stream conversion to utilize stream operations.

      Solution

      Introduce availableIDs() and availableIDs(int rawOffset) which are cousin methods of the existing getAvailableIDs() and getAvailableIDs(int rawOffset).

      Specification

      Update getAvailableIDs(int),

           /**
            * Gets the available IDs according to the given time zone offset in milliseconds.
            *
      +     * @apiNote Consider using {@link #availableIDs(int)} which returns
      +     * a stream of the available time zone IDs according to the given offset.
      +     *
            * @param rawOffset the given time zone GMT offset in milliseconds.
            * @return an array of IDs, where the time zone for that ID has
            * the specified GMT offset. For example, "America/Phoenix" and "America/Denver"
            * both have GMT-07:00, but differ in daylight saving behavior.
            * @see #getRawOffset()
      +     * @see #availableIDs(int)
            */
           public static synchronized String[] getAvailableIDs(int rawOffset) {

      Update getAvailableIDs(),

           /**
      -     * Gets all the available IDs supported.
      -     * @return an array of IDs.
      +     * {@return an array of the available IDs supported}
      +     *
      +     * @apiNote Consider using {@link #availableIDs()} which returns
      +     * a stream of the available time zone IDs.
      +     *
      +     * @see #availableIDs()
            */
           public static synchronized String[] getAvailableIDs() {

      Add availableIDs(int),

      +    /**
      +     * Gets the available IDs according to the given time zone offset in milliseconds.
      +     *
      +     * @implNote Unlike {@link #getAvailableIDs(int)}, this method does
      +     * not create a copy of the {@code TimeZone} IDs array.
      +     *
      +     * @param rawOffset the given time zone GMT offset in milliseconds.
      +     * @return a stream of IDs, where the time zone for that ID has
      +     * the specified GMT offset. For example, "America/Phoenix" and "America/Denver"
      +     * both have GMT-07:00, but differ in daylight saving behavior.
      +     * @see #getRawOffset()
      +     * @see #getAvailableIDs(int)
      +     * @since 25
      +     */
      +    public static Stream<String> availableIDs(int rawOffset) {

      Add availableIDs(),

      +    /**
      +     * {@return a stream of the available IDs supported}
      +     *
      +     * @implNote Unlike {@link #getAvailableIDs()}, this method does
      +     * not create a copy of the {@code TimeZone} IDs array.
      +     *
      +     * @since 25
      +     * @see #getAvailableIDs()
      +     */
      +    public static Stream<String> availableIDs() {

            jlu Justin Lu
            jlu Justin Lu
            Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: