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

Reviewed-by: dfuchs, weijun
This commit is contained in:
Andrey Turbanov 2021-09-24 16:46:52 +00:00 committed by Weijun Wang
parent 0c050be64b
commit baafa6059e
4 changed files with 18 additions and 32 deletions

View file

@ -622,8 +622,7 @@ public final class Security {
// For each selection criterion, remove providers
// which don't satisfy the criterion from the candidate set.
for (Iterator<String> ite = keySet.iterator(); ite.hasNext(); ) {
String key = ite.next();
for (String key : keySet) {
String value = filter.get(key);
LinkedHashSet<Provider> newCandidates = getAllQualifyingCandidates(key, value,

View file

@ -200,8 +200,8 @@ public class PKIXParameters implements CertPathParameters {
throw new InvalidAlgorithmParameterException("the trustAnchors " +
"parameter must be non-empty");
}
for (Iterator<TrustAnchor> i = trustAnchors.iterator(); i.hasNext(); ) {
if (!(i.next() instanceof TrustAnchor)) {
for (Object trustAnchor : trustAnchors) {
if (!(trustAnchor instanceof TrustAnchor)) {
throw new ClassCastException("all elements of set must be "
+ "of type java.security.cert.TrustAnchor");
}
@ -249,9 +249,8 @@ public class PKIXParameters implements CertPathParameters {
*/
public void setInitialPolicies(Set<String> initialPolicies) {
if (initialPolicies != null) {
for (Iterator<String> i = initialPolicies.iterator();
i.hasNext();) {
if (!(i.next() instanceof String))
for (Object initialPolicy : initialPolicies) {
if (!(initialPolicy instanceof String))
throw new ClassCastException("all elements of set must be "
+ "of type java.lang.String");
}
@ -282,8 +281,8 @@ public class PKIXParameters implements CertPathParameters {
if (stores == null) {
this.certStores = new ArrayList<>();
} else {
for (Iterator<CertStore> i = stores.iterator(); i.hasNext();) {
if (!(i.next() instanceof CertStore)) {
for (Object store : stores) {
if (!(store instanceof CertStore)) {
throw new ClassCastException("all elements of list must be "
+ "of type java.security.cert.CertStore");
}

View file

@ -364,8 +364,7 @@ public class X509CRLSelector implements CRLSelector {
private static HashSet<X500Principal> parseIssuerNames(Collection<Object> names)
throws IOException {
HashSet<X500Principal> x500Principals = new HashSet<>();
for (Iterator<Object> t = names.iterator(); t.hasNext(); ) {
Object nameObject = t.next();
for (Object nameObject : names) {
if (nameObject instanceof String) {
x500Principals.add(new X500Name((String)nameObject).asX500Principal());
} else {

View file

@ -68,9 +68,7 @@ public class ProgressMonitor
try {
synchronized(progressSourceList) {
for (Iterator<ProgressSource> iter = progressSourceList.iterator(); iter.hasNext();) {
ProgressSource pi = iter.next();
for (ProgressSource pi : progressSourceList) {
// Clone ProgressSource and add to snapshot
snapshot.add((ProgressSource)pi.clone());
}
@ -114,18 +112,15 @@ public class ProgressMonitor
if (progressListenerList.size() > 0)
{
// Notify progress listener if there is progress change
ArrayList<ProgressListener> listeners = new ArrayList<>();
ArrayList<ProgressListener> listeners;
// Copy progress listeners to another list to avoid holding locks
synchronized(progressListenerList) {
for (Iterator<ProgressListener> iter = progressListenerList.iterator(); iter.hasNext();) {
listeners.add(iter.next());
}
listeners = new ArrayList<>(progressListenerList);
}
// Fire event on each progress listener
for (Iterator<ProgressListener> iter = listeners.iterator(); iter.hasNext();) {
ProgressListener pl = iter.next();
for (ProgressListener pl : listeners) {
ProgressEvent pe = new ProgressEvent(pi, pi.getURL(), pi.getMethod(), pi.getContentType(), pi.getState(), pi.getProgress(), pi.getExpected());
pl.progressStart(pe);
}
@ -151,18 +146,15 @@ public class ProgressMonitor
if (progressListenerList.size() > 0)
{
// Notify progress listener if there is progress change
ArrayList<ProgressListener> listeners = new ArrayList<>();
ArrayList<ProgressListener> listeners;
// Copy progress listeners to another list to avoid holding locks
synchronized(progressListenerList) {
for (Iterator<ProgressListener> iter = progressListenerList.iterator(); iter.hasNext();) {
listeners.add(iter.next());
}
listeners = new ArrayList<>(progressListenerList);
}
// Fire event on each progress listener
for (Iterator<ProgressListener> iter = listeners.iterator(); iter.hasNext();) {
ProgressListener pl = iter.next();
for (ProgressListener pl : listeners) {
ProgressEvent pe = new ProgressEvent(pi, pi.getURL(), pi.getMethod(), pi.getContentType(), pi.getState(), pi.getProgress(), pi.getExpected());
pl.progressFinish(pe);
}
@ -183,18 +175,15 @@ public class ProgressMonitor
if (progressListenerList.size() > 0)
{
// Notify progress listener if there is progress change
ArrayList<ProgressListener> listeners = new ArrayList<>();
ArrayList<ProgressListener> listeners;
// Copy progress listeners to another list to avoid holding locks
synchronized(progressListenerList) {
for (Iterator<ProgressListener> iter = progressListenerList.iterator(); iter.hasNext();) {
listeners.add(iter.next());
}
listeners = new ArrayList<>(progressListenerList);
}
// Fire event on each progress listener
for (Iterator<ProgressListener> iter = listeners.iterator(); iter.hasNext();) {
ProgressListener pl = iter.next();
for (ProgressListener pl : listeners) {
ProgressEvent pe = new ProgressEvent(pi, pi.getURL(), pi.getMethod(), pi.getContentType(), pi.getState(), pi.getProgress(), pi.getExpected());
pl.progressUpdate(pe);
}