Simplify code paths where a statement is unnecessarily nested within an else clause. Also flip some if/else statements when tests can be expressed more clearly.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@619137 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2008-02-06 20:10:05 +00:00
parent db456f2f89
commit 004d7b3e8f
1 changed files with 22 additions and 38 deletions

View File

@ -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;