8274261: Use enhanced-for instead of plain 'for' in jdk.jcmd

Reviewed-by: sspitsyn, cjplummer
This commit is contained in:
Andrey Turbanov 2021-11-16 11:13:24 +00:00 committed by Serguei Spitsyn
parent b8d33a2a4e
commit 20f3872d1c
6 changed files with 30 additions and 44 deletions

View File

@ -31,7 +31,6 @@ import java.io.InputStream;
import java.util.Collection;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
import com.sun.tools.attach.AttachNotSupportedException;
import sun.tools.attach.HotSpotVirtualMachine;
import sun.tools.common.ProcessArgumentMatcher;
@ -171,8 +170,7 @@ public class JMap {
String parallel = null;
String subopts[] = options.split(",");
for (int i = 0; i < subopts.length; i++) {
String subopt = subopts[i];
for (String subopt : subopts) {
if (subopt.equals("") || subopt.equals("all")) {
// pass
} else if (subopt.equals("live")) {
@ -184,11 +182,11 @@ public class JMap {
usage(1);
}
} else if (subopt.startsWith("parallel=")) {
parallel = subopt.substring("parallel=".length());
if (parallel == null) {
parallel = subopt.substring("parallel=".length());
if (parallel == null) {
System.err.println("Fail: no number provided in option: '" + subopt + "'");
usage(1);
}
}
} else {
System.err.println("Fail: invalid option: '" + subopt + "'");
usage(1);
@ -209,8 +207,7 @@ public class JMap {
String liveopt = "-all";
String compress_level = null;
for (int i = 0; i < subopts.length; i++) {
String subopt = subopts[i];
for (String subopt : subopts) {
if (subopt.equals("") || subopt.equals("all")) {
// pass
} else if (subopt.equals("live")) {

View File

@ -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
@ -115,8 +115,8 @@ public class Arguments {
String unitString = null;
String valueString = s;
for (int i = 0; i < unitStrings.length; i++) {
int index = s.indexOf(unitStrings[i]);
for (String unit : unitStrings) {
int index = s.indexOf(unit);
if (index > 0) {
unitString = s.substring(index);
valueString = s.substring(0, index);

View File

@ -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
@ -25,8 +25,6 @@
package sun.tools.jstat;
import java.util.*;
/**
* A class to represent the format for a column of data.
*
@ -156,9 +154,8 @@ public class ColumnFormat extends OptionFormat {
+ ";scale=" + scale.toString() + ";align=" + align.toString()
+ ";required=" + required);
for (Iterator<OptionFormat> i = children.iterator(); i.hasNext(); /* empty */) {
OptionFormat of = i.next();
of.printFormat(indentLevel+1);
for (OptionFormat of : children) {
of.printFormat(indentLevel + 1);
}
System.out.println(indent + "}");

View File

@ -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
@ -77,15 +77,14 @@ public class OptionFormat {
public void apply(Closure c) throws MonitorException {
for (Iterator<OptionFormat> i = children.iterator(); i.hasNext(); /* empty */) {
OptionFormat o = i.next();
c.visit(o, i.hasNext());
}
for (Iterator<OptionFormat> i = children.iterator(); i.hasNext(); /* empty */) {
OptionFormat o = i.next();
c.visit(o, i.hasNext());
}
for (Iterator <OptionFormat>i = children.iterator(); i.hasNext(); /* empty */) {
OptionFormat o = i.next();
o.apply(c);
}
for (OptionFormat o : children) {
o.apply(c);
}
}
public void printFormat() {

View File

@ -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
@ -80,7 +80,7 @@ public class Parser {
};
private static Set<String> reservedWords;
private static final Set<String> reservedWords = Set.of(otherKeyWords);
private StreamTokenizer st;
private String filename;
@ -103,17 +103,12 @@ public class Parser {
st.slashSlashComments(true);
st.slashStarComments(true);
reservedWords = new HashSet<String>();
for (int i = 0; i < otherKeyWords.length; i++) {
reservedWords.add(otherKeyWords[i]);
for (char delimiter : delimiters) {
st.ordinaryChar(delimiter);
}
for (int i = 0; i < delimiters.length; i++ ) {
st.ordinaryChar(delimiters[i]);
}
for (int i = 0; i < infixOps.length; i++ ) {
st.ordinaryChar(infixOps[i]);
for (char infixOp : infixOps) {
st.ordinaryChar(infixOp);
}
}
@ -231,8 +226,8 @@ public class Parser {
* determine if the give work is a reserved key word
*/
private boolean isInfixOperator(char op) {
for (int i = 0; i < infixOps.length; i++) {
if (op == infixOps[i]) {
for (char infixOp : infixOps) {
if (op == infixOp) {
return true;
}
}

View File

@ -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
@ -48,8 +48,7 @@ public class RawOutputFormatter implements OutputFormatter {
if (header == null) {
// build the header string and prune out any unwanted monitors
StringBuilder headerBuilder = new StringBuilder();
for (Iterator<Monitor> i = logged.iterator(); i.hasNext(); /* empty */ ) {
Monitor m = i.next();
for (Monitor m : logged) {
headerBuilder.append(m.getName()).append(' ');
}
header = headerBuilder.toString();
@ -60,8 +59,7 @@ public class RawOutputFormatter implements OutputFormatter {
public String getRow() throws MonitorException {
StringBuilder row = new StringBuilder();
int count = 0;
for (Iterator<Monitor> i = logged.iterator(); i.hasNext(); /* empty */ ) {
Monitor m = i.next();
for (Monitor m : logged) {
if (count++ > 0) {
row.append(" ");
}