diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java index 6c24ff9d7..413a5dbfe 100644 --- a/src/java/org/apache/commons/lang/StringUtils.java +++ b/src/java/org/apache/commons/lang/StringUtils.java @@ -1204,9 +1204,8 @@ public static boolean containsAny(String str, char[] searchChars) { public static boolean containsAny(String str, String searchChars) { if (searchChars == null) { return false; - } else { - return containsAny(str, searchChars.toCharArray()); } + return containsAny(str, searchChars.toCharArray()); } // IndexOfAnyBut chars @@ -1665,9 +1664,8 @@ public static String left(String str, int len) { } if (str.length() <= len) { return str; - } else { - return str.substring(0, len); } + return str.substring(0, len); } /** @@ -1699,9 +1697,8 @@ public static String right(String str, int len) { } if (str.length() <= len) { return str; - } else { - return str.substring(str.length() - len); } + return str.substring(str.length() - len); } /** @@ -1740,9 +1737,8 @@ public static String mid(String str, int pos, int len) { } if (str.length() <= (pos + len)) { return str.substring(pos); - } else { - return str.substring(pos, pos + len); } + return str.substring(pos, pos + len); } // SubStringAfter/SubStringBefore @@ -2018,11 +2014,10 @@ public static String[] substringsBetween(String str, String open, String close) list.add(str.substring(start, end)); pos = end + closeLen; } - if (list.size() > 0) { - return (String[]) list.toArray(new String [list.size()]); - } else { + if (list.isEmpty()) { return null; - } + } + return (String[]) list.toArray(new String [list.size()]); } // Nested extraction @@ -2507,9 +2502,8 @@ private static String[] splitWorker(String str, char separatorChar, boolean pres } start = ++i; continue; - } else { - lastMatch = false; } + lastMatch = false; match = true; i++; } @@ -2642,9 +2636,8 @@ private static String[] splitWorker(String str, String separatorChars, int max, } start = ++i; continue; - } else { - lastMatch = false; } + lastMatch = false; match = true; i++; } @@ -2664,9 +2657,8 @@ private static String[] splitWorker(String str, String separatorChars, int max, } start = ++i; continue; - } else { - lastMatch = false; } + lastMatch = false; match = true; i++; } @@ -2685,9 +2677,8 @@ private static String[] splitWorker(String str, String separatorChars, int max, } start = ++i; continue; - } else { - lastMatch = false; } + lastMatch = false; match = true; i++; } @@ -3876,9 +3867,8 @@ public static String replaceChars(String str, String searchChars, String replace } if (modified) { return buf.toString(); - } else { - return str; } + return str; } // Overlay @@ -4013,9 +4003,8 @@ public static String chomp(String str) { char ch = str.charAt(0); if (ch == CharUtils.CR || ch == CharUtils.LF) { return EMPTY; - } else { - return str; } + return str; } int lastIdx = str.length() - 1; @@ -4098,9 +4087,8 @@ public static String chompLast(String str, String sep) { String sub = str.substring(str.length() - sep.length()); if (sep.equals(sub)) { return str.substring(0, str.length() - sep.length()); - } else { - return str; } + return str; } /** @@ -4139,11 +4127,10 @@ public static String getChomp(String str, String sep) { */ public static String prechomp(String str, String sep) { int idx = str.indexOf(sep); - if (idx != -1) { - return str.substring(idx + sep.length()); - } else { + if (idx == -1) { return str; - } + } + return str.substring(idx + sep.length()); } /** @@ -4160,11 +4147,10 @@ public static String prechomp(String str, String sep) { */ public static String getPrechomp(String str, String sep) { int idx = str.indexOf(sep); - if (idx != -1) { - return str.substring(0, idx + sep.length()); - } else { + if (idx == -1) { return EMPTY; - } + } + return str.substring(0, idx + sep.length()); } // Chopping @@ -5629,9 +5615,8 @@ public static int indexOfDifference(String[] strs) { // shortest string and didn't find a match, but the string lengths // vary, so return the length of the shortest string. return shortestStrLen; - } else { - return firstDiff; } + return firstDiff; } /** @@ -5676,9 +5661,8 @@ public static String getCommonPrefix(String[] strs) { // all strings were identical if (strs[0] == null) { return EMPTY; - } else { - return strs[0]; } + return strs[0]; } else if (smallestIndexOfDiff == 0) { // there were no common initial characters return EMPTY;