1 package org.unicode.cldr.util; 2 3 import com.google.common.base.Splitter; 4 import java.util.Arrays; 5 import java.util.Collections; 6 import java.util.List; 7 import java.util.Locale; 8 import java.util.Map; 9 import java.util.Set; 10 import java.util.TreeMap; 11 import org.unicode.cldr.draft.FileUtilities; 12 13 public class Iso3166Data { 14 public enum Iso3166Status { 15 officially_assigned, 16 private_use, 17 exceptionally_reserved, 18 indeterminately_reserved, 19 transitionally_reserved, 20 formerly_used, 21 out_of_scope 22 } 23 getIsoStatus()24 public static final Map<String, Iso3166Status> getIsoStatus() { 25 return Iso3166Helper.INSTANCE.isoStatus; 26 } 27 getIsoDescription()28 public static final Map<String, String> getIsoDescription() { 29 return Iso3166Helper.INSTANCE.isoDescription; 30 } 31 32 private static final class Iso3166Helper { 33 final Map<String, Iso3166Status> isoStatus; 34 final Map<String, String> isoDescription; 35 Iso3166Helper()36 public Iso3166Helper() { 37 Map<String, Iso3166Status> isoStatus = new TreeMap<>(); 38 Map<String, String> isoDescription = new TreeMap<>(); 39 Splitter semi = Splitter.on(';').trimResults(); 40 for (String line : 41 FileUtilities.in(Iso3166Data.class, "data/external/iso_3166_status.txt")) { 42 if (line.startsWith("#")) continue; 43 List<String> parts = semi.splitToList(line); 44 // AC ; Exceptionally reserved ; Refers to the United Nations and reserved by the 45 // ISO 3166 Maintenance Agency. 46 final String regionCode = parts.get(0); 47 isoStatus.put( 48 regionCode, 49 Iso3166Status.valueOf( 50 parts.get(1).toLowerCase(Locale.ROOT).replace(' ', '_'))); 51 isoDescription.put(regionCode, parts.get(1)); 52 } 53 this.isoStatus = Collections.unmodifiableMap(isoStatus); 54 this.isoDescription = Collections.unmodifiableMap(isoDescription); 55 } 56 57 public static final Iso3166Helper INSTANCE = new Iso3166Helper(); 58 } 59 60 private static final List<String> DELETED3166 = 61 Collections.unmodifiableList( 62 Arrays.asList( 63 new String[] { 64 "BQ", "BU", "CT", "DD", "DY", "FQ", "FX", "HV", "JT", "MI", "NH", 65 "NQ", "NT", "PC", "PU", "PZ", "RH", "SU", "TP", "VD", "WK", "YD", 66 "YU", "ZR" 67 })); 68 getOld3166()69 public static List<String> getOld3166() { 70 return DELETED3166; 71 } 72 73 private static final Set<String> REGION_CODES_NOT_FOR_TRANSLATION = 74 Collections.unmodifiableSet(Collections.singleton("CQ")); 75 76 /** Exceptionally reserved ISO-3166-1 region code, but should not be translated at present. */ getRegionCodesNotForTranslation()77 public static Set<String> getRegionCodesNotForTranslation() { 78 return REGION_CODES_NOT_FOR_TRANSLATION; 79 } 80 81 /** 82 * Exceptionally reserved ISO-3166-1 region code, but should not be translated at present. 83 * 84 * @param territory 85 * @return 86 */ isRegionCodeNotForTranslation(String territory)87 public static boolean isRegionCodeNotForTranslation(String territory) { 88 return (REGION_CODES_NOT_FOR_TRANSLATION.contains(territory)); 89 } 90 } 91