`
cary1130
  • 浏览: 199972 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

refactoring 1

    博客分类:
  • java
阅读更多

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 ui 中文版

    《Refactoring UI》是一本由Adam Wathan和Steve Schoger合著的设计书,主要面向开发者,帮助他们在不具备专业设计背景的情况下也能提升UI设计的质量。这本书提供了实用的设计建议和技巧,帮助开发者在日常工作中更好...

    PHP Refactoring Browser.zip

    1. **安装与配置**:首先,你需要下载`php-refactoring-browser-master`压缩包并解压,然后根据项目需求进行配置,如设置PHP解释器路径、代码库位置等。 2. **代码检测**:运行工具,对项目代码进行扫描,找出需要...

    Refactoring

    系统重构架构设计,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)英文版

    1. **测试驱动**:重构过程中,测试是非常重要的一步。为了确保重构后的代码仍然能正确工作,通常会先编写单元测试,然后再进行实际的代码修改。这样可以确保任何变更都不会破坏原有的功能。 2. **逐步进行**:重构...

    Professional Refactoring in C# & ASP.NET

    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 Ruby

    ##### 1. 重构的基本原则 - **无害性原则**:重构过程不应改变程序的外部行为。 - **逐步改进**:重构应该通过一系列小步骤完成,每一步都确保程序的正确性。 - **测试先行**:在进行重构之前,应先编写测试用例,...

    Refactoring: Improving the Design of Existing Code 第二版

    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 UI v1.0.1.pdf

    UI设计(UserInterfaceDesign),即界面设计,是指对软件的人机交互、操作逻辑、界面美观的整体设计。它可以分为实体UI和虚拟UI两类,互联网中所提及的UI设计即是虚拟UI。 好的UI设计不仅可以让软件变得更有个性、有...

    Refactoring2-free-chapter_cn.pdf

    Refactoring2-free-chapter_cn

    Refactoring思想和实践

    1. **识别坏味道(Code Smells)**:当代码出现冗余、复杂度过高、过于依赖等现象时,我们可以称它们为“坏味道”。识别这些现象是重构的第一步,因为它们通常预示着潜在的问题。 2. **单一职责原则**:每个类或...

    Refactoring Improving The Design Of Existing Code

    Refactoring Improving The Design Of Existing Code

    Refactoring(Improving the Design of Existing Code)

    这本书专注于一个非常重要的软件开发实践,即重构(Refactoring)。重构指的是在不改变外部功能的前提下,对软件的内部结构进行改善的过程。该书的描述提到了书中包含的每个重构方法的书签,为读者查找提供了便利。...

    31天重构指南 《31Days Refactoring》中文版

    《31Days Refactoring》是Sean Chambers撰写的一本关于重构技术的著作,中文版由麒麟.Net翻译。重构,作为软件开发中的一个重要环节,是改善代码结构、提高代码可读性和可维护性的一种方法,不改变代码外在行为,却...

    Refactoring(200803071)

    重构与修正下面问题(包括影片与修正code): http://topic.csdn.net/u/20080305/19/f030ce57-751a-4cea-8b56-28aa3dd7411d.html

    Refactoring2.zip

    《重构:改善既有代码的设计》是一本在IT行业中极具影响力的书籍,由马丁·福勒(Martin Fowler)撰写。这本书深入探讨了代码重构这一关键的软件开发实践,旨在提高代码的质量、可读性和可维护性。...

    Refactoring, Pattern, and Refactoring to Pattern

    1. Refactoring; 2. Design Patterns; 3. Refactoring to Patterns; All chm format books with high quality!

    Automated Java refactoring tool.pdf

    Automated Java refactoring tool.pdf 外文期刊Automatic detection of bad smells in Java code Dynamic analyses for understanding and optimization of Enterprise Java applications

    Refactoring-Improving the Design of Existing Code.pdf

    "Refactoring" was conceived in Smalltalk circles, but it wasn't long before it found its way into other programming language camps. Because refactoring is integral to framework development, the ...

Global site tag (gtag.js) - Google Analytics