8215281: Use String.isEmpty() when applicable in java.base

Reviewed-by: dfuchs, alanb
This commit is contained in:
Claes Redestad 2018-12-13 15:31:05 +01:00
parent c998ead188
commit a3df1d618e
155 changed files with 340 additions and 382 deletions

View file

@ -98,7 +98,7 @@ class UnixFileSystem extends FileSystem {
}
public int prefixLength(String pathname) {
if (pathname.length() == 0) return 0;
if (pathname.isEmpty()) return 0;
return (pathname.charAt(0) == '/') ? 1 : 0;
}
@ -249,7 +249,7 @@ class UnixFileSystem extends FileSystem {
public int getBooleanAttributes(File f) {
int rv = getBooleanAttributes0(f);
String name = f.getName();
boolean hidden = (name.length() > 0) && (name.charAt(0) == '.');
boolean hidden = !name.isEmpty() && name.charAt(0) == '.';
return rv | (hidden ? BA_HIDDEN : 0);
}

View file

@ -59,9 +59,9 @@ public class FileURLMapper {
return path;
}
String host = url.getHost();
if (host == null || "".equals(host) || "localhost".equalsIgnoreCase (host)) {
if (host == null || host.isEmpty() || "localhost".equalsIgnoreCase(host)) {
path = url.getFile();
path = ParseUtil.decode (path);
path = ParseUtil.decode(path);
}
return path;
}

View file

@ -68,14 +68,14 @@ public class ResolverConfigurationImpl
String line;
while ((line = in.readLine()) != null) {
int maxvalues = maxperkeyword;
if (line.length() == 0)
if (line.isEmpty())
continue;
if (line.charAt(0) == '#' || line.charAt(0) == ';')
continue;
if (!line.startsWith(keyword))
continue;
String value = line.substring(keyword.length());
if (value.length() == 0)
if (value.isEmpty())
continue;
if (value.charAt(0) != ' ' && value.charAt(0) != '\t')
continue;
@ -181,7 +181,7 @@ public class ResolverConfigurationImpl
// LOCALDOMAIN has absolute priority on Solaris
String localDomain = localDomain0();
if (localDomain != null && localDomain.length() > 0) {
if (localDomain != null && !localDomain.isEmpty()) {
sl = new LinkedList<>();
sl.add(localDomain);
return sl;
@ -211,7 +211,7 @@ public class ResolverConfigurationImpl
sl = new LinkedList<>();
String domain = fallbackDomain0();
if (domain != null && domain.length() > 0) {
if (domain != null && !domain.isEmpty()) {
sl.add(domain);
}

View file

@ -77,7 +77,7 @@ public class SdpProvider extends NetHooks.Provider {
String logfile = props.getProperty("com.sun.sdp.debug");
if (logfile != null) {
out = System.out;
if (logfile.length() > 0) {
if (!logfile.isEmpty()) {
try {
out = new PrintStream(logfile);
} catch (IOException ignore) { }
@ -167,9 +167,9 @@ public class SdpProvider extends NetHooks.Provider {
result[1] = all ? MAX_PORT : result[0];
} else {
String low = s.substring(0, pos);
if (low.length() == 0) low = "*";
if (low.isEmpty()) low = "*";
String high = s.substring(pos+1);
if (high.length() == 0) high = "*";
if (high.isEmpty()) high = "*";
result[0] = low.equals("*") ? 0 : Integer.parseInt(low);
result[1] = high.equals("*") ? MAX_PORT : Integer.parseInt(high);
}
@ -199,7 +199,7 @@ public class SdpProvider extends NetHooks.Provider {
String line = scanner.nextLine().trim();
// skip blank lines and comments
if (line.length() == 0 || line.charAt(0) == '#')
if (line.isEmpty() || line.charAt(0) == '#')
continue;
// must have 3 fields

View file

@ -127,9 +127,9 @@ public class Handler extends URLStreamHandler {
*/
String s1 = u1.getHost();
String s2 = u2.getHost();
if ("localhost".equalsIgnoreCase(s1) && ( s2 == null || "".equals(s2)))
if ("localhost".equalsIgnoreCase(s1) && (s2 == null || s2.isEmpty()))
return true;
if ("localhost".equalsIgnoreCase(s2) && ( s1 == null || "".equals(s1)))
if ("localhost".equalsIgnoreCase(s2) && (s1 == null || s1.isEmpty()))
return true;
return super.hostsEqual(u1, u2);
}

View file

@ -49,8 +49,8 @@ class UnixAsynchronousSocketChannelImpl
static {
String propValue = GetPropertyAction.privilegedGetProperty(
"sun.nio.ch.disableSynchronousRead", "false");
disableSynchronousRead = (propValue.length() == 0) ?
true : Boolean.valueOf(propValue);
disableSynchronousRead = propValue.isEmpty() ?
true : Boolean.parseBoolean(propValue);
}
private final Port port;

View file

@ -58,8 +58,7 @@ abstract class UnixFileSystem
// default directory.
String propValue = GetPropertyAction
.privilegedGetProperty("sun.nio.fs.chdirAllowed", "false");
boolean chdirAllowed = (propValue.length() == 0) ?
true : Boolean.valueOf(propValue);
boolean chdirAllowed = propValue.isEmpty() ? true : Boolean.parseBoolean(propValue);
if (chdirAllowed) {
this.needToResolveAgainstDefaultDirectory = true;
} else {
@ -269,7 +268,7 @@ abstract class UnixFileSystem
StringBuilder sb = new StringBuilder();
sb.append(first);
for (String segment: more) {
if (segment.length() > 0) {
if (!segment.isEmpty()) {
if (sb.length() > 0)
sb.append('/');
sb.append(segment);