net.sourceforge.pmd.rules.strings

Class InefficientEmptyStringCheck

public class InefficientEmptyStringCheck extends AbstractInefficientZeroCheck

This rule finds code which inefficiently determines empty strings. This code

         if(str.trim().length()==0){....
 

is quite inefficient as trim() causes a new String to be created. Smarter code to check for an empty string would be:

 Character.isWhitespace(str.charAt(i));
 

Author: acaplan

Method Summary
booleanappliesToClassName(String name)
booleanisTargetMethod(NameOccurrence occ)
Determine if we're dealing with String.length method

Method Detail

appliesToClassName

public boolean appliesToClassName(String name)

isTargetMethod

public boolean isTargetMethod(NameOccurrence occ)
Determine if we're dealing with String.length method

Parameters: occ The name occurance

Returns: true if it's String.length, else false