Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/util/calendar/zi/Simple.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.BufferedWriter;26import java.io.File;27import java.io.FileWriter;28import java.io.IOException;29import java.util.HashMap;30import java.util.List;31import java.util.Map;32import java.util.Set;33import java.util.SortedMap;34import java.util.TreeMap;35import java.util.TreeSet;3637/**38* <code>Simple</code> generates TimeZoneData, which had been used as internal39* data of TimeZone before J2SDK1.3.40* Since J2SDK1.4 doesn't need TimeZoneData, this class is for maintenance41* of old JDK release.42*/43class Simple extends BackEnd {4445/**46* Zone records which are applied for given year.47*/48private static Map<String,ZoneRec> lastZoneRecs = new HashMap<>();4950/**51* Rule records which are applied for given year.52*/53private static Map<String,List<RuleRec>> lastRules = new TreeMap<>();5455/**56* zone IDs sorted by their GMT offsets. If zone's GMT57* offset will change in the future, its last known offset is58* used.59*/60private SortedMap<Integer, Set<String>> zonesByOffset = new TreeMap<>();6162/**63* Sets last Rule records and Zone records for given timezone to64* each Map.65*66* @param tz Timezone object for each zone67* @return always 068*/69int processZoneinfo(Timezone tz) {70String zonename = tz.getName();7172lastRules.put(zonename, tz.getLastRules());73lastZoneRecs.put(zonename, tz.getLastZoneRec());7475// Populate zonesByOffset. (Zones that will change their76// GMT offsets are also added to zonesByOffset here.)77int lastKnownOffset = tz.getRawOffset();78Set<String> set = zonesByOffset.get(lastKnownOffset);79if (set == null) {80set = new TreeSet<>();81zonesByOffset.put(lastKnownOffset, set);82}83set.add(zonename);8485return 0;86}8788/**89* Generates TimeZoneData to output SimpleTimeZone data.90* @param map Mappings object which is generated by {@link Main#compile}.91* @return 0 if no error occurred, otherwise 1.92*/93int generateSrc(Mappings map) {94try {95File outD = new File(Main.getOutputDir());96outD.mkdirs();9798FileWriter fw =99new FileWriter(new File(outD, "TimeZoneData.java"), false);100BufferedWriter out = new BufferedWriter(fw);101102out.write("import java.util.SimpleTimeZone;\n\n");103out.write(" static SimpleTimeZone zones[] = {\n");104105Map<String,String> a = map.getAliases();106List<Integer> roi = map.getRawOffsetsIndex();107List<Set<String>> roit = map.getRawOffsetsIndexTable();108109int index = 0;110for (int offset : zonesByOffset.keySet()) {111int o = roi.get(index);112Set<String> set = zonesByOffset.get(offset);113if (offset == o) {114// Merge aliases into zonesByOffset115set.addAll(roit.get(index));116}117index++;118119for (String key : set) {120ZoneRec zrec;121String realname;122List<RuleRec> stz;123if ((realname = a.get(key)) != null) {124// if this alias is not targeted, ignore it.125if (!Zone.isTargetZone(key)) {126continue;127}128stz = lastRules.get(realname);129zrec = lastZoneRecs.get(realname);130} else {131stz = lastRules.get(key);132zrec = lastZoneRecs.get(key);133}134135out.write("\t//--------------------------------------------------------------------\n");136String s = Time.toFormedString(offset);137out.write("\tnew SimpleTimeZone(" +138Time.toFormedString(offset) + ", \"" + key + "\"");139if (realname != null) {140out.write(" /* " + realname + " */");141}142143if (stz == null) {144out.write("),\n");145} else {146RuleRec rr0 = stz.get(0);147RuleRec rr1 = stz.get(1);148149out.write(",\n\t " + Month.toString(rr0.getMonthNum()) +150", " + rr0.getDay().getDayForSimpleTimeZone() + ", " +151rr0.getDay().getDayOfWeekForSimpleTimeZone() + ", " +152Time.toFormedString((int)rr0.getTime().getTime()) + ", " +153rr0.getTime().getTypeForSimpleTimeZone() + ",\n" +154155"\t " + Month.toString(rr1.getMonthNum()) + ", " +156rr1.getDay().getDayForSimpleTimeZone() + ", " +157rr1.getDay().getDayOfWeekForSimpleTimeZone() + ", " +158Time.toFormedString((int)rr1.getTime().getTime())+ ", " +159rr1.getTime().getTypeForSimpleTimeZone() + ",\n" +160161"\t " + Time.toFormedString(rr0.getSave()) + "),\n");162163out.write("\t// " + rr0.getLine() + "\n");164out.write("\t// " + rr1.getLine() + "\n");165}166167String zline = zrec.getLine();168if (zline.indexOf("Zone") == -1) {169zline = "Zone " + key + "\t" + zline.trim();170}171out.write("\t// " + zline + "\n");172}173}174out.write(" };\n");175176out.close();177fw.close();178} catch(IOException e) {179Main.panic("IO error: "+e.getMessage());180return 1;181}182183return 0;184}185}186187188