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;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值