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 * This structure keeps track of any errors found when validating the AddressData. 24 */ 25public class AddressProblems { 26 27 private Map<AddressField, AddressProblemType> mProblems = 28 new HashMap<AddressField, AddressProblemType>(); 29 30 /** 31 * Only one address problem type is saved per addressField. Address field as used here refers to 32 * the different data parts in the AddressData class. 33 */ 34 void add(AddressField addressField, AddressProblemType problem) { 35 mProblems.put(addressField, problem); 36 } 37 38 /** 39 * Returns true if no problems have been added. 40 */ 41 public boolean isEmpty() { 42 return mProblems.isEmpty(); 43 } 44 45 @Override 46 public String toString() { 47 return mProblems.toString(); 48 } 49 50 public void clear() { 51 mProblems.clear(); 52 } 53 54 /** 55 * Returns null if no problems exists. 56 */ 57 public AddressProblemType getProblem(AddressField addressField) { 58 return mProblems.get(addressField); 59 } 60 61 /** 62 * This will return an empty map if there are no problems. 63 */ 64 public Map<AddressField, AddressProblemType> getProblems() { 65 return mProblems; 66 } 67} 68