< prev index next >
src/java.base/share/classes/java/net/URLStreamHandler.java
Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD
@@ -233,11 +233,11 @@
throw new IllegalArgumentException("Invalid port number :" +
port);
start = i;
// If the authority is defined then the path is defined by the
// spec only; See RFC 2396 Section 5.2.4.
- if (authority != null && authority.length() > 0)
+ if (authority != null && !authority.isEmpty())
path = "";
}
if (host == null) {
host = "";
@@ -245,11 +245,11 @@
// Parse the file path if any
if (start < limit) {
if (spec.charAt(start) == '/') {
path = spec.substring(start, limit);
- } else if (path != null && path.length() > 0) {
+ } else if (path != null && !path.isEmpty()) {
isRelPath = true;
int ind = path.lastIndexOf('/');
String separator = "";
if (ind == -1 && authority != null)
separator = "/";
@@ -481,15 +481,15 @@
*/
protected String toExternalForm(URL u) {
String s;
return u.getProtocol()
+ ':'
- + (((s = u.getAuthority()) != null && s.length() > 0)
+ + ((s = u.getAuthority()) != null && !s.isEmpty()
? "//" + s : "")
- + (((s = u.getPath()) != null) ? s : "")
- + (((s = u.getQuery()) != null) ? '?' + s : "")
- + (((s = u.getRef()) != null) ? '#' + s : "");
+ + ((s = u.getPath()) != null ? s : "")
+ + ((s = u.getQuery()) != null ? '?' + s : "")
+ + ((s = u.getRef()) != null ? '#' + s : "");
}
/**
* Sets the fields of the {@code URL} argument to the indicated values.
* Only classes derived from URLStreamHandler are able
@@ -542,11 +542,11 @@
* Only old URL handlers call this, so assume that the host
* field might contain "user:passwd@host". Fix as necessary.
*/
String authority = null;
String userInfo = null;
- if (host != null && host.length() != 0) {
+ if (host != null && !host.isEmpty()) {
authority = (port == -1) ? host : host + ":" + port;
int at = host.lastIndexOf('@');
if (at != -1) {
userInfo = host.substring(0, at);
host = host.substring(at+1);
< prev index next >