Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/util/calendar/zi/Mappings.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.util.ArrayList;26import java.util.HashMap;27import java.util.LinkedList;28import java.util.List;29import java.util.Map;30import java.util.Set;31import java.util.TreeMap;32import java.util.TreeSet;3334/**35* <code>Mappings</code> generates two Maps and a List which are used by36* javazic BackEnd.37*38* @since 1.439*/40class Mappings {41// All aliases specified by Link statements. It's alias name to42// real name mappings.43private Map<String,String> aliases;4445private List<Integer> rawOffsetsIndex;4647private List<Set<String>> rawOffsetsIndexTable;4849// Zone names to be excluded from rawOffset table. Those have GMT50// offsets to change some future time.51private List<String> excludeList;5253/**54* Constructor creates some necessary instances.55*/56Mappings() {57aliases = new TreeMap<String,String>();58rawOffsetsIndex = new LinkedList<Integer>();59rawOffsetsIndexTable = new LinkedList<Set<String>>();60}6162/**63* Generates aliases and rawOffsets tables.64* @param zi a Zoneinfo containing Zones65*/66void add(Zoneinfo zi) {67Map<String,Zone> zones = zi.getZones();6869for (String zoneName : zones.keySet()) {70Zone zone = zones.get(zoneName);71String zonename = zone.getName();72int rawOffset = zone.get(zone.size()-1).getGmtOffset();7374// If the GMT offset of this Zone will change in some75// future time, this Zone is added to the exclude list.76boolean isExcluded = false;77for (int i = 0; i < zone.size(); i++) {78ZoneRec zrec = zone.get(i);79if ((zrec.getGmtOffset() != rawOffset)80&& (zrec.getUntilTime(0) > Time.getCurrentTime())) {81if (excludeList == null) {82excludeList = new ArrayList<String>();83}84excludeList.add(zone.getName());85isExcluded = true;86break;87}88}8990if (!rawOffsetsIndex.contains(new Integer(rawOffset))) {91// Find the index to insert this raw offset zones92int n = rawOffsetsIndex.size();93int i;94for (i = 0; i < n; i++) {95if (rawOffsetsIndex.get(i) > rawOffset) {96break;97}98}99rawOffsetsIndex.add(i, rawOffset);100101Set<String> perRawOffset = new TreeSet<String>();102if (!isExcluded) {103perRawOffset.add(zonename);104}105rawOffsetsIndexTable.add(i, perRawOffset);106} else if (!isExcluded) {107int i = rawOffsetsIndex.indexOf(new Integer(rawOffset));108Set<String> perRawOffset = rawOffsetsIndexTable.get(i);109perRawOffset.add(zonename);110}111}112113Map<String,String> a = zi.getAliases();114// If there are time zone names which refer to any of the115// excluded zones, add those names to the excluded list.116if (excludeList != null) {117for (String zoneName : a.keySet()) {118String realname = a.get(zoneName);119if (excludeList.contains(realname)) {120excludeList.add(zoneName);121}122}123}124aliases.putAll(a);125}126127/**128* Adds valid aliases to one of per-RawOffset table and removes129* invalid aliases from aliases List. Aliases referring to130* excluded zones are not added to a per-RawOffset table.131*/132void resolve() {133int index = rawOffsetsIndexTable.size();134List<String> toBeRemoved = new ArrayList<String>();135for (String key : aliases.keySet()) {136boolean validname = false;137for (int j = 0; j < index; j++) {138Set<String> perRO = rawOffsetsIndexTable.get(j);139boolean isExcluded = (excludeList == null) ?140false : excludeList.contains(key);141142if ((perRO.contains(aliases.get(key)) || isExcluded)143&& Zone.isTargetZone(key)) {144validname = true;145if (!isExcluded) {146perRO.add(key);147Main.info("Alias <"+key+"> added to the list.");148}149break;150}151}152153if (!validname) {154Main.info("Alias <"+key+"> removed from the list.");155toBeRemoved.add(key);156}157}158159// Remove zones, if any, from the list.160for (String key : toBeRemoved) {161aliases.remove(key);162}163// Eliminate any alias-to-alias mappings. For example, if164// there are A->B and B->C, A->B is changed to A->C.165Map<String, String> newMap = new HashMap<String, String>();166for (String key : aliases.keySet()) {167String realid = aliases.get(key);168String leaf = realid;169while (aliases.get(leaf) != null) {170leaf = aliases.get(leaf);171}172if (!realid.equals(leaf)) {173newMap.put(key, leaf);174}175}176aliases.putAll(newMap);177}178179Map<String,String> getAliases() {180return(aliases);181}182183List<Integer> getRawOffsetsIndex() {184return(rawOffsetsIndex);185}186187List<Set<String>> getRawOffsetsIndexTable() {188return(rawOffsetsIndexTable);189}190191List<String> getExcludeList() {192return excludeList;193}194}195196197