1/* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.i18n.addressinput; 18 19import java.util.HashMap; 20import java.util.Map; 21 22/** 23 * Enumerates all the data fields found in the JSON-format address property data that are used by 24 * the Android Address Input Widget. 25 */ 26enum AddressDataKey { 27 /** 28 * Identifies the countries for which data is provided. 29 */ 30 COUNTRIES, 31 /** 32 * The standard format string. This identifies which fields can be used in the address, along 33 * with their order. This also carries additional information for use in formatting the fields 34 * into multiple lines. This is also used to indicate which fields should _not_ be used for an 35 * address. 36 */ 37 FMT, 38 /** 39 * The unique ID of the region, in the form of a path from parent IDs to the key. 40 */ 41 ID, 42 /** 43 * The key of the region, unique to its parent. If there is an accepted abbreviation for this 44 * region, then the key will be set to this and name will be set to the local name for this 45 * region. If there is no accepted abbreviation, then this key will be the local name and there 46 * will be no local name specified. This value must be present. 47 */ 48 KEY, 49 /** 50 * The language of this data, if known. 51 */ 52 LANG, 53 /** 54 * The latin format string {@link #FMT} used when a country defines an alternative format for 55 * use with the latin script, such as in China. 56 */ 57 LFMT, 58 /** 59 * Indicates the type of the name used for the locality (city) field. 60 */ 61 LOCALITY_NAME_TYPE, 62 /** 63 * Indicates which fields must be present in a valid address. 64 */ 65 REQUIRE, 66 /** 67 * Indicates the type of the name used for the state (administrative area) field. 68 */ 69 STATE_NAME_TYPE, 70 /** 71 * Encodes the {@link #KEY} value of all the children of this region. 72 */ 73 SUB_KEYS, 74 /** 75 * Encodes the transliterated latin name value of all the children of this region, if the local 76 * names are not in latin script already. 77 */ 78 SUB_LNAMES, 79 /** 80 * Indicates, for each child of this region, whether that child has additional children. 81 */ 82 SUB_MORES, 83 /** 84 * Encodes the local name value of all the children of this region. 85 */ 86 SUB_NAMES, 87 /** 88 * Encodes the {@link #ZIP} value for the subtree beneath this region. 89 */ 90 XZIP, 91 /** 92 * Encodes the postal code pattern if at the country level, and the postal code prefix if at a 93 * level below country. 94 */ 95 ZIP, 96 /** 97 * Indicates the type of the name used for the ZIP (postal code) field. 98 */ 99 ZIP_NAME_TYPE; 100 101 /** 102 * Returns a field based on its keyname (value in the JSON-format file), or null if no field 103 * matches. 104 */ 105 static AddressDataKey get(String keyname) { 106 return ADDRESS_KEY_NAME_MAP.get(keyname.toLowerCase()); 107 } 108 109 private static final Map<String, AddressDataKey> ADDRESS_KEY_NAME_MAP = 110 new HashMap<String, AddressDataKey>(); 111 112 static { 113 // Populates the map of enums against their lower-cased string values for easy look-up. 114 for (AddressDataKey field : values()) { 115 ADDRESS_KEY_NAME_MAP.put(field.toString().toLowerCase(), field); 116 } 117 } 118} 119