forked from phoedos/pmd
Improve implementation hint in InefficientEmptyStringCheck
The alternative implementation mentions iterating over the string and checking for whitespace which is pretty clear, however, showing the implementation doesn't hurt, nor does the hint for Apache commons-lang's StringUtils.isBlank which does exactly that. The if statement in the demonstration of inefficient code can lead to confusion because users _might_ think that the check is only inefficient inside an if statement although it's clear from the description that it's not.
This commit is contained in:
@ -13,7 +13,7 @@ import net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence;
|
||||
* This rule finds code which inefficiently determines empty strings. This code
|
||||
*
|
||||
* <pre>
|
||||
* if(str.trim().length()==0){....
|
||||
* str.trim().length()==0
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
@ -22,8 +22,16 @@ import net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence;
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* Character.isWhitespace(str.charAt(i));
|
||||
* private boolean checkTrimEmpty(String str) {
|
||||
* for(int i=0; i<str.length(); i++) {
|
||||
* if(!Character.isWhitespace(str.charAt(i))) {
|
||||
* return false;
|
||||
* }
|
||||
* }
|
||||
* return true;
|
||||
* }
|
||||
* </pre>
|
||||
* or Apache commons-lang's <code>StringUtils.isBlank</code>.
|
||||
*
|
||||
* @author acaplan
|
||||
*/
|
||||
|
Reference in New Issue
Block a user