View Javadoc

1   package net.sourceforge.jgeocoder.us;
2   
3   import java.io.BufferedReader;
4   import java.io.IOException;
5   import java.io.InputStreamReader;
6   import java.util.Arrays;
7   import java.util.Comparator;
8   import java.util.HashMap;
9   import java.util.HashSet;
10  import java.util.List;
11  import java.util.Map;
12  import java.util.Set;
13  
14  class SpecialData{
15  	public static final Map<String, List<String>> C_MAP = new HashMap<String, List<String>>();
16  	static{
17  	  BufferedReader r = null;
18  		try {
19  			r = new BufferedReader( new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("exception_city.txt")));
20  			String line = null;
21  			Map<String, Set<String>> tmp = new HashMap<String, Set<String>>();
22  			while((line = r.readLine())!=null){
23  				String[] items = line.split("//s*->//s*");
24  				String[] cities = items[1].split("[|]");
25  				String state = items[0];
26  				Set<String> set = tmp.get(state);
27  				if(set == null){
28  					set = new HashSet<String>();
29  					tmp.put(state, set);
30  				}
31  				for(String city : cities){					
32  					set.add(city);
33  				}
34  			}
35  			for(Map.Entry<String, Set<String>> e : tmp.entrySet()){
36  				String[] array = e.getValue().toArray(new String[]{});
37  				Arrays.sort(array, new Comparator<String>(){
38  					@Override
39  					public int compare(String o1, String o2) {
40  						return Integer.valueOf(o2.length()).compareTo(o1.length());
41  					}
42  				});
43  				C_MAP.put(e.getKey(), Arrays.asList(array));
44  			}
45  		} catch (Exception e) {
46  			throw new Error("Unable to initalize exception_city", e);
47  		}finally{
48  		  if(r != null){ try {
49          r.close();
50        } catch (IOException e) {} }
51  		}
52  	}
53  }