Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-5845 Search and fix minor errors and typos
  3. TRUNK-5931

Use isEmpty() to check whether the collection is empty or not

    XMLWordPrintable

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Could
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Core 2.4.0
    • Component/s: None
    • Labels:
    • Complexity:
      Low

      Description

      Following the SonarQube:

      Using Collection.size() to test for emptiness works, but using Collection.isEmpty() makes the code more readable and can be more performant. The time complexity of any isEmpty() method implementation should be O(1) whereas some implementations of size() can be O(n ).

      The places where Collection.size() I used to test for emptiness:

      Sonar links:

      Solution:

      • replace
        if (unrunChangeSets.size() > 0) {...}
        

        with

        if (!unrunChangeSets.isEmpty()) {...}
        
      • replace
        if (liquibaseUpdateFilenames.size() > 0) {...}
        

        with

        if (!liquibaseUpdateFilenames.isEmpty()) {...}
        

        Gliffy Diagrams

          Attachments

            Activity

              People

              Assignee:
              miirochristopher Christopher Miiro
              Reporter:
              sacull Lukasz Debicki
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: