Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8258006: Replaces while cycles with iterator with enhanced for in java.desktop #1574

Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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;