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

@ -247,7 +247,7 @@ public final class Console implements Flushable
String line = null;
synchronized (writeLock) {
synchronized(readLock) {
if (fmt.length() != 0)
if (!fmt.isEmpty())
pw.format(fmt, args);
try {
char[] ca = readline(false);
@ -319,7 +319,7 @@ public final class Console implements Flushable
}
IOError ioe = null;
try {
if (fmt.length() != 0)
if (!fmt.isEmpty())
pw.format(fmt, args);
passwd = readline(true);
} catch (IOException x) {

View file

@ -1119,7 +1119,7 @@ public abstract class ClassLoader {
// true if the name is null or has the potential to be a valid binary name
private boolean checkName(String name) {
if ((name == null) || (name.length() == 0))
if ((name == null) || (name.isEmpty()))
return true;
if ((name.indexOf('/') != -1) || (name.charAt(0) == '['))
return false;

View file

@ -1409,7 +1409,7 @@ public final class Integer extends Number
boolean negative = false;
Integer result;
if (nm.length() == 0)
if (nm.isEmpty())
throw new NumberFormatException("Zero length string");
char firstChar = nm.charAt(0);
// Handle sign, if present

View file

@ -1248,7 +1248,7 @@ public final class Long extends Number
boolean negative = false;
Long result;
if (nm.length() == 0)
if (nm.isEmpty())
throw new NumberFormatException("Zero length string");
char firstChar = nm.charAt(0);
// Handle sign, if present

View file

@ -397,11 +397,11 @@ public class Package extends NamedPackage implements java.lang.reflect.Annotated
public String toString() {
String spec = versionInfo.specTitle;
String ver = versionInfo.specVersion;
if (spec != null && spec.length() > 0)
if (spec != null && !spec.isEmpty())
spec = ", " + spec;
else
spec = "";
if (ver != null && ver.length() > 0)
if (ver != null && !ver.isEmpty())
ver = ", version " + ver;
else
ver = "";

View file

@ -403,7 +403,7 @@ public class Runtime {
*/
public Process exec(String command, String[] envp, File dir)
throws IOException {
if (command.length() == 0)
if (command.isEmpty())
throw new IllegalArgumentException("Empty command");
StringTokenizer st = new StringTokenizer(command);

View file

@ -664,7 +664,7 @@ public final class String
* object.
*/
public int length() {
return value.length >> coder();
return isLatin1() ? value.length : value.length >> UTF16;
}
/**
@ -1943,8 +1943,7 @@ public final class String
* characters followed by the string argument's characters.
*/
public String concat(String str) {
int olen = str.length();
if (olen == 0) {
if (str.isEmpty()) {
return this;
}
if (coder() == str.coder()) {
@ -1956,6 +1955,7 @@ public final class String
return new String(buf, coder);
}
int len = length();
int olen = str.length();
byte[] buf = StringUTF16.newBytesFor(len + olen);
getBytes(buf, 0, UTF16);
str.getBytes(buf, len, UTF16);
@ -2316,7 +2316,7 @@ public final class String
// Construct result
int resultSize = list.size();
if (limit == 0) {
while (resultSize > 0 && list.get(resultSize - 1).length() == 0) {
while (resultSize > 0 && list.get(resultSize - 1).isEmpty()) {
resultSize--;
}
}

View file

@ -73,7 +73,7 @@ class VersionProps {
"@@VENDOR_VERSION_STRING@@";
private static final String vendor_version =
(VENDOR_VERSION_STRING.length() > 0
(!VENDOR_VERSION_STRING.isEmpty()
? " " + VENDOR_VERSION_STRING : "");
private static final String VENDOR =
@ -95,7 +95,7 @@ class VersionProps {
props.put("java.version.date", java_version_date);
props.put("java.runtime.version", java_runtime_version);
props.put("java.runtime.name", java_runtime_name);
if (VENDOR_VERSION_STRING.length() > 0)
if (!VENDOR_VERSION_STRING.isEmpty())
props.put("java.vendor.version", VENDOR_VERSION_STRING);
props.put("java.class.version", CLASSFILE_MAJOR_MINOR);

View file

@ -103,7 +103,7 @@ public final class ConstantBootstraps {
if (type != Class.class) {
throw new IllegalArgumentException();
}
if (name.length() == 0 || name.length() > 1) {
if (name.length() != 1) {
throw new IllegalArgumentException(String.format("not primitive: %s", name));
}

View file

@ -201,7 +201,7 @@ public class MethodHandles {
throw new IllegalAccessException(callerModule + " does not read " + targetModule);
if (targetModule.isNamed()) {
String pn = targetClass.getPackageName();
assert pn.length() > 0 : "unnamed package cannot be in named module";
assert !pn.isEmpty() : "unnamed package cannot be in named module";
if (!targetModule.isOpen(pn, callerModule))
throw new IllegalAccessException(targetModule + " does not open " + pn + " to " + callerModule);
}

View file

@ -62,7 +62,7 @@ final class ProxyClassesDumper {
}
try {
path = path.trim();
final Path dir = Path.of(path.length() == 0 ? "." : path);
final Path dir = Path.of(path.isEmpty() ? "." : path);
AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public Void run() {

View file

@ -149,7 +149,7 @@ public final class HttpCookie implements Cloneable {
*/
HttpCookie(String name, String value, String header, long creationTime) {
name = name.trim();
if (name.length() == 0 || !isToken(name) || name.charAt(0) == '$') {
if (name.isEmpty() || !isToken(name) || name.charAt(0) == '$') {
throw new IllegalArgumentException("Illegal cookie name");
}

View file

@ -433,7 +433,7 @@ class Inet6Address extends InetAddress {
NetworkInterface nif)
throws UnknownHostException
{
if (host != null && host.length() > 0 && host.charAt(0) == '[') {
if (host != null && !host.isEmpty() && host.charAt(0) == '[') {
if (host.charAt(host.length()-1) == ']') {
host = host.substring(1, host.length() -1);
}
@ -466,7 +466,7 @@ class Inet6Address extends InetAddress {
int scope_id)
throws UnknownHostException
{
if (host != null && host.length() > 0 && host.charAt(0) == '[') {
if (host != null && !host.isEmpty() && host.charAt(0) == '[') {
if (host.charAt(host.length()-1) == ']') {
host = host.substring(1, host.length() -1);
}
@ -601,7 +601,7 @@ class Inet6Address extends InetAddress {
boolean scope_ifname_set = gf.get("scope_ifname_set", false);
String ifname = (String)gf.get("ifname", null);
if (ifname != null && !"".equals (ifname)) {
if (ifname != null && !ifname.isEmpty()) {
try {
scope_ifname = NetworkInterface.getByName(ifname);
if (scope_ifname == null) {

View file

@ -1187,7 +1187,7 @@ class InetAddress implements java.io.Serializable {
*/
public static InetAddress getByAddress(String host, byte[] addr)
throws UnknownHostException {
if (host != null && host.length() > 0 && host.charAt(0) == '[') {
if (host != null && !host.isEmpty() && host.charAt(0) == '[') {
if (host.charAt(host.length()-1) == ']') {
host = host.substring(1, host.length() -1);
}
@ -1301,7 +1301,7 @@ class InetAddress implements java.io.Serializable {
private static InetAddress[] getAllByName(String host, InetAddress reqAddr)
throws UnknownHostException {
if (host == null || host.length() == 0) {
if (host == null || host.isEmpty()) {
InetAddress[] ret = new InetAddress[1];
ret[0] = impl.loopbackAddress();
return ret;

View file

@ -460,7 +460,7 @@ public final class SocketPermission extends Permission
}
return;
} else {
if (host.length() > 0) {
if (!host.isEmpty()) {
// see if we are being initialized with an IP address.
char ch = host.charAt(0);
if (ch == ':' || Character.digit(ch, 16) != -1) {
@ -705,8 +705,7 @@ public final class SocketPermission extends Permission
.orElse(b);
}
return cdomain.length() != 0 && hdomain.length() != 0
&& cdomain.equals(hdomain);
return !cdomain.isEmpty() && !hdomain.isEmpty() && cdomain.equals(hdomain);
}
private boolean authorized(String cname, byte[] addr) {

View file

@ -1959,10 +1959,8 @@ public final class URI
throws URISyntaxException
{
if (scheme != null) {
if ((path != null)
&& ((path.length() > 0) && (path.charAt(0) != '/')))
throw new URISyntaxException(s,
"Relative path in absolute URI");
if (path != null && !path.isEmpty() && path.charAt(0) != '/')
throw new URISyntaxException(s, "Relative path in absolute URI");
}
}
@ -2163,7 +2161,7 @@ public final class URI
ru.port = base.port;
String cp = (child.path == null) ? "" : child.path;
if ((cp.length() > 0) && (cp.charAt(0) == '/')) {
if (!cp.isEmpty() && cp.charAt(0) == '/') {
// 5.2 (5): Child path is absolute
ru.path = child.path;
} else {
@ -2187,7 +2185,7 @@ public final class URI
// o.w., return a new URI containing the normalized path.
//
private static URI normalize(URI u) {
if (u.isOpaque() || (u.path == null) || (u.path.length() == 0))
if (u.isOpaque() || u.path == null || u.path.isEmpty())
return u;
String np = normalize(u.path);

View file

@ -1513,7 +1513,7 @@ public final class URL implements java.io.Serializable {
String ref = (String)gf.get("ref", null);
int hashCode = gf.get("hashCode", -1);
if (authority == null
&& ((host != null && host.length() > 0) || port != -1)) {
&& ((host != null && !host.isEmpty()) || port != -1)) {
if (host == null)
host = "";
authority = (port == -1) ? host : host + ":" + port;
@ -1560,7 +1560,7 @@ public final class URL implements java.io.Serializable {
// Construct authority part
if (authority == null
&& ((host != null && host.length() > 0) || port != -1)) {
&& ((host != null && !host.isEmpty()) || port != -1)) {
if (host == null)
host = "";
authority = (port == -1) ? host : host + ":" + port;
@ -1716,7 +1716,7 @@ final class UrlDeserializedState {
// pre-compute length of StringBuffer
int len = protocol.length() + 1;
if (authority != null && authority.length() > 0)
if (authority != null && !authority.isEmpty())
len += 2 + authority.length();
if (file != null) {
len += file.length();
@ -1726,7 +1726,7 @@ final class UrlDeserializedState {
StringBuilder result = new StringBuilder(len);
result.append(protocol);
result.append(":");
if (authority != null && authority.length() > 0) {
if (authority != null && !authority.isEmpty()) {
result.append("//");
result.append(authority);
}

View file

@ -743,7 +743,7 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
locUrl = ((JarURLConnection)urlConnection).getJarFileURL();
}
String host = locUrl.getHost();
if (host != null && (host.length() > 0))
if (host != null && !host.isEmpty())
p = new SocketPermission(host,
SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION);
}

View file

@ -133,7 +133,7 @@ public class URLDecoder {
* @since 1.4
*/
public static String decode(String s, String enc) throws UnsupportedEncodingException {
if (enc.length() == 0) {
if (enc.isEmpty()) {
throw new UnsupportedEncodingException ("URLDecoder: empty string enc parameter");
}

View file

@ -409,7 +409,7 @@ public final class URLPermission extends Permission {
char c = methods.charAt(i);
if (c == ',') {
String s = b.toString();
if (s.length() > 0)
if (!s.isEmpty())
l.add(s);
b = new StringBuilder();
} else if (c == ' ' || c == '\t') {
@ -423,7 +423,7 @@ public final class URLPermission extends Permission {
}
}
String s = b.toString();
if (s.length() > 0)
if (!s.isEmpty())
l.add(s);
return l;
}
@ -448,7 +448,7 @@ public final class URLPermission extends Permission {
b.append(c);
} else if (c == ',') {
String s = b.toString();
if (s.length() > 0)
if (!s.isEmpty())
l.add(s);
b = new StringBuilder();
capitalizeNext = true;
@ -458,7 +458,7 @@ public final class URLPermission extends Permission {
}
}
String s = b.toString();
if (s.length() > 0)
if (!s.isEmpty())
l.add(s);
return l;
}

View file

@ -235,7 +235,7 @@ public abstract class URLStreamHandler {
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 = "";
}
@ -247,7 +247,7 @@ public abstract class URLStreamHandler {
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 = "";
@ -483,11 +483,11 @@ public abstract class URLStreamHandler {
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 : "");
}
/**
@ -544,7 +544,7 @@ public abstract class URLStreamHandler {
*/
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) {

View file

@ -104,7 +104,7 @@ public final class LinkPermission extends BasicPermission {
public LinkPermission(String name, String actions) {
super(name);
checkName(name);
if (actions != null && actions.length() > 0) {
if (actions != null && !actions.isEmpty()) {
throw new IllegalArgumentException("actions: " + actions);
}
}

View file

@ -228,7 +228,7 @@ public class AlgorithmParameterGenerator {
throws NoSuchAlgorithmException, NoSuchProviderException
{
Objects.requireNonNull(algorithm, "null algorithm name");
if (provider == null || provider.length() == 0)
if (provider == null || provider.isEmpty())
throw new IllegalArgumentException("missing provider");
Object[] objs = Security.getImpl(algorithm,
"AlgorithmParameterGenerator",

View file

@ -209,7 +209,7 @@ public class AlgorithmParameters {
throws NoSuchAlgorithmException, NoSuchProviderException
{
Objects.requireNonNull(algorithm, "null algorithm name");
if (provider == null || provider.length() == 0)
if (provider == null || provider.isEmpty())
throw new IllegalArgumentException("missing provider");
Object[] objs = Security.getImpl(algorithm, "AlgorithmParameters",
provider);

View file

@ -913,7 +913,7 @@ public class KeyStore {
throws KeyStoreException, NoSuchProviderException
{
Objects.requireNonNull(type, "null type name");
if (provider == null || provider.length() == 0)
if (provider == null || provider.isEmpty())
throw new IllegalArgumentException("missing provider");
try {
Object[] objs = Security.getImpl(type, "KeyStore", provider);

View file

@ -237,7 +237,7 @@ public abstract class MessageDigest extends MessageDigestSpi {
throws NoSuchAlgorithmException, NoSuchProviderException
{
Objects.requireNonNull(algorithm, "null algorithm name");
if (provider == null || provider.length() == 0)
if (provider == null || provider.isEmpty())
throw new IllegalArgumentException("missing provider");
Object[] objs = Security.getImpl(algorithm, "MessageDigest", provider);
if (objs[0] instanceof MessageDigest) {

View file

@ -222,7 +222,7 @@ public abstract class Permission implements Guard, java.io.Serializable {
*/
public String toString() {
String actions = getActions();
if ((actions == null) || (actions.length() == 0)) { // OPTIONAL
if (actions == null || actions.isEmpty()) { // OPTIONAL
return "(\"" + getClass().getName() + "\" \"" + name + "\")";
} else {
return "(\"" + getClass().getName() + "\" \"" + name +

View file

@ -456,7 +456,7 @@ public abstract class Policy {
throws NoSuchProviderException, NoSuchAlgorithmException {
Objects.requireNonNull(type, "null type name");
if (provider == null || provider.length() == 0) {
if (provider == null || provider.isEmpty()) {
throw new IllegalArgumentException("missing provider");
}

View file

@ -942,7 +942,7 @@ public class SecureRandom extends java.util.Random {
}
});
if ((property == null) || (property.length() == 0)) {
if (property == null || property.isEmpty()) {
throw new NoSuchAlgorithmException(
"Null/empty securerandom.strongAlgorithms Security Property");
}

View file

@ -649,7 +649,7 @@ public final class Security {
}
}
if ((candidates == null) || (candidates.isEmpty()))
if (candidates == null || candidates.isEmpty())
return null;
Object[] candidatesArray = candidates.toArray();
@ -1005,11 +1005,11 @@ public final class Security {
String algName = null;
String attrName = null;
if (filterValue.length() == 0) {
if (filterValue.isEmpty()) {
// The filterValue is an empty string. So the filterKey
// should be in the format of <crypto_service>.<algorithm_or_type>.
algName = filterKey.substring(algIndex + 1).trim();
if (algName.length() == 0) {
if (algName.isEmpty()) {
// There must be a algorithm or type name.
throw new InvalidParameterException("Invalid filter");
}
@ -1024,7 +1024,7 @@ public final class Security {
throw new InvalidParameterException("Invalid filter");
} else {
attrName = filterKey.substring(attrIndex + 1).trim();
if (attrName.length() == 0) {
if (attrName.isEmpty()) {
// There is no attribute name in the filter.
throw new InvalidParameterException("Invalid filter");
}
@ -1070,7 +1070,7 @@ public final class Security {
**/
public static Set<String> getAlgorithms(String serviceName) {
if ((serviceName == null) || (serviceName.length() == 0) ||
if ((serviceName == null) || (serviceName.isEmpty()) ||
(serviceName.endsWith("."))) {
return Collections.emptySet();
}

View file

@ -360,7 +360,7 @@ public abstract class Signature extends SignatureSpi {
Objects.requireNonNull(algorithm, "null algorithm name");
if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
// exception compatibility with existing code
if ((provider == null) || (provider.length() == 0)) {
if (provider == null || provider.isEmpty()) {
throw new IllegalArgumentException("missing provider");
}
Provider p = Security.getProvider(provider);

View file

@ -210,7 +210,7 @@ public class TrustAnchor {
if (caName == null)
throw new NullPointerException("the caName parameter must be " +
"non-null");
if (caName.length() == 0)
if (caName.isEmpty())
throw new IllegalArgumentException("the caName " +
"parameter must be a non-empty String");
// check if caName is formatted correctly

View file

@ -85,7 +85,7 @@ public class AttributedString {
text = buffer.toString();
if (text.length() > 0) {
if (!text.isEmpty()) {
// Determine the runs, creating a new run when the attributes
// differ.
int offset = 0;
@ -144,7 +144,7 @@ public class AttributedString {
}
this.text = text;
if (text.length() == 0) {
if (text.isEmpty()) {
if (attributes.isEmpty())
return;
throw new IllegalArgumentException("Can't add attribute to 0-length text");

View file

@ -125,7 +125,7 @@ public final class CollationElementIterator
CollationElementIterator(String sourceText, RuleBasedCollator owner) {
this.owner = owner;
ordering = owner.getTables();
if ( sourceText.length() != 0 ) {
if (!sourceText.isEmpty()) {
NormalizerBase.Mode mode =
CollatorUtilities.toNormalizerMode(owner.getDecomposition());
text = new NormalizerBase(sourceText, mode);

View file

@ -799,7 +799,7 @@ public final class CompactNumberFormat extends NumberFormat {
*/
private void append(StringBuffer result, String string,
FieldDelegate delegate, List<FieldPosition> positions) {
if (string.length() > 0) {
if (!string.isEmpty()) {
int start = result.length();
result.append(string);
for (int counter = 0; counter < positions.size(); counter++) {
@ -1213,7 +1213,7 @@ public final class CompactNumberFormat extends NumberFormat {
}
// If no 0s are specified in a non empty pattern, it is invalid
if (pattern.length() != 0 && zeros.isEmpty()) {
if (!pattern.isEmpty() && zeros.isEmpty()) {
throw new IllegalArgumentException("Invalid pattern"
+ " [" + pattern + "]: all patterns must include digit"
+ " placement 0s");

View file

@ -1113,11 +1113,9 @@ public class DecimalFormat extends NumberFormat {
// Records the need for adding prefix or suffix
fastPathData.positiveAffixesRequired
= (positivePrefix.length() != 0)
|| (positiveSuffix.length() != 0);
= !positivePrefix.isEmpty() || !positiveSuffix.isEmpty();
fastPathData.negativeAffixesRequired
= (negativePrefix.length() != 0)
|| (negativeSuffix.length() != 0);
= !negativePrefix.isEmpty() || !negativeSuffix.isEmpty();
// Creates a cached char container for result, with max possible size.
int maxNbIntegralDigits = 10;
@ -2062,7 +2060,7 @@ public class DecimalFormat extends NumberFormat {
Format.Field signAttribute) {
int start = result.length();
if (string.length() > 0) {
if (!string.isEmpty()) {
result.append(string);
for (int counter = 0, max = positions.length; counter < max;
counter++) {
@ -3042,7 +3040,7 @@ public class DecimalFormat extends NumberFormat {
} else {
string = symbols.getCurrencySymbol();
}
if (string.length() > 0) {
if (!string.isEmpty()) {
if (positions == null) {
positions = new ArrayList<>(2);
}
@ -3613,7 +3611,7 @@ public class DecimalFormat extends NumberFormat {
}
}
if (pattern.length() == 0) {
if (pattern.isEmpty()) {
posPrefixPattern = posSuffixPattern = "";
setMinimumIntegerDigits(0);
setMaximumIntegerDigits(MAXIMUM_INTEGER_DIGITS);

View file

@ -663,7 +663,7 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
// Check for empty country string separately because it's a valid
// country ID for Locale (and used for the C locale), but not a valid
// ISO 3166 country code, and exceptions are expensive.
if (locale.getCountry().length() > 0) {
if (!locale.getCountry().isEmpty()) {
try {
currency = Currency.getInstance(locale);
} catch (IllegalArgumentException e) {

View file

@ -92,7 +92,7 @@ final class MergeCollation {
int i;
for (i = 0; i < patterns.size(); ++i) {
PatternEntry entry = patterns.get(i);
if (entry.extension.length() != 0) {
if (!entry.extension.isEmpty()) {
if (extList == null)
extList = new ArrayList<>();
extList.add(entry);
@ -122,7 +122,7 @@ final class MergeCollation {
private final PatternEntry findLastWithNoExtension(int i) {
for (--i;i >= 0; --i) {
PatternEntry entry = patterns.get(i);
if (entry.extension.length() == 0) {
if (entry.extension.isEmpty()) {
return entry;
}
}

View file

@ -1330,7 +1330,7 @@ public class MessageFormat extends Format {
}
arg = null;
}
if (arg != null && arg.length() > 0) {
if (arg != null && !arg.isEmpty()) {
result.append(arg);
characterIterators.add(
createAttributedCharacterIterator(
@ -1476,7 +1476,7 @@ public class MessageFormat extends Format {
// now get the format
Format newFormat = null;
if (segments[SEG_TYPE].length() != 0) {
if (!segments[SEG_TYPE].isEmpty()) {
int type = findKeyword(segments[SEG_TYPE], TYPE_KEYWORDS);
switch (type) {
case TYPE_NULL:

View file

@ -141,7 +141,7 @@ class PatternEntry {
if (showWhiteSpace)
toAddTo.append(' ');
appendQuoted(chars,toAddTo);
if (showExtension && extension.length() != 0) {
if (showExtension && !extension.isEmpty()) {
toAddTo.append('/');
appendQuoted(extension,toAddTo);
}

View file

@ -75,13 +75,10 @@ final class RBTableBuilder {
* @exception ParseException If the rules format is incorrect.
*/
public void build(String pattern, int decmp) throws ParseException
{
boolean isSource = true;
int i = 0;
public void build(String pattern, int decmp) throws ParseException {
String expChars;
String groupChars;
if (pattern.length() == 0)
if (pattern.isEmpty())
throw new ParseException("Build rules empty.", 0);
// This array maps Unicode characters to their collation ordering
@ -119,8 +116,7 @@ final class RBTableBuilder {
int order = 0;
// Now walk though each entry and add it to my own tables
for (i = 0; i < mPattern.getCount(); ++i)
{
for (int i = 0; i < mPattern.getCount(); ++i) {
PatternEntry entry = mPattern.getItemAt(i);
if (entry != null) {
groupChars = entry.getChars();
@ -140,7 +136,7 @@ final class RBTableBuilder {
order = increment(entry.getStrength(), order);
expChars = entry.getExtension();
if (expChars.length() != 0) {
if (!expChars.isEmpty()) {
addExpandOrder(groupChars, expChars, order);
} else if (groupChars.length() > 1) {
char ch = groupChars.charAt(0);

View file

@ -372,7 +372,7 @@ public abstract class ZoneId implements Serializable {
public static ZoneId ofOffset(String prefix, ZoneOffset offset) {
Objects.requireNonNull(prefix, "prefix");
Objects.requireNonNull(offset, "offset");
if (prefix.length() == 0) {
if (prefix.isEmpty()) {
return offset;
}

View file

@ -1439,7 +1439,7 @@ public final class DateTimeFormatterBuilder {
*/
public DateTimeFormatterBuilder appendLiteral(String literal) {
Objects.requireNonNull(literal, "literal");
if (literal.length() > 0) {
if (!literal.isEmpty()) {
if (literal.length() == 1) {
appendInternal(new CharLiteralPrinterParser(literal.charAt(0)));
} else {
@ -1832,7 +1832,7 @@ public final class DateTimeFormatterBuilder {
throw new IllegalArgumentException("Pattern ends with an incomplete string literal: " + pattern);
}
String str = pattern.substring(start + 1, pos);
if (str.length() == 0) {
if (str.isEmpty()) {
appendLiteral('\'');
} else {
appendLiteral(str.replace("''", "'"));
@ -4332,7 +4332,7 @@ public final class DateTimeFormatterBuilder {
this.key = k;
this.value = v;
this.child = child;
if (k.length() == 0){
if (k.isEmpty()) {
c0 = 0xffff;
} else {
c0 = key.charAt(0);

View file

@ -2232,7 +2232,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
if (strings != null) {
Map<String,Integer> names = new HashMap<>();
for (int i = 0; i < strings.length; i++) {
if (strings[i].length() == 0) {
if (strings[i].isEmpty()) {
continue;
}
names.put(strings[i], i);

View file

@ -1396,11 +1396,11 @@ public final class Locale implements Cloneable, Serializable {
*/
@Override
public final String toString() {
boolean l = (baseLocale.getLanguage().length() != 0);
boolean s = (baseLocale.getScript().length() != 0);
boolean r = (baseLocale.getRegion().length() != 0);
boolean v = (baseLocale.getVariant().length() != 0);
boolean e = (localeExtensions != null && localeExtensions.getID().length() != 0);
boolean l = !baseLocale.getLanguage().isEmpty();
boolean s = !baseLocale.getScript().isEmpty();
boolean r = !baseLocale.getRegion().isEmpty();
boolean v = !baseLocale.getVariant().isEmpty();
boolean e = localeExtensions != null && !localeExtensions.getID().isEmpty();
StringBuilder result = new StringBuilder(baseLocale.getLanguage());
if (r || (l && (v || s || e))) {
@ -1504,18 +1504,18 @@ public final class Locale implements Cloneable, Serializable {
StringBuilder buf = new StringBuilder();
String subtag = tag.getLanguage();
if (subtag.length() > 0) {
if (!subtag.isEmpty()) {
buf.append(LanguageTag.canonicalizeLanguage(subtag));
}
subtag = tag.getScript();
if (subtag.length() > 0) {
if (!subtag.isEmpty()) {
buf.append(LanguageTag.SEP);
buf.append(LanguageTag.canonicalizeScript(subtag));
}
subtag = tag.getRegion();
if (subtag.length() > 0) {
if (!subtag.isEmpty()) {
buf.append(LanguageTag.SEP);
buf.append(LanguageTag.canonicalizeRegion(subtag));
}
@ -1534,7 +1534,7 @@ public final class Locale implements Cloneable, Serializable {
}
subtag = tag.getPrivateuse();
if (subtag.length() > 0) {
if (!subtag.isEmpty()) {
if (buf.length() > 0) {
buf.append(LanguageTag.SEP);
}
@ -1684,7 +1684,7 @@ public final class Locale implements Cloneable, Serializable {
bldr.setLanguageTag(tag);
BaseLocale base = bldr.getBaseLocale();
LocaleExtensions exts = bldr.getLocaleExtensions();
if (exts == null && base.getVariant().length() > 0) {
if (exts == null && !base.getVariant().isEmpty()) {
exts = getCompatibilityExtensions(base.getLanguage(), base.getScript(),
base.getRegion(), base.getVariant());
}
@ -1917,7 +1917,7 @@ public final class Locale implements Cloneable, Serializable {
* @exception NullPointerException if <code>inLocale</code> is <code>null</code>
*/
public String getDisplayVariant(Locale inLocale) {
if (baseLocale.getVariant().length() == 0)
if (baseLocale.getVariant().isEmpty())
return "";
LocaleResources lr = LocaleProviderAdapter
@ -1998,14 +1998,14 @@ public final class Locale implements Cloneable, Serializable {
// The display name consists of a main name, followed by qualifiers.
// Typically, the format is "MainName (Qualifier, Qualifier)" but this
// depends on what pattern is stored in the display locale.
String mainName = null;
String[] qualifierNames = null;
String mainName;
String[] qualifierNames;
// The main name is the language, or if there is no language, the script,
// then if no script, the country. If there is no language/script/country
// (an anomalous situation) then the display name is simply the variant's
// display name.
if (languageName.length() == 0 && scriptName.length() == 0 && countryName.length() == 0) {
if (languageName.isEmpty() && scriptName.isEmpty() && countryName.isEmpty()) {
if (variantNames.length == 0) {
return "";
} else {
@ -2013,13 +2013,13 @@ public final class Locale implements Cloneable, Serializable {
}
}
ArrayList<String> names = new ArrayList<>(4);
if (languageName.length() != 0) {
if (!languageName.isEmpty()) {
names.add(languageName);
}
if (scriptName.length() != 0) {
if (!scriptName.isEmpty()) {
names.add(scriptName);
}
if (countryName.length() != 0) {
if (!countryName.isEmpty()) {
names.add(countryName);
}
if (variantNames.length != 0) {
@ -2309,7 +2309,7 @@ public final class Locale implements Cloneable, Serializable {
String variant = (String)fields.get("variant", "");
String extStr = (String)fields.get("extensions", "");
baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant);
if (extStr.length() > 0) {
if (!extStr.isEmpty()) {
try {
InternalLocaleBuilder bldr = new InternalLocaleBuilder();
bldr.setExtensions(extStr);
@ -2367,13 +2367,13 @@ public final class Locale implements Cloneable, Serializable {
LocaleExtensions extensions = null;
// Special cases for backward compatibility support
if (LocaleUtils.caseIgnoreMatch(language, "ja")
&& script.length() == 0
&& script.isEmpty()
&& LocaleUtils.caseIgnoreMatch(country, "jp")
&& "JP".equals(variant)) {
// ja_JP_JP -> u-ca-japanese (calendar = japanese)
extensions = LocaleExtensions.CALENDAR_JAPANESE;
} else if (LocaleUtils.caseIgnoreMatch(language, "th")
&& script.length() == 0
&& script.isEmpty()
&& LocaleUtils.caseIgnoreMatch(country, "th")
&& "TH".equals(variant)) {
// th_TH_TH -> u-nu-thai (numbersystem = thai)
@ -2806,7 +2806,7 @@ public final class Locale implements Cloneable, Serializable {
public Locale build() {
BaseLocale baseloc = localeBuilder.getBaseLocale();
LocaleExtensions extensions = localeBuilder.getLocaleExtensions();
if (extensions == null && baseloc.getVariant().length() > 0) {
if (extensions == null && !baseloc.getVariant().isEmpty()) {
extensions = getCompatibilityExtensions(baseloc.getLanguage(), baseloc.getScript(),
baseloc.getRegion(), baseloc.getVariant());
}

View file

@ -771,8 +771,8 @@ public abstract class ResourceBundle {
@Override
public String toString() {
String l = locale.toString();
if (l.length() == 0) {
if (locale.getVariant().length() != 0) {
if (l.isEmpty()) {
if (!locale.getVariant().isEmpty()) {
l = "__" + locale.getVariant();
} else {
l = "\"\"";
@ -2903,7 +2903,7 @@ public abstract class ResourceBundle {
List<Locale> bokmalList = new LinkedList<>();
for (Locale l : tmpList) {
bokmalList.add(l);
if (l.getLanguage().length() == 0) {
if (l.getLanguage().isEmpty()) {
break;
}
bokmalList.add(Locale.getInstance("no", l.getScript(), l.getCountry(),
@ -2921,7 +2921,7 @@ public abstract class ResourceBundle {
}
// Special handling for Chinese
else if (language.equals("zh")) {
if (script.length() == 0 && region.length() > 0) {
if (script.isEmpty() && !region.isEmpty()) {
// Supply script for users who want to use zh_Hans/zh_Hant
// as bundle names (recommended for Java7+)
switch (region) {
@ -2944,7 +2944,7 @@ public abstract class ResourceBundle {
private static List<Locale> getDefaultList(String language, String script, String region, String variant) {
List<String> variants = null;
if (variant.length() > 0) {
if (!variant.isEmpty()) {
variants = new LinkedList<>();
int idx = variant.length();
while (idx != -1) {
@ -2960,14 +2960,14 @@ public abstract class ResourceBundle {
list.add(Locale.getInstance(language, script, region, v, null));
}
}
if (region.length() > 0) {
if (!region.isEmpty()) {
list.add(Locale.getInstance(language, script, region, "", null));
}
if (script.length() > 0) {
if (!script.isEmpty()) {
list.add(Locale.getInstance(language, script, "", "", null));
// Special handling for Chinese
if (language.equals("zh")) {
if (region.length() == 0) {
if (region.isEmpty()) {
// Supply region(country) for users who still package Chinese
// bundles using old convension.
switch (script) {
@ -2988,11 +2988,11 @@ public abstract class ResourceBundle {
list.add(Locale.getInstance(language, "", region, v, null));
}
}
if (region.length() > 0) {
if (!region.isEmpty()) {
list.add(Locale.getInstance(language, "", region, "", null));
}
}
if (language.length() > 0) {
if (!language.isEmpty()) {
list.add(Locale.getInstance(language, "", "", "", null));
}
// Add root locale at the end

View file

@ -1297,16 +1297,16 @@ public final class Scanner implements Iterator<String>, Closeable {
nanString = "\\Q" + dfs.getNaN() + "\\E";
infinityString = "\\Q" + dfs.getInfinity() + "\\E";
positivePrefix = df.getPositivePrefix();
if (positivePrefix.length() > 0)
if (!positivePrefix.isEmpty())
positivePrefix = "\\Q" + positivePrefix + "\\E";
negativePrefix = df.getNegativePrefix();
if (negativePrefix.length() > 0)
if (!negativePrefix.isEmpty())
negativePrefix = "\\Q" + negativePrefix + "\\E";
positiveSuffix = df.getPositiveSuffix();
if (positiveSuffix.length() > 0)
if (!positiveSuffix.isEmpty())
positiveSuffix = "\\Q" + positiveSuffix + "\\E";
negativeSuffix = df.getNegativeSuffix();
if (negativeSuffix.length() > 0)
if (!negativeSuffix.isEmpty())
negativeSuffix = "\\Q" + negativeSuffix + "\\E";
// Force rebuilding and recompilation of locale dependent

View file

@ -1390,7 +1390,7 @@ public final class Pattern
localTCNCount = 0;
// if length > 0, the Pattern is lazily compiled
if (pattern.length() == 0) {
if (pattern.isEmpty()) {
root = new Start(lastAccept);
matchRoot = lastAccept;
compiled = true;
@ -1423,7 +1423,7 @@ public final class Pattern
localCount = 0;
localTCNCount = 0;
if (pattern.length() > 0) {
if (!pattern.isEmpty()) {
compile();
} else {
root = new Start(lastAccept);