1 33 package com.icesoft.applications.faces.address; 34 35 import java.util.Iterator ; 36 import java.util.TreeMap ; 37 38 41 public class MatchState extends MatchBean { 42 43 46 public MatchState(String state) { 47 this.state = state; 48 cityMap = new TreeMap (); 49 } 50 51 57 public MatchCity addCity(MatchCity cityDb) { 58 MatchCity existingCity = getCity(cityDb.getCity()); 59 if (existingCity == null) { 60 cityMap.put(cityDb.getCity(), cityDb); 61 return cityDb; 62 } 63 return existingCity; 64 } 65 66 71 public String [] getCitiesAsStrings() { 72 73 Iterator itor = cityMap.keySet().iterator(); 74 String cities[] = new String [cityMap.size()]; 75 int i = 0; 76 77 while (itor.hasNext()) { 78 cities[i++] = (String ) itor.next(); 79 } 80 return cities; 81 } 82 83 89 public MatchCity getCity(String checkCity) { 90 MatchCity matchingCity = (MatchCity) cityMap.get(checkCity); 91 if (matchingCity != null) { 92 matchingCity.setMatch(true); 94 } 95 return matchingCity; 96 } 97 98 104 public MatchCity getClosestCity(String checkCity) { 105 checkCity = checkCity.trim(); 106 AddressFormProcessor.fixCapitalization(checkCity); 107 return (MatchCity) getClosestMatch(checkCity, cityMap); 108 } 109 110 116 public MatchZip getClosestZip(String checkZip) { 117 checkZip = checkZip.trim(); 118 Iterator itor = cityMap.keySet().iterator(); 119 TreeMap zips = new TreeMap (); 120 121 while (itor.hasNext()) { 122 MatchCity thisCity = (MatchCity) cityMap.get(itor.next()); 123 MatchZip thisZip = thisCity.getClosestZip(checkZip); 124 zips.put(thisZip.getZip(), thisZip); 125 } 126 return (MatchZip) getClosestMatch(checkZip, zips); 127 } 128 } | Popular Tags |