1 33 package com.icesoft.applications.faces.address; 34 35 import java.util.Iterator ; 36 import java.util.TreeMap ; 37 38 41 public class MatchCity extends MatchBean { 42 43 public MatchCity(String city) { 44 this.city = city; 45 zipMap = new TreeMap (); 46 } 47 48 public MatchCity(String city, String state) { 49 this.city = city; 50 this.state = state; 51 zipMap = new TreeMap (); 52 } 53 54 59 public MatchZip addZip(MatchZip zipDb) { 60 MatchZip existingZip = getZip(zipDb.getZip()); 61 62 if (existingZip == null) { 63 zipMap.put(zipDb.getZip(), zipDb); 64 return zipDb; 65 } else { 66 return existingZip; 67 } 68 } 69 70 75 public String [] getZipsAsStrings() { 76 77 Iterator itor = zipMap.keySet().iterator(); 78 String zips[] = new String [zipMap.size()]; 79 int i = 0; 80 81 while (itor.hasNext()) { 82 zips[i++] = (String ) itor.next(); 83 } 84 return zips; 85 } 86 87 93 public boolean hasZip(String checkZip) { 94 return getClosestZip(checkZip).isMatch(); 95 } 96 97 104 public MatchZip getZip(String checkZip) { 105 106 MatchZip matchingZip = (MatchZip) zipMap.get(checkZip); 107 108 if (matchingZip != null) { 109 matchingZip.setMatch(true); 111 } 112 return matchingZip; 113 } 114 115 121 public MatchZip getClosestZip(String checkZip) { 122 checkZip = checkZip.trim(); 123 return (MatchZip) getClosestMatch(checkZip, zipMap); 124 } 125 } | Popular Tags |