Author: britter Date: Fri Dec 26 12:33:35 2014 New Revision: 1647964 URL: http://svn.apache.org/r1647964 Log: PMD: Combine nested if statements
Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/UrlValidator.java commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java?rev=1647964&r1=1647963&r2=1647964&view=diff ============================================================================== --- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java (original) +++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java Fri Dec 26 12:33:35 2014 @@ -82,11 +82,10 @@ public class GenericTypeValidator implem Number num = formatter.parse(value, pos); // If there was no error and we used the whole string - if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { - if (num.doubleValue() >= Byte.MIN_VALUE && - num.doubleValue() <= Byte.MAX_VALUE) { - result = new Byte(num.byteValue()); - } + if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length() && + num.doubleValue() >= Byte.MIN_VALUE && + num.doubleValue() <= Byte.MAX_VALUE) { + result = new Byte(num.byteValue()); } } @@ -135,11 +134,10 @@ public class GenericTypeValidator implem Number num = formatter.parse(value, pos); // If there was no error and we used the whole string - if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { - if (num.doubleValue() >= Short.MIN_VALUE && - num.doubleValue() <= Short.MAX_VALUE) { - result = new Short(num.shortValue()); - } + if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length() && + num.doubleValue() >= Short.MIN_VALUE && + num.doubleValue() <= Short.MAX_VALUE) { + result = new Short(num.shortValue()); } } @@ -188,11 +186,10 @@ public class GenericTypeValidator implem Number num = formatter.parse(value, pos); // If there was no error and we used the whole string - if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { - if (num.doubleValue() >= Integer.MIN_VALUE && - num.doubleValue() <= Integer.MAX_VALUE) { - result = new Integer(num.intValue()); - } + if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length() && + num.doubleValue() >= Integer.MIN_VALUE && + num.doubleValue() <= Integer.MAX_VALUE) { + result = new Integer(num.intValue()); } } @@ -241,11 +238,10 @@ public class GenericTypeValidator implem Number num = formatter.parse(value, pos); // If there was no error and we used the whole string - if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { - if (num.doubleValue() >= Long.MIN_VALUE && - num.doubleValue() <= Long.MAX_VALUE) { - result = new Long(num.longValue()); - } + if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length() && + num.doubleValue() >= Long.MIN_VALUE && + num.doubleValue() <= Long.MAX_VALUE) { + result = new Long(num.longValue()); } } @@ -293,11 +289,10 @@ public class GenericTypeValidator implem Number num = formatter.parse(value, pos); // If there was no error and we used the whole string - if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { - if (num.doubleValue() >= (Float.MAX_VALUE * -1) && - num.doubleValue() <= Float.MAX_VALUE) { - result = new Float(num.floatValue()); - } + if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length() && + num.doubleValue() >= (Float.MAX_VALUE * -1) && + num.doubleValue() <= Float.MAX_VALUE) { + result = new Float(num.floatValue()); } } @@ -345,11 +340,10 @@ public class GenericTypeValidator implem Number num = formatter.parse(value, pos); // If there was no error and we used the whole string - if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { - if (num.doubleValue() >= (Double.MAX_VALUE * -1) && - num.doubleValue() <= Double.MAX_VALUE) { - result = new Double(num.doubleValue()); - } + if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length() && + num.doubleValue() >= (Double.MAX_VALUE * -1) && + num.doubleValue() <= Double.MAX_VALUE) { + result = new Double(num.doubleValue()); } } @@ -447,10 +441,8 @@ public class GenericTypeValidator implem date = formatter.parse(value); - if (strict) { - if (datePattern.length() != value.length()) { - date = null; - } + if (strict && datePattern.length() != value.length()) { + date = null; } } catch (ParseException e) { // Bad date so return null Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/UrlValidator.java URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/UrlValidator.java?rev=1647964&r1=1647963&r2=1647964&view=diff ============================================================================== --- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/UrlValidator.java (original) +++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/UrlValidator.java Fri Dec 26 12:33:35 2014 @@ -293,11 +293,8 @@ public class UrlValidator implements Ser return false; } - if (options.isOff(ALLOW_ALL_SCHEMES)) { - - if (!allowedSchemes.contains(scheme)) { - return false; - } + if (options.isOff(ALLOW_ALL_SCHEMES) && !allowedSchemes.contains(scheme)) { + return false; } return true; @@ -383,10 +380,8 @@ public class UrlValidator implements Ser } String port = authorityMatcher.group(PARSE_AUTHORITY_PORT); - if (port != null) { - if (!PORT_PATTERN.matcher(port).matches()) { - return false; - } + if (port != null && !PORT_PATTERN.matcher(port).matches()) { + return false; } String extra = authorityMatcher.group(PARSE_AUTHORITY_EXTRA); @@ -418,10 +413,8 @@ public class UrlValidator implements Ser int slashCount = countToken("/", path); int dot2Count = countToken("..", path); - if (dot2Count > 0) { - if ((slashCount - slash2Count - 1) <= dot2Count) { - return false; - } + if (dot2Count > 0 && (slashCount - slash2Count - 1) <= dot2Count){ + return false; } return true; Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java?rev=1647964&r1=1647963&r2=1647964&view=diff ============================================================================== --- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java (original) +++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java Fri Dec 26 12:33:35 2014 @@ -132,12 +132,9 @@ public class DomainValidator implements String[] groups = domainRegex.match(domain); if (groups != null && groups.length > 0) { return isValidTld(groups[0]); - } else if(allowLocal) { - if (hostnameRegex.isValid(domain)) { - return true; - } + } else { + return allowLocal && hostnameRegex.isValid(domain); } - return false; } /**