Skip to content
Permalink
Browse files
8274016: Replace 'for' cycles with iterator with enhanced-for in java…
….desktop

Reviewed-by: serb
  • Loading branch information
turbanoff authored and mrserb committed Sep 28, 2021
1 parent d8a278f commit 1a29b1e95e448bbef93373a25ba93a5591faed49
@@ -34,7 +34,6 @@
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;

public abstract class SimpleRenderedImage implements RenderedImage {
@@ -282,13 +281,7 @@ public String[] getPropertyNames(String prefix) {
return null;
}

// Copy the strings from the Vector over to a String array.
String[] prefixNames = new String[names.size()];
int count = 0;
for (Iterator<String> it = names.iterator(); it.hasNext(); ) {
prefixNames[count++] = it.next();
}

String[] prefixNames = names.toArray(new String[0]);
return prefixNames;
}

@@ -41,7 +41,6 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.imageio.IIOException;
@@ -159,9 +158,7 @@ protected Object clone() {
JFIFMarkerSegment newGuy = (JFIFMarkerSegment) super.clone();
if (!extSegments.isEmpty()) { // Clone the list with a deep copy
newGuy.extSegments = new ArrayList<>();
for (Iterator<JFIFExtensionMarkerSegment> iter =
extSegments.iterator(); iter.hasNext();) {
JFIFExtensionMarkerSegment jfxx = iter.next();
for (JFIFExtensionMarkerSegment jfxx : extSegments) {
newGuy.extSegments.add((JFIFExtensionMarkerSegment) jfxx.clone());
}
}
@@ -231,9 +228,7 @@ IIOMetadataNode getNativeNode() {
if (!extSegments.isEmpty()) {
IIOMetadataNode JFXXnode = new IIOMetadataNode("JFXX");
node.appendChild(JFXXnode);
for (Iterator<JFIFExtensionMarkerSegment> iter =
extSegments.iterator(); iter.hasNext();) {
JFIFExtensionMarkerSegment seg = iter.next();
for (JFIFExtensionMarkerSegment seg : extSegments) {
JFXXnode.appendChild(seg.getNativeNode());
}
}
@@ -635,9 +630,7 @@ void print() {
System.out.print("Thumbnail Height: ");
System.out.println(thumbHeight);
if (!extSegments.isEmpty()) {
for (Iterator<JFIFExtensionMarkerSegment> iter =
extSegments.iterator(); iter.hasNext();) {
JFIFExtensionMarkerSegment extSegment = iter.next();
for (JFIFExtensionMarkerSegment extSegment : extSegments) {
extSegment.print();
}
}
@@ -1275,9 +1275,8 @@ private Raster readInternal(int imageIndex,
// and set knownPassCount
if (imageIndex == imageMetadataIndex) { // We have metadata
knownPassCount = 0;
for (Iterator<MarkerSegment> iter =
imageMetadata.markerSequence.iterator(); iter.hasNext();) {
if (iter.next() instanceof SOSMarkerSegment) {
for (MarkerSegment markerSegment : imageMetadata.markerSequence) {
if (markerSegment instanceof SOSMarkerSegment) {
knownPassCount++;
}
}
@@ -41,7 +41,6 @@
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.imageio.IIOException;
@@ -1382,9 +1381,7 @@ private void checkAdobe(AdobeMarkerSegment adobe,
List<SOSMarkerSegment> segments = new ArrayList<>();
int SCAN_SIZE = 9;
int MAX_COMPS_PER_SCAN = 4;
for (Iterator<MarkerSegment> iter = metadata.markerSequence.iterator();
iter.hasNext();) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : metadata.markerSequence) {
if (seg instanceof SOSMarkerSegment) {
segments.add((SOSMarkerSegment) seg);
}
@@ -1711,9 +1711,7 @@ private void mergeStandardChromaNode(Node node, NodeList siblings)
}
if (idsDiffer) {
// update the ids in each SOS marker segment
for (Iterator<MarkerSegment> iter = markerSequence.iterator();
iter.hasNext();) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
if (seg instanceof SOSMarkerSegment) {
SOSMarkerSegment target = (SOSMarkerSegment) seg;
for (int i = 0; i < target.componentSpecs.length; i++) {
@@ -1766,9 +1764,7 @@ private void mergeStandardChromaNode(Node node, NodeList siblings)

if (updateQtables) {
List<DQTMarkerSegment> tableSegments = new ArrayList<>();
for (Iterator<MarkerSegment> iter = markerSequence.iterator();
iter.hasNext();) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
if (seg instanceof DQTMarkerSegment) {
tableSegments.add((DQTMarkerSegment) seg);
}
@@ -1784,12 +1780,8 @@ private void mergeStandardChromaNode(Node node, NodeList siblings)

// Find the table with selector 1.
boolean found = false;
for (Iterator<DQTMarkerSegment> iter = tableSegments.iterator();
iter.hasNext();) {
DQTMarkerSegment testdqt = iter.next();
for (Iterator<DQTMarkerSegment.Qtable> tabiter =
testdqt.tables.iterator(); tabiter.hasNext();) {
DQTMarkerSegment.Qtable tab = tabiter.next();
for (DQTMarkerSegment testdqt : tableSegments) {
for (DQTMarkerSegment.Qtable tab : testdqt.tables) {
if (tab.tableID == 1) {
found = true;
}
@@ -1798,12 +1790,8 @@ private void mergeStandardChromaNode(Node node, NodeList siblings)
if (!found) {
// find the table with selector 0. There should be one.
DQTMarkerSegment.Qtable table0 = null;
for (Iterator<DQTMarkerSegment> iter =
tableSegments.iterator(); iter.hasNext();) {
DQTMarkerSegment testdqt = iter.next();
for (Iterator<DQTMarkerSegment.Qtable> tabiter =
testdqt.tables.iterator(); tabiter.hasNext();) {
DQTMarkerSegment.Qtable tab = tabiter.next();
for (DQTMarkerSegment testdqt : tableSegments) {
for (DQTMarkerSegment.Qtable tab : testdqt.tables) {
if (tab.tableID == 0) {
table0 = tab;
}
@@ -1821,9 +1809,7 @@ private void mergeStandardChromaNode(Node node, NodeList siblings)

if (updateHtables) {
List<DHTMarkerSegment> tableSegments = new ArrayList<>();
for (Iterator<MarkerSegment> iter = markerSequence.iterator();
iter.hasNext();) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
if (seg instanceof DHTMarkerSegment) {
tableSegments.add((DHTMarkerSegment) seg);
}
@@ -1838,12 +1824,8 @@ private void mergeStandardChromaNode(Node node, NodeList siblings)

// find a table with selector 1. AC/DC is irrelevant
boolean found = false;
for (Iterator<DHTMarkerSegment> iter = tableSegments.iterator();
iter.hasNext();) {
DHTMarkerSegment testdht = iter.next();
for (Iterator<DHTMarkerSegment.Htable> tabiter =
testdht.tables.iterator(); tabiter.hasNext();) {
DHTMarkerSegment.Htable tab = tabiter.next();
for (DHTMarkerSegment testdht : tableSegments) {
for (DHTMarkerSegment.Htable tab : testdht.tables) {
if (tab.tableID == 1) {
found = true;
}
@@ -1078,8 +1078,8 @@ private boolean typeAheadAssertions(Component target, AWTEvent e) {
* @since 1.5
*/
private boolean hasMarker(Component comp) {
for (Iterator<TypeAheadMarker> iter = typeAheadMarkers.iterator(); iter.hasNext(); ) {
if (iter.next().untilFocused == comp) {
for (TypeAheadMarker typeAheadMarker : typeAheadMarkers) {
if (typeAheadMarker.untilFocused == comp) {
return true;
}
}
@@ -1137,15 +1137,11 @@ private boolean preDispatchKeyEvent(KeyEvent ke) {

java.util.List<KeyEventDispatcher> dispatchers = getKeyEventDispatchers();
if (dispatchers != null) {
for (java.util.Iterator<KeyEventDispatcher> iter = dispatchers.iterator();
iter.hasNext(); )
{
if (iter.next().
dispatchKeyEvent(ke))
{
return true;
}
}
for (KeyEventDispatcher dispatcher : dispatchers) {
if (dispatcher.dispatchKeyEvent(ke)) {
return true;
}
}
}
return dispatchKeyEvent(ke);
}
@@ -2977,13 +2977,9 @@ static boolean removeFirstRequest() {
if (hwFocusRequest != null) {
heavyweightRequests.removeFirst();
if (hwFocusRequest.lightweightRequests != null) {
for (Iterator<KeyboardFocusManager.LightweightFocusRequest> lwIter = hwFocusRequest.lightweightRequests.
iterator();
lwIter.hasNext(); )
{
for (LightweightFocusRequest lwFocusRequest : hwFocusRequest.lightweightRequests) {
manager.dequeueKeyEvents
(-1, lwIter.next().
component);
(-1, lwFocusRequest.component);
}
}
}
@@ -28,13 +28,9 @@

import java.awt.AWTKeyStroke;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.font.TextAttribute;

@@ -521,8 +517,8 @@ protected void initialize(Class<?> type, Object oldInstance, Object newInstance,
if (newO.size() != 0) {
invokeStatement(oldInstance, "clear", new Object[]{}, out);
}
for (Iterator<?> i = oldO.iterator(); i.hasNext();) {
invokeStatement(oldInstance, "add", new Object[]{i.next()}, out);
for (Object o : oldO) {
invokeStatement(oldInstance, "add", new Object[]{o}, out);
}
}
}
@@ -771,17 +771,15 @@ public synchronized boolean needsGui() {
}

synchronized(children) {
for (Iterator<Object> i = children.keySet().iterator(); i.hasNext();) {
Object c = i.next();

for (Object c : children.keySet()) {
try {
return ((Visibility)c).needsGui();
} catch (ClassCastException cce) {
// do nothing ...
}
return ((Visibility)c).needsGui();
} catch (ClassCastException cce) {
// do nothing ...
}

if (c instanceof Container || c instanceof Component)
return true;
if (c instanceof Container || c instanceof Component)
return true;
}
}

@@ -798,11 +796,11 @@ public synchronized void dontUseGui() {

// lets also tell the Children that can that they may not use their GUI's
synchronized(children) {
for (Iterator<Object> i = children.keySet().iterator(); i.hasNext();) {
Visibility v = getChildVisibility(i.next());
for (Object c : children.keySet()) {
Visibility v = getChildVisibility(c);

if (v != null) v.dontUseGui();
}
}
}
}
}
@@ -817,8 +815,8 @@ public synchronized void okToUseGui() {

// lets also tell the Children that can that they may use their GUI's
synchronized(children) {
for (Iterator<Object> i = children.keySet().iterator(); i.hasNext();) {
Visibility v = getChildVisibility(i.next());
for (Object c : children.keySet()) {
Visibility v = getChildVisibility(c);

if (v != null) v.okToUseGui();
}
@@ -799,8 +799,7 @@ private void updateWindows(Map<Component,Rectangle> dirtyComponents) {

Set<Window> windows = new HashSet<Window>();
Set<Component> dirtyComps = dirtyComponents.keySet();
for (Iterator<Component> it = dirtyComps.iterator(); it.hasNext();) {
Component dirty = it.next();
for (Component dirty : dirtyComps) {
Window window = dirty instanceof Window ?
(Window)dirty :
SwingUtilities.getWindowAncestor(dirty);
@@ -82,7 +82,6 @@
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Vector;
@@ -946,13 +945,12 @@ public static BufferedImage getScaledIconImage(java.util.List<Image> imageList,
int bestHeight = 0;
double bestSimilarity = 3; //Impossibly high value
double bestScaleFactor = 0;
for (Iterator<Image> i = multiResAndnormalImages.iterator();i.hasNext();) {
for (Image im : multiResAndnormalImages) {
//Iterate imageList looking for best matching image.
//'Similarity' measure is defined as good scale factor and small insets.
//best possible similarity is 0 (no scale, no insets).
//It's found while the experiments that good-looking result is achieved
//with scale factors x1, x3/4, x2/3, xN, x1/N.
Image im = i.next();
if (im == null) {
continue;
}
@@ -1992,9 +1992,7 @@ private static void callTimeoutTasks() {
while (time.compareTo(currentTime) <= 0) {
java.util.List<Runnable> tasks = timeoutTasks.remove(time);

for (Iterator<Runnable> iter = tasks.iterator(); iter.hasNext();) {
Runnable task = iter.next();

for (Runnable task : tasks) {
if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
timeoutTaskLog.finer("XToolkit.callTimeoutTasks(): current time={0}" +
"; about to run task={1}", Long.valueOf(currentTime), task);
@@ -51,7 +51,6 @@
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -306,8 +305,7 @@ public void updateIconImages() {
if (iconImages.size() != 0) {
//read icon images from target
winAttr.iconsInherited = false;
for (Iterator<Image> i = iconImages.iterator(); i.hasNext(); ) {
Image image = i.next();
for (Image image : iconImages) {
if (image == null) {
if (log.isLoggable(PlatformLogger.Level.FINEST)) {
log.finest("XWindowPeer.updateIconImages: Skipping the image passed into Java because it's null.");
@@ -403,8 +401,8 @@ static java.util.List<IconInfo> normalizeIconImages(java.util.List<IconInfo> ico
static void dumpIcons(java.util.List<IconInfo> icons) {
if (iconLog.isLoggable(PlatformLogger.Level.FINEST)) {
iconLog.finest(">>> Sizes of icon images:");
for (Iterator<IconInfo> i = icons.iterator(); i.hasNext(); ) {
iconLog.finest(" {0}", i.next());
for (IconInfo icon : icons) {
iconLog.finest(" {0}", icon);
}
}
}

1 comment on commit 1a29b1e

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 1a29b1e Sep 28, 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.