Details
-
Technical task
-
Status: Closed
-
Could
-
Resolution: Fixed
-
None
-
None
-
Low
Description
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).
Problem:
Using the size() method to determine if the collection is empty.
Solution:
Using the isEmpty() method for this purpose.
Where the problem occurs:
- https://github.com/openmrs/openmrs-module-registrationapp/blob/1.19.0/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/MatchingPatientsFragmentController.java#L125
- https://github.com/openmrs/openmrs-module-registrationapp/blob/1.19.0/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/RegisterPatientFragmentController.java#L229
- https://github.com/openmrs/openmrs-module-registrationapp/blob/1.19.0/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/RegisterPatientFragmentController.java#L314
Support materials:
- explanation of the problem by SonarQube: https://sonar.openmrs.org/coding_rules#rule_key=squid%3AS1155