Clover Coverage Report
Coverage timestamp: Fri Jun 27 2008 17:20:33 EDT
../../../../img/srcFileCovDistChart9.png 50% of files have more coverage
475   1,097   198   15.83
224   762   0.42   10
30     6.6  
3    
 
  ZoneMeta       Line # 47 475 198 85% 0.85048014
  ZoneMeta.OlsonToMetaMappingEntry       Line # 831 0 0 - -1.0
  ZoneMeta.MetaToOlsonMappingEntry       Line # 837 0 0 - -1.0
 
No Tests
 
1    /*
2    **********************************************************************
3    * Copyright (c) 2003-2008 International Business Machines
4    * Corporation and others. All Rights Reserved.
5    **********************************************************************
6    * Author: Alan Liu
7    * Created: September 4 2003
8    * Since: ICU 2.8
9    **********************************************************************
10    */
11    package com.ibm.icu.impl;
12   
13    import java.lang.ref.SoftReference;
14    import java.text.ParsePosition;
15    import java.util.Enumeration;
16    import java.util.HashMap;
17    import java.util.HashSet;
18    import java.util.LinkedList;
19    import java.util.List;
20    import java.util.Map;
21    import java.util.MissingResourceException;
22    import java.util.Set;
23    import java.util.Vector;
24   
25    import com.ibm.icu.text.MessageFormat;
26    import com.ibm.icu.text.NumberFormat;
27    import com.ibm.icu.util.SimpleTimeZone;
28    import com.ibm.icu.util.TimeZone;
29    import com.ibm.icu.util.ULocale;
30    import com.ibm.icu.util.UResourceBundle;
31    import com.ibm.icu.util.UResourceBundleIterator;
32   
33    /**
34    * This class, not to be instantiated, implements the meta-data
35    * missing from the underlying core JDK implementation of time zones.
36    * There are two missing features: Obtaining a list of available zones
37    * for a given country (as defined by the Olson database), and
38    * obtaining a list of equivalent zones for a given zone (as defined
39    * by Olson links).
40    *
41    * This class uses a data class, ZoneMetaData, which is created by the
42    * tool tz2icu.
43    *
44    * @author Alan Liu
45    * @since ICU 2.8
46    */
 
47    public final class ZoneMeta {
48    private static final boolean ASSERT = false;
49   
50    /**
51    * Returns a String array containing all system TimeZone IDs
52    * associated with the given country. These IDs may be passed to
53    * <code>TimeZone.getTimeZone()</code> to construct the
54    * corresponding TimeZone object.
55    * @param country a two-letter ISO 3166 country code, or <code>null</code>
56    * to return zones not associated with any country
57    * @return an array of IDs for system TimeZones in the given
58    * country. If there are none, return a zero-length array.
59    */
 
60  9 toggle public static synchronized String[] getAvailableIDs(String country) {
61  9 if(!getOlsonMeta()){
62  0 return EMPTY;
63    }
64  9 try{
65  9 UResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
66  9 UResourceBundle regions = top.get(kREGIONS);
67  9 UResourceBundle names = top.get(kNAMES); // dereference Zones section
68  9 UResourceBundle temp = regions.get(country);
69  8 int[] vector = temp.getIntVector();
70  0 if (ASSERT) Assert.assrt("vector.length>0", vector.length>0);
71  8 String[] ret = new String[vector.length];
72  136 for (int i=0; i<vector.length; ++i) {
73  0 if (ASSERT) Assert.assrt("vector[i] >= 0 && vector[i] < OLSON_ZONE_COUNT",
74    vector[i] >= 0 && vector[i] < OLSON_ZONE_COUNT);
75  128 ret[i] = names.getString(vector[i]);
76    }
77  8 return ret;
78    }catch(MissingResourceException ex){
79    //throw away the exception
80    }
81  1 return EMPTY;
82    }
 
83  234 toggle public static synchronized String[] getAvailableIDs() {
84  234 if(!getOlsonMeta()){
85  0 return EMPTY;
86    }
87  234 try{
88  234 UResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
89  234 UResourceBundle names = top.get(kNAMES); // dereference Zones section
90  234 return names.getStringArray();
91    }catch(MissingResourceException ex){
92    //throw away the exception
93    }
94  0 return EMPTY;
95    }
 
96  61 toggle public static synchronized String[] getAvailableIDs(int offset){
97  61 Vector vector = new Vector();
98  36783 for (int i=0; i<OLSON_ZONE_COUNT; ++i) {
99  36722 String unistr;
100  ? if ((unistr=getID(i))!=null) {
101    // This is VERY inefficient.
102  36722 TimeZone z = TimeZone.getTimeZone(unistr);
103    // Make sure we get back the ID we wanted (if the ID is
104    // invalid we get back GMT).
105  36722 if (z != null && z.getID().equals(unistr) &&
106    z.getRawOffset() == offset) {
107  656 vector.add(unistr);
108    }
109    }
110    }
111  61 if(!vector.isEmpty()){
112  39 String[] strings = new String[vector.size()];
113  39 return (String[])vector.toArray(strings);
114    }
115  22 return EMPTY;
116    }
 
117  36722 toggle private static String getID(int i) {
118  36722 try{
119  36722 UResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
120  36722 UResourceBundle names = top.get(kNAMES); // dereference Zones section
121  36722 return names.getString(i);
122    }catch(MissingResourceException ex){
123    //throw away the exception
124    }
125  0 return null;
126    }
127