예제 #1
0
  /**
   * Generates aliases and rawOffsets tables.
   *
   * @param zi a Zoneinfo containing Zones
   */
  void add(Zoneinfo zi) {
    Map<String, Zone> zones = zi.getZones();

    for (String zoneName : zones.keySet()) {
      Zone zone = zones.get(zoneName);
      String zonename = zone.getName();
      int rawOffset = zone.get(zone.size() - 1).getGmtOffset();

      // If the GMT offset of this Zone will change in some
      // future time, this Zone is added to the exclude list.
      boolean isExcluded = false;
      if (zone.size() > 1) {
        ZoneRec zrec = zone.get(zone.size() - 2);
        if ((zrec.getGmtOffset() != rawOffset) && (zrec.getUntilTime(0) > Time.getCurrentTime())) {
          if (excludeList == null) {
            excludeList = new ArrayList<String>();
          }
          excludeList.add(zone.getName());
          isExcluded = true;
        }
      }

      if (!rawOffsetsIndex.contains(new Integer(rawOffset))) {
        // Find the index to insert this raw offset zones
        int n = rawOffsetsIndex.size();
        int i;
        for (i = 0; i < n; i++) {
          if (rawOffsetsIndex.get(i) > rawOffset) {
            break;
          }
        }
        rawOffsetsIndex.add(i, rawOffset);

        Set<String> perRawOffset = new TreeSet<String>();
        if (!isExcluded) {
          perRawOffset.add(zonename);
        }
        rawOffsetsIndexTable.add(i, perRawOffset);
      } else if (!isExcluded) {
        int i = rawOffsetsIndex.indexOf(new Integer(rawOffset));
        Set<String> perRawOffset = rawOffsetsIndexTable.get(i);
        perRawOffset.add(zonename);
      }
    }

    Map<String, String> a = zi.getAliases();
    // If there are time zone names which refer to any of the
    // excluded zones, add those names to the excluded list.
    if (excludeList != null) {
      for (String zoneName : a.keySet()) {
        String realname = a.get(zoneName);
        if (excludeList.contains(realname)) {
          excludeList.add(zoneName);
        }
      }
    }
    aliases.putAll(a);
  }