001: /*
002: * @(#)Mappings.java 1.6 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package sun.tools.javazic;
028:
029: import java.util.HashMap;
030: import java.util.Iterator;
031: import java.util.LinkedList;
032: import java.util.Set;
033: import java.util.TreeMap;
034: import java.util.TreeSet;
035:
036: /**
037: * <code>Mappings</code> generates two Maps and a List which are used by
038: * javazic BackEnd.
039: *
040: * @since 1.4
041: */
042: class Mappings {
043: private TreeMap aliases;
044: private LinkedList rawOffsetsIndex;
045: private LinkedList rawOffsetsIndexTable;
046:
047: /**
048: * Constructor creates some necessary instances.
049: */
050: Mappings() {
051: aliases = new TreeMap();
052: rawOffsetsIndex = new LinkedList();
053: rawOffsetsIndexTable = new LinkedList();
054: }
055:
056: /**
057: * Generates aliases and rawOffsets tables.
058: * @param Zoneinfo
059: */
060: void add(Zoneinfo zi) {
061: int i;
062: HashMap zones = zi.getZones();
063: Set s = zones.keySet();
064: Iterator keys = s.iterator();
065: TreeSet perRawOffset;
066:
067: while (keys.hasNext()) {
068: String key = (String) keys.next();
069: Zone zone = zi.getZone(key);
070: String zonename = zone.getName();
071: int rawOffset = zone.get(zone.size() - 1).getGmtOffset();
072:
073: if (!rawOffsetsIndex.contains(new Integer(rawOffset))) {
074: int n = rawOffsetsIndex.size();
075:
076: for (i = 0; i < n; i++) {
077: if (((Integer) rawOffsetsIndex.get(i)).intValue() > rawOffset) {
078: break;
079: }
080: }
081: rawOffsetsIndex.add(i, new Integer(rawOffset));
082:
083: perRawOffset = new TreeSet();
084: perRawOffset.add(zonename);
085: rawOffsetsIndexTable.add(i, perRawOffset);
086: } else {
087: i = rawOffsetsIndex.indexOf(new Integer(rawOffset));
088: perRawOffset = (TreeSet) rawOffsetsIndexTable.get(i);
089: }
090: perRawOffset.add(zonename);
091: }
092:
093: aliases.putAll(zi.getAliases());
094: }
095:
096: /**
097: * Removes invalid aliases from aliases List.
098: */
099: void resolve() {
100: Object o[] = aliases.keySet().toArray();
101: int len = o.length;
102: int index = rawOffsetsIndexTable.size();
103:
104: for (int i = 0; i < len; i++) {
105: String key = o[i].toString();
106: boolean validname = false;
107:
108: for (int j = 0; j < index; j++) {
109: TreeSet perRO = (TreeSet) rawOffsetsIndexTable.get(j);
110:
111: if (perRO.contains(aliases.get(key))
112: && Zone.isTargetZone(key)) {
113: validname = true;
114: perRO.add(key);
115: Main.info("Alias <" + key + "> added to the list.");
116: break;
117: }
118: }
119:
120: if (!validname) {
121: Main.info("Alias <" + key + "> removed from the list.");
122: aliases.remove(key);
123: }
124: }
125: return;
126: }
127:
128: TreeMap getAliases() {
129: return (aliases);
130: }
131:
132: LinkedList getRawOffsetsIndex() {
133: return (rawOffsetsIndex);
134: }
135:
136: LinkedList getRawOffsetsIndexTable() {
137: return (rawOffsetsIndexTable);
138: }
139: }
|