< prev index next >

src/java.base/share/classes/java/time/ZoneId.java

Print this page
rev 51919 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: dfuchs, alanb


 355     public static ZoneId of(String zoneId) {
 356         return of(zoneId, true);
 357     }
 358 
 359     /**
 360      * Obtains an instance of {@code ZoneId} wrapping an offset.
 361      * <p>
 362      * If the prefix is "GMT", "UTC", or "UT" a {@code ZoneId}
 363      * with the prefix and the non-zero offset is returned.
 364      * If the prefix is empty {@code ""} the {@code ZoneOffset} is returned.
 365      *
 366      * @param prefix  the time-zone ID, not null
 367      * @param offset  the offset, not null
 368      * @return the zone ID, not null
 369      * @throws IllegalArgumentException if the prefix is not one of
 370      *     "GMT", "UTC", or "UT", or ""
 371      */
 372     public static ZoneId ofOffset(String prefix, ZoneOffset offset) {
 373         Objects.requireNonNull(prefix, "prefix");
 374         Objects.requireNonNull(offset, "offset");
 375         if (prefix.length() == 0) {
 376             return offset;
 377         }
 378 
 379         if (!prefix.equals("GMT") && !prefix.equals("UTC") && !prefix.equals("UT")) {
 380              throw new IllegalArgumentException("prefix should be GMT, UTC or UT, is: " + prefix);
 381         }
 382 
 383         if (offset.getTotalSeconds() != 0) {
 384             prefix = prefix.concat(offset.getId());
 385         }
 386         return new ZoneRegion(prefix, offset.getRules());
 387     }
 388 
 389     /**
 390      * Parses the ID, taking a flag to indicate whether {@code ZoneRulesException}
 391      * should be thrown or not, used in deserialization.
 392      *
 393      * @param zoneId  the time-zone ID, not null
 394      * @param checkAvailable  whether to check if the zone ID is available
 395      * @return the zone ID, not null




 355     public static ZoneId of(String zoneId) {
 356         return of(zoneId, true);
 357     }
 358 
 359     /**
 360      * Obtains an instance of {@code ZoneId} wrapping an offset.
 361      * <p>
 362      * If the prefix is "GMT", "UTC", or "UT" a {@code ZoneId}
 363      * with the prefix and the non-zero offset is returned.
 364      * If the prefix is empty {@code ""} the {@code ZoneOffset} is returned.
 365      *
 366      * @param prefix  the time-zone ID, not null
 367      * @param offset  the offset, not null
 368      * @return the zone ID, not null
 369      * @throws IllegalArgumentException if the prefix is not one of
 370      *     "GMT", "UTC", or "UT", or ""
 371      */
 372     public static ZoneId ofOffset(String prefix, ZoneOffset offset) {
 373         Objects.requireNonNull(prefix, "prefix");
 374         Objects.requireNonNull(offset, "offset");
 375         if (prefix.isEmpty()) {
 376             return offset;
 377         }
 378 
 379         if (!prefix.equals("GMT") && !prefix.equals("UTC") && !prefix.equals("UT")) {
 380              throw new IllegalArgumentException("prefix should be GMT, UTC or UT, is: " + prefix);
 381         }
 382 
 383         if (offset.getTotalSeconds() != 0) {
 384             prefix = prefix.concat(offset.getId());
 385         }
 386         return new ZoneRegion(prefix, offset.getRules());
 387     }
 388 
 389     /**
 390      * Parses the ID, taking a flag to indicate whether {@code ZoneRulesException}
 391      * should be thrown or not, used in deserialization.
 392      *
 393      * @param zoneId  the time-zone ID, not null
 394      * @param checkAvailable  whether to check if the zone ID is available
 395      * @return the zone ID, not null


< prev index next >