2 * Copyright (C) 2010 Google Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.i18n.addressinput;
19 import java.util.HashMap;
23 * Defines the character codes used in the metadata to specify the types of fields used in address
24 * formatting. Note that the metadata also has a character for newlines, which is not defined here.
26 public enum AddressField {
31 // Deprecated - use A instead.
33 // Deprecated - use A instead.
35 DEPENDENT_LOCALITY('D'),
43 * Enum for width types of address input fields.
45 public enum WidthType {
50 private static final Map<Character, AddressField> FIELD_MAPPING
51 = new HashMap<Character, AddressField>();
54 for (AddressField value : values()) {
55 FIELD_MAPPING.put(value.getChar(), value);
59 private final char field;
61 private AddressField(char field) {
66 * Gets the corresponding AddressField for the character code. Returns null if the character is
69 static AddressField of(char field) {
70 return FIELD_MAPPING.get(field);
74 * Gets the field's identification character, as used in the metadata.
76 * @return identification char.
82 /** Returns default width type of the address field. */
83 WidthType getDefaulWidthType() {
84 return this.equals(POSTAL_CODE) || this.equals(SORTING_CODE)
85 ? WidthType.SHORT : WidthType.LONG;