首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

refactoring 一

2012-10-26 
refactoring 11,Although the condition value.indexOf(() 0? can be instead by bracketsCount(va

refactoring 1

1,Although the condition "value.indexOf("(") < 0"? can be instead by "bracketsCount(value,'(') < bracketsCount(value,')')",use "||",cos the sencond condition can rarely be satisfied and the second condition call a mehtod including a for loop which will lower the performance.

2,no if in if.

//before refactoring

??? if (value.endsWith(")"))
????? {
??? ?? //AR43966, modify by Jerry Gao,April 24,2007
??? ?? if(value.indexOf("(") < 0 || bracketsCount(value,'(') < bracketsCount(value,')')){
??? ??? value = value.substring(0, value.length() - 1);
??? ??? rightBrackets[i] = "yes";
??? ?? }
??? ?? //end
????? }

//after refactoring

?

?

? //AR43966, modify by Jerry Gao,April 25,2007
??????????? //add condition after &&
??????????? if (value.endsWith(")") && (value.indexOf("(") < 0 || bracketsCount(value,'(') < bracketsCount(value,')'))) {
??????????????? value = value.substring(0, value.length() - 1);
??????????????? rightBrackets[i] = "yes";
??????????? }


??? /**
???? * get the count of destination char,add by Jerry Gao for AR43966,April 25,2007
???? * @param sourceStr - source string
???? * @param desChar - the char which want to search
???? * @return the count of destination chars
???? */
??? private static int bracketsCount(String sourceStr,char desChar){
? ?? int count = 0;
? ?? for(int i = 0; i < sourceStr.length();i++){
? ??? if(sourceStr.charAt(i) == desChar)
? ???? count++;
? ?? }
? ?? return count;
??? }

热点排行