Skip to content
Permalink
Browse files
8258006: Replaces while cycles with iterator with enhanced for in jav…
…a.desktop

Reviewed-by: prr, serb
  • Loading branch information
turbanoff authored and mrserb committed Dec 19, 2020
1 parent dc7f01f commit 580af4906d1fab7f0c3ba6e5b287761fff2b019c
Showing with 68 additions and 167 deletions.
  1. +2 −3 src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageWriter.java
  2. +2 −4 src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/DHTMarkerSegment.java
  3. +2 −4 src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/DQTMarkerSegment.java
  4. +2 −6 src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java
  5. +10 −28 src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java
  6. +2 −6 src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFIFD.java
  7. +4 −12 src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFImageMetadata.java
  8. +3 −7 src/java.desktop/share/classes/com/sun/media/sound/SF2Soundbank.java
  9. +1 −3 src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java
  10. +2 −6 src/java.desktop/share/classes/java/awt/Dialog.java
  11. +2 −4 src/java.desktop/share/classes/java/awt/SequencedEvent.java
  12. +2 −3 src/java.desktop/share/classes/java/beans/Introspector.java
  13. +2 −11 src/java.desktop/share/classes/java/beans/beancontext/BeanContextServicesSupport.java
  14. +2 −3 src/java.desktop/share/classes/java/beans/beancontext/BeanContextSupport.java
  15. +4 −10 src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadataFormatImpl.java
  16. +1 −3 src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadataNode.java
  17. +3 −4 src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFDirectory.java
  18. +2 −4 src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFTagSet.java
  19. +4 −10 src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java
  20. +2 −4 src/java.desktop/share/classes/javax/print/StreamPrintServiceFactory.java
  21. +3 −7 src/java.desktop/share/classes/javax/sound/midi/MidiSystem.java
  22. +2 −6 src/java.desktop/share/classes/javax/swing/text/DateFormatter.java
  23. +3 −7 src/java.desktop/share/classes/sun/awt/SunDisplayChanger.java
  24. +4 −6 src/java.desktop/share/classes/sun/awt/SunToolkit.java
  25. +2 −6 src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java
@@ -1252,11 +1252,10 @@ private void writeCommentExtension(GIFWritableImageMetadata im)
throws IOException {
if (im.comments != null) {
try {
Iterator<byte[]> iter = im.comments.iterator();
while (iter.hasNext()) {
for (byte[] bytes : im.comments) {
stream.write(0x21);
stream.write(0xfe);
writeBlocks(iter.next());
writeBlocks(bytes);
stream.write(0x00);
}
} catch (IOException e) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2020, 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
@@ -94,9 +94,7 @@
protected Object clone() {
DHTMarkerSegment newGuy = (DHTMarkerSegment) super.clone();
newGuy.tables = new ArrayList<>(tables.size());
Iterator<Htable> iter = tables.iterator();
while (iter.hasNext()) {
Htable table = iter.next();
for (Htable table : tables) {
newGuy.tables.add((Htable) table.clone());
}
return newGuy;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2020, 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
@@ -87,9 +87,7 @@
protected Object clone() {
DQTMarkerSegment newGuy = (DQTMarkerSegment) super.clone();
newGuy.tables = new ArrayList<>(tables.size());
Iterator<Qtable> iter = tables.iterator();
while (iter.hasNext()) {
Qtable table = iter.next();
for (Qtable table : tables) {
newGuy.tables.add((Qtable) table.clone());
}
return newGuy;
@@ -1424,9 +1424,7 @@ private void checkAdobe(AdobeMarkerSegment adobe,
private JPEGQTable [] collectQTablesFromMetadata
(JPEGMetadata metadata) {
ArrayList<DQTMarkerSegment.Qtable> tables = new ArrayList<>();
Iterator<MarkerSegment> iter = metadata.markerSequence.iterator();
while (iter.hasNext()) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : metadata.markerSequence) {
if (seg instanceof DQTMarkerSegment) {
DQTMarkerSegment dqt =
(DQTMarkerSegment) seg;
@@ -1454,9 +1452,7 @@ private void checkAdobe(AdobeMarkerSegment adobe,
private JPEGHuffmanTable[] collectHTablesFromMetadata
(JPEGMetadata metadata, boolean wantDC) throws IIOException {
ArrayList<DHTMarkerSegment.Htable> tables = new ArrayList<>();
Iterator<MarkerSegment> iter = metadata.markerSequence.iterator();
while (iter.hasNext()) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : metadata.markerSequence) {
if (seg instanceof DHTMarkerSegment) {
DHTMarkerSegment dht = (DHTMarkerSegment) seg;
for (int i = 0; i < dht.tables.size(); i++) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2020, 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
@@ -635,9 +635,7 @@
* with the given tag, or null if none is found.
*/
MarkerSegment findMarkerSegment(int tag) {
Iterator<MarkerSegment> iter = markerSequence.iterator();
while (iter.hasNext()) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
if (seg.tag == tag) {
return seg;
}
@@ -651,9 +649,7 @@ MarkerSegment findMarkerSegment(int tag) {
*/
MarkerSegment findMarkerSegment(Class<? extends MarkerSegment> cls, boolean first) {
if (first) {
Iterator<MarkerSegment> iter = markerSequence.iterator();
while (iter.hasNext()) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
if (cls.isInstance(seg)) {
return seg;
}
@@ -732,9 +728,7 @@ protected Object clone() {
return null;
}
List<MarkerSegment> retval = new ArrayList<>(markerSequence.size());
Iterator<MarkerSegment> iter = markerSequence.iterator();
while(iter.hasNext()) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
retval.add((MarkerSegment) seg.clone());
}

@@ -955,9 +949,7 @@ protected IIOMetadataNode getStandardCompressionNode() {

// NumProgressiveScans - count sos segments
int sosCount = 0;
Iterator<MarkerSegment> iter = markerSequence.iterator();
while (iter.hasNext()) {
MarkerSegment ms = iter.next();
for (MarkerSegment ms : markerSequence) {
if (ms.tag == JPEG.SOS) {
sosCount++;
}
@@ -1022,9 +1014,7 @@ protected IIOMetadataNode getStandardTextNode() {
// Add a text entry for each COM Marker Segment
if (findMarkerSegment(JPEG.COM) != null) {
text = new IIOMetadataNode("Text");
Iterator<MarkerSegment> iter = markerSequence.iterator();
while (iter.hasNext()) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
if (seg.tag == JPEG.COM) {
COMMarkerSegment com = (COMMarkerSegment) seg;
IIOMetadataNode entry = new IIOMetadataNode("TextEntry");
@@ -1176,9 +1166,7 @@ private void mergeSequenceSubtree(Node sequenceTree)
private void mergeDQTNode(Node node) throws IIOInvalidTreeException {
// First collect any existing DQT nodes into a local list
ArrayList<DQTMarkerSegment> oldDQTs = new ArrayList<>();
Iterator<MarkerSegment> iter = markerSequence.iterator();
while (iter.hasNext()) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
if (seg instanceof DQTMarkerSegment) {
oldDQTs.add((DQTMarkerSegment) seg);
}
@@ -1251,9 +1239,7 @@ private void mergeDQTNode(Node node) throws IIOInvalidTreeException {
private void mergeDHTNode(Node node) throws IIOInvalidTreeException {
// First collect any existing DQT nodes into a local list
ArrayList<DHTMarkerSegment> oldDHTs = new ArrayList<>();
Iterator<MarkerSegment> iter = markerSequence.iterator();
while (iter.hasNext()) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
if (seg instanceof DHTMarkerSegment) {
oldDHTs.add((DHTMarkerSegment) seg);
}
@@ -2305,9 +2291,7 @@ private boolean isConsistent() {
*/
private int countScanBands() {
List<Integer> ids = new ArrayList<>();
Iterator<MarkerSegment> iter = markerSequence.iterator();
while(iter.hasNext()) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
if (seg instanceof SOSMarkerSegment) {
SOSMarkerSegment sos = (SOSMarkerSegment) seg;
SOSMarkerSegment.ScanComponentSpec [] specs = sos.componentSpecs;
@@ -2354,9 +2338,7 @@ void writeToStream(ImageOutputStream ios,
}
}
// Iterate over each MarkerSegment
Iterator<MarkerSegment> iter = markerSequence.iterator();
while(iter.hasNext()) {
MarkerSegment seg = iter.next();
for (MarkerSegment seg : markerSequence) {
if (seg instanceof JFIFMarkerSegment) {
if (ignoreJFIF == false) {
JFIFMarkerSegment jfif = (JFIFMarkerSegment) seg;
@@ -135,9 +135,7 @@ public static TIFFIFD getDirectoryAsIFD(TIFFDirectory dir) {
}

public static TIFFTag getTag(int tagNumber, List<TIFFTagSet> tagSets) {
Iterator<TIFFTagSet> iter = tagSets.iterator();
while (iter.hasNext()) {
TIFFTagSet tagSet = iter.next();
for (TIFFTagSet tagSet : tagSets) {
TIFFTag tag = tagSet.getTag(tagNumber);
if (tag != null) {
return tag;
@@ -148,9 +146,7 @@ public static TIFFTag getTag(int tagNumber, List<TIFFTagSet> tagSets) {
}

public static TIFFTag getTag(String tagName, List<TIFFTagSet> tagSets) {
Iterator<TIFFTagSet> iter = tagSets.iterator();
while (iter.hasNext()) {
TIFFTagSet tagSet = iter.next();
for (TIFFTagSet tagSet : tagSets) {
TIFFTag tag = tagSet.getTag(tagName);
if (tag != null) {
return tag;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2020, 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
@@ -864,11 +864,7 @@ private void mergeStandardTree(Node root)
int mapSize = maxIndex + 1;
int paletteLength = 3*mapSize;
char[] paletteEntries = new char[paletteLength];
Iterator<Map.Entry<Integer,char[]>> paletteIter
= palette.entrySet().iterator();
while(paletteIter.hasNext()) {
Map.Entry<Integer,char[]> paletteEntry
= paletteIter.next();
for (Map.Entry<Integer,char[]> paletteEntry : palette.entrySet()) {
int index = paletteEntry.getKey();
char[] rgb = paletteEntry.getValue();
paletteEntries[index] =
@@ -1541,9 +1537,7 @@ public static TIFFIFD parseIFD(Node node) throws IIOInvalidTreeException {
int number = Integer.parseInt(getAttribute(node, "number"));

TIFFTagSet tagSet = null;
Iterator<TIFFTagSet> iter = tagSets.iterator();
while (iter.hasNext()) {
TIFFTagSet t = iter.next();
for (TIFFTagSet t : tagSets) {
if (t.getTag(number) != null) {
tagSet = t;
break;
@@ -1577,9 +1571,7 @@ private void mergeNativeTree(Node root) throws IIOInvalidTreeException {
TIFFIFD ifd = parseIFD(node);

List<TIFFTagSet> rootIFDTagSets = rootIFD.getTagSetList();
Iterator<TIFFTagSet> tagSetIter = ifd.getTagSetList().iterator();
while(tagSetIter.hasNext()) {
Object o = tagSetIter.next();
for (Object o : ifd.getTagSetList()) {
if(o instanceof TIFFTagSet && !rootIFDTagSets.contains(o)) {
rootIFD.addTagSet((TIFFTagSet)o);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2020, 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
@@ -458,9 +458,7 @@ private void readPdtaChunk(RIFFReader riff) throws IOException {
}
}

Iterator<SF2Layer> liter = this.layers.iterator();
while (liter.hasNext()) {
SF2Layer layer = liter.next();
for (SF2Layer layer : this.layers) {
Iterator<SF2LayerRegion> siter = layer.regions.iterator();
SF2Region globalsplit = null;
while (siter.hasNext()) {
@@ -487,9 +485,7 @@ private void readPdtaChunk(RIFFReader riff) throws IOException {
}


Iterator<SF2Instrument> iiter = this.instruments.iterator();
while (iiter.hasNext()) {
SF2Instrument instrument = iiter.next();
for (SF2Instrument instrument : this.instruments) {
Iterator<SF2InstrumentRegion> siter = instrument.regions.iterator();
SF2Region globalsplit = null;
while (siter.hasNext()) {
@@ -971,9 +971,7 @@ void dumpMarkers() {
focusLog.finest(">>> Markers dump, time: {0}", System.currentTimeMillis());
synchronized (this) {
if (typeAheadMarkers.size() != 0) {
Iterator<TypeAheadMarker> iter = typeAheadMarkers.iterator();
while (iter.hasNext()) {
TypeAheadMarker marker = iter.next();
for (TypeAheadMarker marker : typeAheadMarkers) {
focusLog.finest(" {0}", marker);
}
}
@@ -1056,9 +1056,7 @@ public void show() {
// if this dialog is toolkit-modal, the filter should be added
// to all EDTs (for all AppContexts)
if (modalityType == ModalityType.TOOLKIT_MODAL) {
Iterator<AppContext> it = AppContext.getAppContexts().iterator();
while (it.hasNext()) {
AppContext appContext = it.next();
for (AppContext appContext : AppContext.getAppContexts()) {
if (appContext == showAppContext) {
continue;
}
@@ -1086,9 +1084,7 @@ public void show() {
// if this dialog is toolkit-modal, its filter must be removed
// from all EDTs (for all AppContexts)
if (modalityType == ModalityType.TOOLKIT_MODAL) {
Iterator<AppContext> it = AppContext.getAppContexts().iterator();
while (it.hasNext()) {
AppContext appContext = it.next();
for (AppContext appContext : AppContext.getAppContexts()) {
if (appContext == showAppContext) {
continue;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2020, 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
@@ -96,9 +96,7 @@ public FilterAction acceptEvent(AWTEvent ev) {
// Move forward dispatching only if the event is previous
// in SequencedEvent.list. Otherwise, hold it for reposting later.
synchronized (SequencedEvent.class) {
Iterator<SequencedEvent> it = list.iterator();
while (it.hasNext()) {
SequencedEvent iev = it.next();
for (SequencedEvent iev : list) {
if (iev.equals(currentSequencedEvent)) {
break;
} else if (iev.equals(ev)) {
@@ -594,12 +594,11 @@ private void processPropertyDescriptors() {
PropertyDescriptor pd, gpd, spd;
IndexedPropertyDescriptor ipd, igpd, ispd;

Iterator<List<PropertyDescriptor>> it = pdStore.values().iterator();
while (it.hasNext()) {
for (List<PropertyDescriptor> propertyDescriptors : pdStore.values()) {
pd = null; gpd = null; spd = null;
ipd = null; igpd = null; ispd = null;

list = it.next();
list = propertyDescriptors;

// First pass. Find the latest getter method. Merge properties
// of previous getter methods.
@@ -511,12 +511,7 @@ void cleanupReferences() {
void revokeAllDelegatedServicesNow() {
if (serviceClasses == null) return;

Iterator<BCSSCServiceClassRef> serviceClassRefs =
new HashSet<>(serviceClasses.values()).iterator();

while (serviceClassRefs.hasNext()) {
BCSSCServiceClassRef serviceClassRef = serviceClassRefs.next();

for (BCSSCServiceClassRef serviceClassRef : new HashSet<>(serviceClasses.values())) {
if (!serviceClassRef.isDelegated()) continue;

Iterator<Map.Entry<Object, BeanContextServiceRevokedListener>> i = serviceClassRef.cloneOfEntries();
@@ -702,11 +697,7 @@ protected boolean addService(Class<?> serviceClass, BeanContextServiceProvider b
fireServiceAdded(bcssae);

synchronized(children) {
Iterator<Object> i = children.keySet().iterator();

while (i.hasNext()) {
Object c = i.next();

for (Object c : children.keySet()) {
if (c instanceof BeanContextServices) {
((BeanContextServicesListener)c).serviceAvailable(bcssae);
}
@@ -566,9 +566,8 @@ protected boolean remove(Object targetChild, boolean callChildSetBC) {
@SuppressWarnings("rawtypes")
public boolean containsAll(Collection c) {
synchronized(children) {
Iterator<?> i = c.iterator();
while (i.hasNext())
if(!contains(i.next()))
for (Object o : c)
if(!contains(o))
return false;

return true;
Loading

1 comment on commit 580af49

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 580af49 Dec 19, 2020

Please sign in to comment.