< prev index next >

make/jdk/src/classes/build/tools/tzdb/TzdbZoneRulesProvider.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  50  *
  51  * @since   9
  52  */
  53 
  54 class TzdbZoneRulesProvider {
  55 
  56     /**
  57      * Creates an instance.
  58      *
  59      * @throws ZoneRulesException if unable to load
  60      */
  61     public TzdbZoneRulesProvider(List<Path> files) {
  62         try {
  63              load(files);
  64         } catch (Exception ex) {
  65             throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex);
  66         }
  67     }
  68 
  69     public Set<String> getZoneIds() {
  70         return new TreeSet(regionIds);
  71     }
  72 
  73     public Map<String, String> getAliasMap() {
  74         return links;
  75     }
  76 

  77     public ZoneRules getZoneRules(String zoneId) {
  78         Object obj = zones.get(zoneId);
  79         if (obj == null) {
  80             String zoneId0 = zoneId;
  81             if (links.containsKey(zoneId)) {
  82                 zoneId = links.get(zoneId);
  83                 obj = zones.get(zoneId);
  84             }
  85             if (obj == null) {
  86                 // Timezone link can be located in 'backward' file and it
  87                 // can refer to another link, so we need to check for
  88                 // link one more time, before throwing an exception
  89                 String zoneIdBack = zoneId;
  90                 if (links.containsKey(zoneId)) {
  91                     zoneId = links.get(zoneId);
  92                     obj = zones.get(zoneId);
  93                 }
  94                 if (obj == null) {
  95                     throw new ZoneRulesException("Unknown time-zone ID: " + zoneIdBack);
  96                 }


   1 /*
   2  * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  50  *
  51  * @since   9
  52  */
  53 
  54 class TzdbZoneRulesProvider {
  55 
  56     /**
  57      * Creates an instance.
  58      *
  59      * @throws ZoneRulesException if unable to load
  60      */
  61     public TzdbZoneRulesProvider(List<Path> files) {
  62         try {
  63              load(files);
  64         } catch (Exception ex) {
  65             throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex);
  66         }
  67     }
  68 
  69     public Set<String> getZoneIds() {
  70         return new TreeSet<String>(regionIds);
  71     }
  72 
  73     public Map<String, String> getAliasMap() {
  74         return links;
  75     }
  76 
  77     @SuppressWarnings("unchecked")
  78     public ZoneRules getZoneRules(String zoneId) {
  79         Object obj = zones.get(zoneId);
  80         if (obj == null) {
  81             String zoneId0 = zoneId;
  82             if (links.containsKey(zoneId)) {
  83                 zoneId = links.get(zoneId);
  84                 obj = zones.get(zoneId);
  85             }
  86             if (obj == null) {
  87                 // Timezone link can be located in 'backward' file and it
  88                 // can refer to another link, so we need to check for
  89                 // link one more time, before throwing an exception
  90                 String zoneIdBack = zoneId;
  91                 if (links.containsKey(zoneId)) {
  92                     zoneId = links.get(zoneId);
  93                     obj = zones.get(zoneId);
  94                 }
  95                 if (obj == null) {
  96                     throw new ZoneRulesException("Unknown time-zone ID: " + zoneIdBack);
  97                 }


< prev index next >