2fe58a4b74cbbca181add2a68068050e93c0c9c7
[platform/framework/web/crosswalk.git] / src / third_party / libaddressinput / src / java / src / com / android / i18n / addressinput / AddressDataKey.java
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
17 package com.android.i18n.addressinput;
18
19 import java.util.HashMap;
20 import 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  */
26 enum 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 the type of the name used for the sublocality field.
81      */
82     SUBLOCALITY_NAME_TYPE,
83     /**
84      * Indicates, for each child of this region, whether that child has additional children.
85      */
86     SUB_MORES,
87     /**
88      * Encodes the local name value of all the children of this region.
89      */
90     SUB_NAMES,
91     /**
92      * Encodes the {@link #ZIP} value for the subtree beneath this region.
93      */
94     XZIP,
95     /**
96      * Encodes the postal code pattern if at the country level, and the postal code prefix if at a
97      * level below country.
98      */
99     ZIP,
100     /**
101      * Indicates the type of the name used for the ZIP (postal code) field.
102      */
103     ZIP_NAME_TYPE;
104
105     /**
106      * Returns a field based on its keyname (value in the JSON-format file), or null if no field
107      * matches.
108      */
109     static AddressDataKey get(String keyname) {
110         return ADDRESS_KEY_NAME_MAP.get(keyname.toLowerCase());
111     }
112
113     private static final Map<String, AddressDataKey> ADDRESS_KEY_NAME_MAP =
114         new HashMap<String, AddressDataKey>();
115
116     static {
117         // Populates the map of enums against their lower-cased string values for easy look-up.
118         for (AddressDataKey field : values()) {
119             ADDRESS_KEY_NAME_MAP.put(field.toString().toLowerCase(), field);
120         }
121     }
122 }