src/share/classes/sun/util/calendar/ZoneInfo.java
Print this page
@@ -28,14 +28,16 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.ref.SoftReference;
import java.security.AccessController;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
/**
* <code>ZoneInfo</code> is an implementation subclass of {@link
@@ -76,23 +78,10 @@
private static final int DST_NSHIFT = 4;
// this bit field is reserved for abbreviation support
private static final long ABBR_MASK = 0xf00L;
private static final int TRANSITION_NSHIFT = 12;
- // Flag for supporting JDK backward compatible IDs, such as "EST".
- static final boolean USE_OLDMAPPING;
- static {
- String oldmapping = AccessController.doPrivileged(
- new sun.security.action.GetPropertyAction("sun.timezone.ids.oldmapping", "false")).toLowerCase(Locale.ROOT);
- USE_OLDMAPPING = (oldmapping.equals("yes") || oldmapping.equals("true"));
- }
-
- // IDs having conflicting data between Olson and JDK 1.1
- static final String[] conflictingIDs = {
- "EST", "MST", "HST"
- };
-
private static final CalendarSystem gcal = CalendarSystem.getGregorianCalendar();
/**
* The raw GMT offset in milliseconds between this zone and GMT.
* Negative offsets are to the west of Greenwich. To obtain local
@@ -570,21 +559,12 @@
* Gets all available IDs supported in the Java run-time.
*
* @return an array of time zone IDs.
*/
public static String[] getAvailableIDs() {
- List<String> idList = ZoneInfoFile.getZoneIDs();
- List<String> excluded = ZoneInfoFile.getExcludedZones();
- if (excluded != null) {
- // List all zones from the idList and excluded lists
- List<String> list = new ArrayList<>(idList.size() + excluded.size());
- list.addAll(idList);
- list.addAll(excluded);
- idList = list;
- }
- String[] ids = new String[idList.size()];
- return idList.toArray(ids);
+ Set<String> idSet = ZoneInfoFile.getZoneIds();
+ return idSet.toArray(new String[idSet.size()]);
}
/**
* Gets all available IDs that have the same value as the
* specified raw GMT offset.
@@ -593,49 +573,11 @@
* value should not include any daylight saving time.
*
* @return an array of time zone IDs.
*/
public static String[] getAvailableIDs(int rawOffset) {
- String[] result;
- List<String> matched = new ArrayList<>();
- List<String> IDs = ZoneInfoFile.getZoneIDs();
- int[] rawOffsets = ZoneInfoFile.getRawOffsets();
-
- loop:
- for (int index = 0; index < rawOffsets.length; index++) {
- if (rawOffsets[index] == rawOffset) {
- byte[] indices = ZoneInfoFile.getRawOffsetIndices();
- for (int i = 0; i < indices.length; i++) {
- if (indices[i] == index) {
- matched.add(IDs.get(i++));
- while (i < indices.length && indices[i] == index) {
- matched.add(IDs.get(i++));
- }
- break loop;
- }
- }
- }
- }
-
- // We need to add any zones from the excluded zone list that
- // currently have the same GMT offset as the specified
- // rawOffset. The zones returned by this method may not be
- // correct as of return to the caller if any GMT offset
- // transition is happening during this GMT offset checking...
- List<String> excluded = ZoneInfoFile.getExcludedZones();
- if (excluded != null) {
- for (String id : excluded) {
- TimeZone zi = getTimeZone(id);
- if (zi != null && zi.getRawOffset() == rawOffset) {
- matched.add(id);
- }
- }
- }
-
- result = new String[matched.size()];
- matched.toArray(result);
- return result;
+ return ZoneInfoFile.getZoneIds(rawOffset);
}
/**
* Gets the ZoneInfo for the given ID.
*
@@ -643,48 +585,11 @@
*
* @return the specified ZoneInfo object, or null if there is no
* time zone of the ID.
*/
public static TimeZone getTimeZone(String ID) {
- String givenID = null;
-
- /*
- * If old JDK compatibility is specified, get the old alias
- * name.
- */
- if (USE_OLDMAPPING) {
- String compatibleID = TzIDOldMapping.MAP.get(ID);
- if (compatibleID != null) {
- givenID = ID;
- ID = compatibleID;
- }
- }
-
- ZoneInfo zi = ZoneInfoFile.getZoneInfo(ID);
- if (zi == null) {
- // if we can't create an object for the ID, try aliases.
- try {
- Map<String, String> map = getAliasTable();
- String alias = ID;
- while ((alias = map.get(alias)) != null) {
- zi = ZoneInfoFile.getZoneInfo(alias);
- if (zi != null) {
- zi.setID(ID);
- zi = ZoneInfoFile.addToCache(ID, zi);
- zi = (ZoneInfo) zi.clone();
- break;
- }
- }
- } catch (Exception e) {
- // ignore exceptions
- }
- }
-
- if (givenID != null && zi != null) {
- zi.setID(givenID);
- }
- return zi;
+ return ZoneInfoFile.getZoneInfo(ID);
}
private transient SimpleTimeZone lastRule;
/**
@@ -809,45 +714,20 @@
return false;
}
return (checksum == ((ZoneInfo)other).checksum);
}
- private static SoftReference<Map<String, String>> aliasTable;
-
- static Map<String, String> getCachedAliasTable() {
- Map<String, String> aliases = null;
-
- SoftReference<Map<String, String>> cache = aliasTable;
- if (cache != null) {
- aliases = cache.get();
- }
- return aliases;
- }
-
/**
* Returns a Map from alias time zone IDs to their standard
* time zone IDs.
*
* @return the Map that holds the mappings from alias time zone IDs
* to their standard time zone IDs, or null if
* <code>ZoneInfoMappings</code> file is not available.
*/
- public synchronized static Map<String, String> getAliasTable() {
- Map<String, String> aliases = getCachedAliasTable();
- if (aliases == null) {
- aliases = ZoneInfoFile.getZoneAliases();
- if (aliases != null) {
- if (!USE_OLDMAPPING) {
- // Remove the conflicting IDs from the alias table.
- for (String key : conflictingIDs) {
- aliases.remove(key);
- }
- }
- aliasTable = new SoftReference<Map<String, String>>(aliases);
- }
- }
- return aliases;
+ public static Map<String, String> getAliasTable() {
+ return ZoneInfoFile.getAliasMap();
}
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();