public void Add(Address address)
 {
     if (prefectureDictionary.ContainsKey(address.Prefecture))
     {
         prefectureDictionary[address.Prefecture].Add(address);
     }
     else
     {
         var prefectureSet = new PrefectureSet(address.Prefecture);
         prefectureSet.Add(address);
         prefectureDictionary[address.Prefecture] = prefectureSet;
         prefectureSets.Add(prefectureSet);
     }
 }
 public void Add(PostalCode postalCode)
 {
     if (prefectureDictionary.ContainsKey(postalCode.Prefecture))
     {
         prefectureDictionary[postalCode.Prefecture].Add(postalCode);
     }
     else
     {
         var prefectureSet = new PrefectureSet(postalCode.Prefecture);
         prefectureSet.Add(postalCode);
         prefectureDictionary[postalCode.Prefecture] = prefectureSet;
         prefectureSets.Add(prefectureSet);
     }
 }
示例#3
0
        public IReadOnlyList <LocationMatch> FindLocations(PrefectureSet prefectureSet)
        {
            var result = new List <LocationMatch>();

            foreach (var postalCode in prefectureSet.PostalCodes)
            {
                var locationMatch = new LocationMatch(postalCode);

                foreach (var address in prefectureSet.Addresses)
                {
                    if (postalCode.Prefecture != address.Prefecture ||
                        postalCode.Municipality != address.Municipality)
                    {
                        continue;
                    }

                    locationMatch.AddSameMunicipalityMatches(address);

                    if (postalCode.TownArea is null)
                    {
                        continue;
                    }
                    if (address.TownArea.StartsWith(postalCode.TownArea))
                    {
                        locationMatch.AddSameTownAreaMatch(address);
                    }

                    if (postalCode.SubTownAreas is null)
                    {
                        continue;
                    }
                    foreach (string subTownArea in postalCode.SubTownAreas)
                    {
                        if (address.TownArea == (postalCode.TownArea + subTownArea))
                        {
                            locationMatch.AddExactMatch(address);
                        }
                    }
                }

                result.Add(locationMatch);
            }

            return(result);
        }