Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/util/calendar/zi/Zone.java
38855 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425import java.io.BufferedReader;26import java.io.FileReader;27import java.io.FileNotFoundException;28import java.io.IOException;29import java.util.ArrayList;30import java.util.HashMap;31import java.util.HashSet;32import java.util.List;33import java.util.Map;34import java.util.Set;35import java.util.StringTokenizer;3637/**38* Zone holds information corresponding to a "Zone" part of a time39* zone definition file.40*41* @since 1.442*/43class Zone {44// zone name (e.g., "America/Los_Angeles")45private String name;4647// zone records48private List<ZoneRec> list;4950// target zone names for this compilation51private static Set<String> targetZones;5253/**54* Constructs a Zone with the specified zone name.55* @param name the zone name56*/57Zone(String name) {58this.name = name;59list = new ArrayList<ZoneRec>();60}6162/**63* Reads time zone names to be generated, called "target zone64* name", from the specified text file and creats an internal hash65* table to keep those names. It's assumed that one text line66* contains a zone name or comments if it starts with67* '#'. Comments can't follow a zone name in a single line.68* @param fileName the text file name69*/70static void readZoneNames(String fileName) {71if (fileName == null) {72return;73}74BufferedReader in = null;75try {76FileReader fr = new FileReader(fileName);77in = new BufferedReader(fr);78} catch (FileNotFoundException e) {79Main.panic("can't open file: " + fileName);80}81targetZones = new HashSet<String>();82String line;8384try {85while ((line = in.readLine()) != null) {86line = line.trim();87if (line.length() == 0 || line.charAt(0) == '#') {88continue;89}90if (!targetZones.add(line)) {91Main.warning("duplicated target zone name: " + line);92}93}94in.close();95} catch (IOException e) {96Main.panic("IO error: "+e.getMessage());97}98}99100/**101* Determines whether the specified zone is one of the target zones.102* If no target zones are specified, this method always returns103* true for any zone name.104* @param zoneName the zone name105* @return true if the specified name is a target zone.106*/107static boolean isTargetZone(String zoneName) {108if (targetZones == null) {109return true;110}111return targetZones.contains(zoneName);112}113114/**115* Forces to add "MET" to the target zone table. This is because116* there is a conflict between Java zone name "WET" and Olson zone117* name.118*/119static void addMET() {120if (targetZones != null) {121targetZones.add("MET");122}123}124125/**126* @return the zone name127*/128String getName() {129return name;130}131132/**133* Adds the specified zone record to the zone record list.134*/135void add(ZoneRec rec) {136list.add(rec);137}138139/**140* @param index the index at which the zone record in the list is returned.141* @return the zone record specified by the index.142*/143ZoneRec get(int index) {144return list.get(index);145}146147/**148* @return the size of the zone record list149*/150int size() {151return list.size();152}153154/**155* Resolves the reference to a rule in each zone record.156* @param zi the Zoneinfo object with which the rule reference is157* resolved.158*/159void resolve(Zoneinfo zi) {160for (int i = 0; i < list.size(); i++) {161ZoneRec rec = list.get(i);162rec.resolve(zi);163}164}165}166167168