| Version 2 (modified by zhangyihui, 12 years ago) (diff) |
|---|
2013年9月27日代码道场活动纪实
代码道场的参与者:秦鸿源,陈阳,王安宁,丁健勇,李炳岳,黄志强,李剑文,张艺辉,江毅超, 刘必晓, 李峰
地点:4G会议室
本次代码道场的题目,希望与实际工作有一定的联系,从而能激发大家的热情,所以这期代码道场的题目为论坛系统其中一个方法的重构
题目如下:
重构如下代码:
public static String htmlUrl(Object object, int type) {
boolean isIt = false;
if (isIt && type != SystemConstant.TYPE_WAP ) {
return "";
} else {
switch (type) {
case SystemConstant.TYPE_WEB:
rootUrl = rootUrl;
break;
case SystemConstant.TYPE_WAP:
rootUrl = rootUrl;
break;
default:
break;
}
if ("".equals(rootUrl) || rootUrl == null) {
return "";
}
if (object instanceof Forum) {
Forum forum = (Forum) object;
if (!isEmpty(forum.getRedirectUrl()) && SystemConstant.TYPE_WEB == type) {
return forum.getRedirectUrl();
} else {
return rootUrl + "/forum-" + forum.getFid() + ".html";
}
} else if (object instanceof Topic) {
//销售配合,此帖子跳转到指定链接
if(SystemConstant.AUTO_APP_NAME.equals(appName) && ((Topic) object).getTid() == 4018911){
return "http://ad.doubleclick.net/clk;275446626;102403463;a?http://bbs.pcauto.com.cn/topic-4018911.html";
}
if(SystemConstant.AUTO_APP_NAME.equals(appName) && ((Topic) object).getTid() == 4027940){
return "http://ad.doubleclick.net/clk;275446638;102403466;g?http://bbs.pcauto.com.cn/topic-4027940.html";
}
if(SystemConstant.AUTO_APP_NAME.equals(appName) && ((Topic) object).getTid() == 4040395){
return "http://ad.doubleclick.net/clk;275446642;102403468;d?http://bbs.pcauto.com.cn/topic-4040395.html";
}
return rootUrl + "/topic-" + ((Topic) object).getTid() + ".html";
} else if (object instanceof Post) {
return rootUrl + "/post-" + ((Post) object).getTid() + '_' + ((Post) object).getPid() + ".html";
} else if (object instanceof String) {
return (String) object;
} else if (object instanceof User) {
return "/" + ((User) object).getUid();
} else if (object instanceof ftree.Forum) {
ftree.Forum forum = (ftree.Forum) object;
return rootUrl + "/forum-" + forum.getFid() + ".html";
} else {
return "";
}
}
}
public static boolean isEmpty(String text){
return (null == text || "".equals(text));
}
}}}[[BR]]
活动开始前,咱们组的陈阳童鞋一马当先,只管抢占键盘,是的,他只用键盘,就已经将需要重构的方法提炼出来,完全忽略鼠标,看得我眼睛一眨一眨的,暗下决定要学好vi的使用。
![(please configure the [header_logo] section in trac.ini)](http://www1.pconline.com.cn/hr/2009/global/images/logo.gif)