[問題] 關於郵遞區號的判別

看板java作者 (swpoker)時間17年前 (2008/10/01 13:36), 編輯推噓7(705)
留言12則, 3人參與, 最新討論串1/1
各位大大好~ 我在處理從地址判斷郵遞區號 3 或 5 碼的時候 再處理前3碼部分就已經完成 就在最後的門號部份的判定 不太清楚該怎麼實作 可以有人提供想法嗎 我的想法是 public interface DoorPlateMatch { public boolean isMatchDoorPlate(String address); } ---> 這個用來判別輸入地址的門號是否符合 public interface PlateStrategy { public boolean isMatchZipcodeFormat(String plate); public DoorPlateMatch getDoorPlateMatch(); } ---> 這個用來匯入規則時~所對應的且要提供門號符合的元件 public class DoorPlateFacade { public static DoorPlateMatch getDoorPlateMatch(String doorplateformat){ for(int i=0;i<plateStrategys.length;i++){ if(plateStrategys[i].isMatchZipcodeFormat(doorplateformat)){ return plateStrategys[i].getDoorPlateMatch(); } } return null; } static PlateStrategy [] plateStrategys = new PlateStrategy[]{ new PlateStrategy(){ /* 全 */ public DoorPlateMatch getDoorPlateMatch() { return new DoorPlateMatch(){ public boolean isMatchDoorPlate(String address) { return true; } }; } public boolean isMatchZipcodeFormat(String plate) { // TODO 自動產生方法 Stub return plate.trim().equals("全"); } } ,new PlateStrategy(){ /* 單全 */ public DoorPlateMatch getDoorPlateMatch() { return new DoorPlateMatch(){ public boolean isMatchDoorPlate(String address) { 待實作 return true; } }; } public boolean isMatchZipcodeFormat(String plate) { // TODO 自動產生方法 Stub return plate.trim().equals("單全"); } } }; } ----> 處理匯入的規則及決定是否有適當的門號判別元件 謝謝~~ 以下為由郵局所提供的區碼判別規則的部份 10058,台北市,中正區,八德路1段,全 10079,台北市,中正區,三元街,單全 10070,台北市,中正區,三元街,雙 48號以下 10079,台北市,中正區,三元街,雙 50號以上 10068,台北市,中正區,大埔街,單 17號以上 ....... (可以在郵局下載此份規則) -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.29.28.137

10/01 14:31, , 1F
要做到後兩碼 要先把那分區規則看完吧? 感覺後兩碼分很細
10/01 14:31, 1F

10/01 15:27, , 2F
就是因為很細~規則很多~所以在想要怎麼弄會比較好~謝謝了
10/01 15:27, 2F

10/01 23:17, , 3F
抓郵局的excel 檔回來,再去比對會不會比你搞規則好?
10/01 23:17, 3F

10/02 00:44, , 4F
拆成樹結構,比你寫rule還要對測來得好寫.
10/02 00:44, 4F

10/02 09:35, , 5F
之前有試過採用decorator,可是有些情況很難處理
10/02 09:35, 5F

10/02 09:37, , 6F
所以我採用stratgey,來寫規則~可以順利分離規則到門號
10/02 09:37, 6F

10/02 11:03, , 7F
我的看法是與其折規則後再全測,不如拿檔回來分拆做成樹
10/02 11:03, 7F

10/02 11:05, , 8F
比較快, 參考看看吧.
10/02 11:05, 8F

10/02 14:49, , 9F
請問樹是指 台北縣-永和市-成功路-連單號 之類的嗎
10/02 14:49, 9F

10/02 14:51, , 10F
你怎麼拆規則就怎麼拆樹, 拆到什麼單雙號再去比大小就好
10/02 14:51, 10F

10/02 23:59, , 11F
其實滿煩雜的ㄟ 例如規則寫A路23號到D路99號同區
10/02 23:59, 11F

10/03 00:02, , 12F
但怎判斷給定地址是否包在此區塊內? 除非有完整的資料庫吧
10/03 00:02, 12F
文章代碼(AID): #18umnV6u (java)