8274190: Use String.equals instead of String.compareTo in jdk.internal.jvmstat

Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
Andrey Turbanov 2021-11-16 11:15:52 +00:00 committed by Serguei Spitsyn
parent a9cb8bdbaa
commit 0bc268377e
7 changed files with 15 additions and 18 deletions
src/jdk.internal.jvmstat/share/classes/sun/jvmstat

@ -106,7 +106,7 @@ public class HostIdentifier {
* by the string.
*/
private URI canonicalize(String uriString) throws URISyntaxException {
if ((uriString == null) || (uriString.compareTo("localhost") == 0)) {
if (uriString == null || uriString.equals("localhost")) {
uriString = "//localhost";
return new URI(uriString);
}
@ -247,7 +247,7 @@ public class HostIdentifier {
String authority = vmid.getAuthority();
// check for 'file:' VmIdentifiers and handled as a special case.
if ((scheme != null) && (scheme.compareTo("file") == 0)) {
if ("file".equals(scheme)) {
try {
uri = new URI("file://localhost");
} catch (URISyntaxException e) { };
@ -343,7 +343,7 @@ public class HostIdentifier {
String host = vmid.getHost();
String authority = vmid.getAuthority();
if ((scheme != null) && (scheme.compareTo("file") == 0)) {
if ("file".equals(scheme)) {
// don't attempt to resolve a file based VmIdentifier.
return vmid;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -203,7 +203,7 @@ public abstract class MonitoredHost {
assert hostname != null;
if (scheme == null) {
if (hostname.compareTo("localhost") == 0) {
if (hostname.equals("localhost")) {
scheme = LOCAL_PROTOCOL;
} else {
scheme = REMOTE_PROTOCOL;

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -82,7 +82,7 @@ public class MonitoredVmUtil {
int firstSpace = commandLine.indexOf(' ');
if (firstSpace > 0) {
return commandLine.substring(firstSpace + 1);
} else if (commandLine.compareTo("Unknown") == 0) {
} else if (commandLine.equals("Unknown")) {
return commandLine;
} else {
return null;

@ -174,7 +174,7 @@ public class VmIdentifier {
private void validate() throws URISyntaxException {
// file:// uri, which is a special case where the lvmid is not required.
String s = getScheme();
if ((s != null) && (s.compareTo("file") == 0)) {
if ("file".equals(s)) {
return;
}
if (getLocalVmId() == -1) {

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,6 @@ package sun.jvmstat.perfdata.monitor;
import java.net.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
/**
* Class for parsing alias files. File format is expected to follow
@ -127,7 +126,7 @@ public class AliasFileParser {
while (currentToken.ttype != StreamTokenizer.TT_EOF) {
// look for the start symbol
if ((currentToken.ttype != StreamTokenizer.TT_WORD)
|| (currentToken.sval.compareTo(ALIAS) != 0)) {
|| !currentToken.sval.equals(ALIAS)) {
nextToken();
continue;
}
@ -143,7 +142,7 @@ public class AliasFileParser {
match(StreamTokenizer.TT_WORD);
} while ((currentToken.ttype != StreamTokenizer.TT_EOF)
&& (currentToken.sval.compareTo(ALIAS) != 0));
&& !currentToken.sval.equals(ALIAS));
map.put(name, aliases);
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,6 @@ package sun.jvmstat.perfdata.monitor.protocol.file;
import sun.jvmstat.monitor.*;
import sun.jvmstat.perfdata.monitor.*;
import java.io.*;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
@ -60,9 +59,9 @@ public class PerfDataBuffer extends AbstractPerfDataBuffer {
FileChannel fc = new RandomAccessFile(f, mode).getChannel();
ByteBuffer bb = null;
if (mode.compareTo("r") == 0) {
if (mode.equals("r")) {
bb = fc.map(FileChannel.MapMode.READ_ONLY, 0L, (int)fc.size());
} else if (mode.compareTo("rw") == 0) {
} else if (mode.equals("rw")) {
bb = fc.map(FileChannel.MapMode.READ_WRITE, 0L, (int)fc.size());
} else {
throw new IllegalArgumentException("Invalid mode: " + mode);

@ -28,7 +28,6 @@ package sun.jvmstat.perfdata.monitor.v1_0;
import sun.jvmstat.monitor.*;
import sun.jvmstat.perfdata.monitor.*;
import java.util.*;
import java.util.regex.*;
import java.nio.*;
/**
@ -360,7 +359,7 @@ public class PerfDataBuffer extends PerfDataBufferImpl {
String cname = "hotspot.gc.collector.0.name";
StringMonitor collector = (StringMonitor)map.get(cname);
if (collector.stringValue().compareTo("PSScavenge") == 0) {
if (collector.stringValue().equals("PSScavenge")) {
boolean adaptiveSizePolicy = true;
/*