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;
}
分享到:
相关推荐
Refactoring: Improving the Design of Existing Code shows how refactoring can make object-oriented code simpler and easier to maintain. Today refactoring requires considerable design know-how, but ...
Refactoring Ruby
系统重构架构设计,A guide to refactoring, the process of changing a software system so that it does not alter the external behavior of the code yet improves its internal structure, for professional ...
Refactoring is an effective way to quickly uncover problematic code and fix it. In this first book to provide a hands-on approach to refactoring in C# and ASP.NET, you’ll discover to apply ...
a book about SQL refactoring
refactoring to patterns
This eagerly awaited new edition has been fully updated to reflect crucial changes in the programming landscape.Refactoring, Second Edition,features an updated catalog of refactorings and includes ...
Refactoring(Improving the Design of Existing Code) 我加上了每个重构方法的书签,方便查阅
PHP Refactoring Browser ,这是 PHP 代码的重构工具,通过生成 diffs 来描述重构的步骤。为了避免重构过程中的简单错误,...
UI设计(UserInterfaceDesign),即界面设计,是指对软件的人机交互、操作逻辑、界面美观的整体设计。它可以分为实体UI和虚拟UI两类,互联网中所提及的UI设计即是虚拟UI。 好的UI设计不仅可以让软件变得更有个性、有...
Refactoring.in.Ruby.pdf
Refactoring2-free-chapter_cn
原版Refactoring思想和实践,深入了解Refact 精髓。
Refactoring to Patterns
Refactoring is an effective way to quickly uncover problematic code and fix it. In this first book to provide a hands-on approach to refactoring in C# and ASP.NET, you'll discover to apply refactoring...
Refactoring_2_Patter
Refactoring in Large Software Projects