Home | History | Annotate | Download | only in addressinput
      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 which fields must be present in a valid address.
     60      */
     61     REQUIRE,
     62     /**
     63      * Indicates the name used for the admin areas for a particular region.
     64      */
     65     STATE_NAME_TYPE,
     66     /**
     67      * Encodes the {@link #KEY} value of all the children of this region.
     68      */
     69     SUB_KEYS,
     70     /**
     71      * Encodes the transliterated latin name value of all the children of this region, if the local
     72      * names are not in latin script already.
     73      */
     74     SUB_LNAMES,
     75     /**
     76      * Indicates, for each child of this region, whether that child has additional children.
     77      */
     78     SUB_MORES,
     79     /**
     80      * Encodes the local name value of all the children of this region.
     81      */
     82     SUB_NAMES,
     83     /**
     84      * Encodes the {@link #ZIP} value for the subtree beneath this region.
     85      */
     86     XZIP,
     87     /**
     88      * Encodes the postal code pattern if at the country level, and the postal code prefix if at a
     89      * level below country.
     90      */
     91     ZIP,
     92     /**
     93      * Indicates the name used for the postal code for a particular region.
     94      */
     95     ZIP_NAME_TYPE;
     96 
     97     /**
     98      * Returns a field based on its keyname (value in the JSON-format file), or null if no field
     99      * matches.
    100      */
    101     static AddressDataKey get(String keyname) {
    102         return ADDRESS_KEY_NAME_MAP.get(keyname.toLowerCase());
    103     }
    104 
    105     private static final Map<String, AddressDataKey> ADDRESS_KEY_NAME_MAP =
    106         new HashMap<String, AddressDataKey>();
    107 
    108     static {
    109         // Populates the map of enums against their lower-cased string values for easy look-up.
    110         for (AddressDataKey field : values()) {
    111             ADDRESS_KEY_NAME_MAP.put(field.toString().toLowerCase(), field);
    112         }
    113     }
    114 }
    115