Skip to content
Permalink
Browse files
8274163: Use String.equals instead of String.compareTo in jdk.jcmd
Reviewed-by: cjplummer, amenkov, sspitsyn
  • Loading branch information
turbanoff authored and Serguei Spitsyn committed Nov 16, 2021
1 parent 0bc2683 commit 9629627e2c8021c254517ac5463cc66723175fd9
Showing 4 changed files with 35 additions and 35 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2018, 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
@@ -64,11 +64,11 @@ public Arguments(String[] args) throws IllegalArgumentException {
int argc = 0;

if (args.length == 1) {
if ((args[0].compareTo("-?") == 0)
|| (args[0].compareTo("-h")== 0)
|| (args[0].compareTo("--help")== 0)
if ((args[0].equals("-?"))
|| (args[0].equals("-h"))
|| (args[0].equals("--help"))
// -help: legacy.
|| (args[0].compareTo("-help")== 0)) {
|| (args[0].equals("-help"))) {
help = true;
return;
}
@@ -78,7 +78,7 @@ public Arguments(String[] args) throws IllegalArgumentException {
argc++) {
String arg = args[argc];

if (arg.compareTo("-q") == 0) {
if (arg.equals("-q")) {
quiet = true;
} else if (arg.startsWith("-")) {
for (int j = 1; j < arg.length(); j++) {
@@ -127,9 +127,9 @@ private static int toMillis(String s) throws IllegalArgumentException {
try {
int value = Integer.parseInt(valueString);

if (unitString == null || unitString.compareTo("ms") == 0) {
if (unitString == null || unitString.equals("ms")) {
return value;
} else if (unitString.compareTo("s") == 0) {
} else if (unitString.equals("s")) {
return value * 1000;
} else {
throw new IllegalArgumentException(
@@ -149,17 +149,17 @@ public Arguments(String[] args) throws IllegalArgumentException {
return;
}

if ((args[0].compareTo("-?") == 0)
|| (args[0].compareTo("-h") == 0)
|| (args[0].compareTo("--help") == 0)
if ((args[0].equals("-?"))
|| (args[0].equals("-h"))
|| (args[0].equals("--help"))
// -help: legacy.
|| (args[0].compareTo("-help") == 0)) {
|| (args[0].equals("-help"))) {
help = true;
return;
} else if (args[0].compareTo("-options") == 0) {
} else if (args[0].equals("-options")) {
options = true;
return;
} else if (args[0].compareTo("-list") == 0) {
} else if (args[0].equals("-list")) {
list = true;
if (args.length > 2) {
throw new IllegalArgumentException("invalid argument count");
@@ -171,23 +171,23 @@ public Arguments(String[] args) throws IllegalArgumentException {
for ( ; (argc < args.length) && (args[argc].startsWith("-")); argc++) {
String arg = args[argc];

if (arg.compareTo("-a") == 0) {
if (arg.equals("-a")) {
comparator = new AscendingMonitorComparator();
} else if (arg.compareTo("-d") == 0) {
} else if (arg.equals("-d")) {
comparator = new DescendingMonitorComparator();
} else if (arg.compareTo("-t") == 0) {
} else if (arg.equals("-t")) {
timestamp = true;
} else if (arg.compareTo("-v") == 0) {
} else if (arg.equals("-v")) {
verbose = true;
} else if ((arg.compareTo("-constants") == 0)
|| (arg.compareTo("-c") == 0)) {
} else if ((arg.equals("-constants"))
|| (arg.equals("-c"))) {
constants = true;
} else if ((arg.compareTo("-strings") == 0)
|| (arg.compareTo("-s") == 0)) {
} else if ((arg.equals("-strings"))
|| (arg.equals("-s"))) {
strings = true;
} else if (arg.startsWith("-h")) {
String value;
if (arg.compareTo("-h") != 0) {
if (!arg.equals("-h")) {
value = arg.substring(2);
} else {
argc++;
@@ -245,7 +245,7 @@ public Arguments(String[] args) throws IllegalArgumentException {
} catch (NumberFormatException nfe) {
// it didn't parse. check for the -snap or jstat_options
// file options.
if ((argc == 0) && (args[argc].compareTo("-snap") == 0)) {
if ((argc == 0) && (args[argc].equals("-snap"))) {
snap = true;
} else if (argc == 0) {
specialOption = args[argc].substring(1);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2010, 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
@@ -73,7 +73,7 @@ public int compare(OptionFormat o1, OptionFormat o2) {
}

for ( OptionFormat of : options) {
if (of.getName().compareTo("timestamp") == 0) {
if (of.getName().equals("timestamp")) {
// ignore the special timestamp OptionFormat.
continue;
}
@@ -468,19 +468,19 @@ private void statementList(ColumnFormat cf)
return;
}

if (lookahead.sval.compareTo(DATA) == 0) {
if (lookahead.sval.equals(DATA)) {
dataStmt(cf);
} else if (lookahead.sval.compareTo(HEADER) == 0) {
} else if (lookahead.sval.equals(HEADER)) {
headerStmt(cf);
} else if (lookahead.sval.compareTo(WIDTH) == 0) {
} else if (lookahead.sval.equals(WIDTH)) {
widthStmt(cf);
} else if (lookahead.sval.compareTo(FORMAT) == 0) {
} else if (lookahead.sval.equals(FORMAT)) {
formatStmt(cf);
} else if (lookahead.sval.compareTo(ALIGN) == 0) {
} else if (lookahead.sval.equals(ALIGN)) {
alignStmt(cf);
} else if (lookahead.sval.compareTo(SCALE) == 0) {
} else if (lookahead.sval.equals(SCALE)) {
scaleStmt(cf);
} else if (lookahead.sval.compareTo(REQUIRED) == 0) {
} else if (lookahead.sval.equals(REQUIRED)) {
requiredStmt(cf);
} else {
return;
@@ -539,7 +539,7 @@ public OptionFormat parse(String option)
while (lookahead.ttype != StreamTokenizer.TT_EOF) {
// look for the start symbol
if ((lookahead.ttype != StreamTokenizer.TT_WORD)
|| (lookahead.sval.compareTo(START) != 0)) {
|| (!lookahead.sval.equals(START))) {
// skip tokens until a start symbol is found
nextToken();
continue;
@@ -569,7 +569,7 @@ public Set<OptionFormat> parseOptions() throws ParserException, IOException {
while (lookahead.ttype != StreamTokenizer.TT_EOF) {
// look for the start symbol
if ((lookahead.ttype != StreamTokenizer.TT_WORD)
|| (lookahead.sval.compareTo(START) != 0)) {
|| (!lookahead.sval.equals(START))) {
// skip tokens until a start symbol is found
nextToken();
continue;

1 comment on commit 9629627

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 9629627 Nov 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.