8273261: Replace 'while' cycles with iterator with enhanced-for in java.base

Reviewed-by: dfuchs, rriggs, iris, mullan
This commit is contained in:
Andrey Turbanov 2021-09-23 20:04:36 +00:00 committed by Roger Riggs
parent 0aa63feca8
commit 56b8b35286
11 changed files with 43 additions and 92 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -314,9 +314,7 @@ public class X509CRLSelector implements CRLSelector {
throws IOException
{
HashSet<Object> namesCopy = new HashSet<>();
Iterator<?> i = names.iterator();
while (i.hasNext()) {
Object nameObject = i.next();
for (Object nameObject : names) {
if (!(nameObject instanceof byte []) &&
!(nameObject instanceof String))
throw new IOException("name not byte array or String");
@ -573,9 +571,8 @@ public class X509CRLSelector implements CRLSelector {
sb.append("X509CRLSelector: [\n");
if (issuerNames != null) {
sb.append(" IssuerNames:\n");
Iterator<Object> i = issuerNames.iterator();
while (i.hasNext())
sb.append(" " + i.next() + "\n");
for (Object issuerName : issuerNames)
sb.append(" " + issuerName + "\n");
}
if (minCRL != null)
sb.append(" minCRLNumber: " + minCRL + "\n");

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -1778,9 +1778,7 @@ public class X509CertSelector implements CertSelector {
+ String.valueOf(matchAllSubjectAltNames) + "\n");
if (subjectAlternativeNames != null) {
sb.append(" SubjectAlternativeNames:\n");
Iterator<List<?>> i = subjectAlternativeNames.iterator();
while (i.hasNext()) {
List<?> list = i.next();
for (List<?> list : subjectAlternativeNames) {
sb.append(" type " + list.get(0) +
", name " + list.get(1) + "\n");
}
@ -1823,9 +1821,8 @@ public class X509CertSelector implements CertSelector {
}
if (pathToGeneralNames != null) {
sb.append(" Path to names:\n");
Iterator<GeneralNameInterface> i = pathToGeneralNames.iterator();
while (i.hasNext()) {
sb.append(" " + i.next() + "\n");
for (GeneralNameInterface pathToGeneralName : pathToGeneralNames) {
sb.append(" " + pathToGeneralName + "\n");
}
}
sb.append("]");
@ -2399,10 +2396,8 @@ public class X509CertSelector implements CertSelector {
}
if ((debug != null) && Debug.isOn("certpath")) {
debug.println("X509CertSelector.match pathToNames:\n");
Iterator<GeneralNameInterface> i =
pathToGeneralNames.iterator();
while (i.hasNext()) {
debug.println(" " + i.next() + "\n");
for (GeneralNameInterface pathToGeneralName : pathToGeneralNames) {
debug.println(" " + pathToGeneralName + "\n");
}
}
@ -2439,9 +2434,7 @@ public class X509CertSelector implements CertSelector {
for (Iterator<GeneralSubtree> t = excluded.iterator(); t.hasNext(); ) {
GeneralSubtree tree = t.next();
GeneralNameInterface excludedName = tree.getName().getName();
Iterator<GeneralNameInterface> i = pathToGeneralNames.iterator();
while (i.hasNext()) {
GeneralNameInterface pathToName = i.next();
for (GeneralNameInterface pathToName : pathToGeneralNames) {
if (excludedName.getType() == pathToName.getType()) {
switch (pathToName.constrains(excludedName)) {
case GeneralNameInterface.NAME_WIDENS:
@ -2468,9 +2461,7 @@ public class X509CertSelector implements CertSelector {
* If not, return false. However, if no subtrees of a given type
* are listed, all names of that type are permitted.
*/
Iterator<GeneralNameInterface> i = pathToGeneralNames.iterator();
while (i.hasNext()) {
GeneralNameInterface pathToName = i.next();
for (GeneralNameInterface pathToName : pathToGeneralNames) {
Iterator<GeneralSubtree> t = permitted.iterator();
boolean permittedNameFound = false;
boolean nameTypeFound = false;

View file

@ -158,9 +158,7 @@ public class AttributedString {
runAttributes[0] = newRunAttributes;
runAttributeValues[0] = newRunAttributeValues;
Iterator<? extends Map.Entry<? extends Attribute, ?>> iterator = attributes.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<? extends Attribute, ?> entry = iterator.next();
for (Map.Entry<? extends Attribute, ?> entry : attributes.entrySet()) {
newRunAttributes.addElement(entry.getKey());
newRunAttributeValues.addElement(entry.getValue());
}
@ -264,9 +262,7 @@ public class AttributedString {
// Get and set attribute runs for each attribute name. Need to
// scan from the top of the text so that we can discard any
// Annotation that is no longer applied to a subset text segment.
Iterator<Attribute> itr = keys.iterator();
while (itr.hasNext()) {
Attribute attributeKey = itr.next();
for (Attribute attributeKey : keys) {
text.setIndex(textBeginIndex);
while (text.getIndex() < endIndex) {
int start = text.getRunStart(attributeKey);
@ -388,10 +384,7 @@ public class AttributedString {
int beginRunIndex = ensureRunBreak(beginIndex);
int endRunIndex = ensureRunBreak(endIndex);
Iterator<? extends Map.Entry<? extends Attribute, ?>> iterator =
attributes.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<? extends Attribute, ?> entry = iterator.next();
for (Map.Entry<? extends Attribute, ?> entry : attributes.entrySet()) {
addAttributeRunData(entry.getKey(), entry.getValue(), beginRunIndex, endRunIndex);
}
}
@ -656,10 +649,8 @@ public class AttributedString {
// returns whether all specified attributes have equal values in the runs with the given indices
private boolean attributeValuesMatch(Set<? extends Attribute> attributes, int runIndex1, int runIndex2) {
Iterator<? extends Attribute> iterator = attributes.iterator();
while (iterator.hasNext()) {
Attribute key = iterator.next();
if (!valuesMatch(getAttribute(key, runIndex1), getAttribute(key, runIndex2))) {
for (Attribute key : attributes) {
if (!valuesMatch(getAttribute(key, runIndex1), getAttribute(key, runIndex2))) {
return false;
}
}
@ -706,11 +697,8 @@ public class AttributedString {
if (attrs != null && (size = attrs.size()) > 0) {
Vector<Attribute> runAttrs = new Vector<>(size);
Vector<Object> runValues = new Vector<>(size);
Iterator<Map.Entry<Attribute, Object>> iterator = attrs.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Attribute, Object> entry = iterator.next();
for (Map.Entry<Attribute, Object> entry : attrs.entrySet()) {
runAttrs.add(entry.getKey());
runValues.add(entry.getValue());
}