Fix sonar issue s1155 'Collection.isEmpty()' should be used to test for emptiness#83
Open
jlerbsc wants to merge 1 commit intoyuu-nkjm:masterfrom
Open
Fix sonar issue s1155 'Collection.isEmpty()' should be used to test for emptiness#83jlerbsc wants to merge 1 commit intoyuu-nkjm:masterfrom
jlerbsc wants to merge 1 commit intoyuu-nkjm:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We propose the fix to violation s1155 "Collection.isEmpty() should be used to test for emptiness" identified by SonarQube.
When you call isEmpty(), it clearly communicates the code’s intention, which is to check if the collection is empty. Using size() == 0 for this purpose is less direct and makes the code slightly more complex.
Moreover, depending on the implementation, the size() method can have a time complexity of O(n) where n is the number of elements in the collection. On the other hand, isEmpty() simply checks if there is at least one element in the collection, which is a constant time operation, O(1).
This patch has been automatically produced by our java code remediation solution, available free of charge for all open source projects (https://www.indepth.fr/).
We believe that this PR can improve the quality of your project code to a certain extent. Your feedback will also be very useful for us to know if our solution produces quality code or if we need to improve the way it works.
Thank you for your feedback.