Author: ggregory Date: Tue Aug 2 18:49:52 2011 New Revision: 1153241 URL: http://svn.apache.org/viewvc?rev=1153241&view=rev Log: Fix PMD issues: "These nested if statements could be combined"
Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeUnescaper.java Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?rev=1153241&r1=1153240&r2=1153241&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java Tue Aug 2 18:49:52 2011 @@ -4425,10 +4425,8 @@ public class StringUtils { int lastIdx = strLen - 1; String ret = str.substring(0, lastIdx); char last = str.charAt(lastIdx); - if (last == CharUtils.LF) { - if (ret.charAt(lastIdx - 1) == CharUtils.CR) { - return ret.substring(0, lastIdx - 1); - } + if (last == CharUtils.LF && ret.charAt(lastIdx - 1) == CharUtils.CR) { + return ret.substring(0, lastIdx - 1); } return ret; } Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java?rev=1153241&r1=1153240&r2=1153241&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java Tue Aug 2 18:49:52 2011 @@ -1320,22 +1320,20 @@ public class NumberUtils { boolean foundDigit = false; // deal with any possible sign up front int start = (chars[0] == '-') ? 1 : 0; - if (sz > start + 1) { - if (chars[start] == '0' && chars[start + 1] == 'x') { - int i = start + 2; - if (i == sz) { - return false; // str == "0x" - } - // checking hex (it can't be anything else) - for (; i < chars.length; i++) { - if ((chars[i] < '0' || chars[i] > '9') - && (chars[i] < 'a' || chars[i] > 'f') - && (chars[i] < 'A' || chars[i] > 'F')) { - return false; - } + if (sz > start + 1 && chars[start] == '0' && chars[start + 1] == 'x') { + int i = start + 2; + if (i == sz) { + return false; // str == "0x" + } + // checking hex (it can't be anything else) + for (; i < chars.length; i++) { + if ((chars[i] < '0' || chars[i] > '9') + && (chars[i] < 'a' || chars[i] > 'f') + && (chars[i] < 'A' || chars[i] > 'F')) { + return false; } - return true; } + return true; } sz--; // don't want to loop to the last char, check it afterwords // for type qualifiers Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java?rev=1153241&r1=1153240&r2=1153241&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java Tue Aug 2 18:49:52 2011 @@ -517,22 +517,16 @@ public class MethodUtils { Method bestMatch = null; Method[] methods = cls.getMethods(); for (Method method : methods) { - if (method.getName().equals(methodName)) { - // compare parameters - if (ClassUtils.isAssignable(parameterTypes, method - .getParameterTypes(), true)) { - // get accessible version of method - Method accessibleMethod = getAccessibleMethod(method); - if (accessibleMethod != null) { - if (bestMatch == null - || MemberUtils.compareParameterTypes( - accessibleMethod.getParameterTypes(), - bestMatch.getParameterTypes(), - parameterTypes) < 0) { - bestMatch = accessibleMethod; - } - } - } + // compare name and parameters + if (method.getName().equals(methodName) && ClassUtils.isAssignable(parameterTypes, method.getParameterTypes(), true)) { + // get accessible version of method + Method accessibleMethod = getAccessibleMethod(method); + if (accessibleMethod != null && (bestMatch == null || MemberUtils.compareParameterTypes( + accessibleMethod.getParameterTypes(), + bestMatch.getParameterTypes(), + parameterTypes) < 0)) { + bestMatch = accessibleMethod; + } } } if (bestMatch != null) { Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java?rev=1153241&r1=1153240&r2=1153241&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java Tue Aug 2 18:49:52 2011 @@ -773,12 +773,10 @@ public class StrTokenizer implements Lis } // check for quote, and thus back into quoting mode - if (quoteLen > 0) { - if (isQuote(chars, pos, len, quoteStart, quoteLen)) { - quoting = true; - pos += quoteLen; - continue; - } + if (quoteLen > 0 && isQuote(chars, pos, len, quoteStart, quoteLen)) { + quoting = true; + pos += quoteLen; + continue; } // check for ignored (outside quotes), and ignore Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeUnescaper.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeUnescaper.java?rev=1153241&r1=1153240&r2=1153241&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeUnescaper.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeUnescaper.java Tue Aug 2 18:49:52 2011 @@ -34,34 +34,31 @@ public class UnicodeUnescaper extends Ch */ @Override public int translate(CharSequence input, int index, Writer out) throws IOException { - if(input.charAt(index) == '\\') { - if( (index + 1 < input.length()) && input.charAt(index + 1) == 'u') { - // consume optional additional 'u' chars - int i=2; - while( (index + i < input.length()) && input.charAt(index + i) == 'u') { - i++; - } + if (input.charAt(index) == '\\' && (index + 1 < input.length()) && input.charAt(index + 1) == 'u') { + // consume optional additional 'u' chars + int i = 2; + while ((index + i < input.length()) && input.charAt(index + i) == 'u') { + i++; + } - if( (index + i < input.length()) && (input.charAt(index + i) == '+') ) { - i++; - } + if ((index + i < input.length()) && (input.charAt(index + i) == '+')) { + i++; + } - if( (index + i + 4 <= input.length()) ) { - // Get 4 hex digits - CharSequence unicode = input.subSequence(index + i, index + i + 4); + if ((index + i + 4 <= input.length())) { + // Get 4 hex digits + CharSequence unicode = input.subSequence(index + i, index + i + 4); - try { - int value = Integer.parseInt(unicode.toString(), 16); - out.write((char) value); - } catch (NumberFormatException nfe) { - throw new IllegalArgumentException("Unable to parse unicode value: " + unicode, nfe); - } - return i + 4; - } else { - throw new IllegalArgumentException("Less than 4 hex digits in unicode value: '" + - input.subSequence(index, input.length()) + - "' due to end of CharSequence"); + try { + int value = Integer.parseInt(unicode.toString(), 16); + out.write((char) value); + } catch (NumberFormatException nfe) { + throw new IllegalArgumentException("Unable to parse unicode value: " + unicode, nfe); } + return i + 4; + } else { + throw new IllegalArgumentException("Less than 4 hex digits in unicode value: '" + input.subSequence(index, input.length()) + + "' due to end of CharSequence"); } } return 0;