From 71f73b29fa90b78f12a7742fbf713d8a83400316 Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Mon, 6 Jan 2014 10:30:42 +0000 Subject: [PATCH] Use for each --- .../DefaultModelInheritanceAssembler.java | 49 ++++++++----------- .../resolver/DefaultArtifactResolverTest.java | 6 +-- .../t02/ProjectInheritanceTest.java | 16 +++--- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java b/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java index ec04f34a43..4b08eb967e 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java +++ b/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java @@ -20,6 +20,7 @@ package org.apache.maven.project.inheritance; */ import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -372,18 +373,16 @@ public class DefaultModelInheritanceAssembler return; } - List parentPlugins = parent.getPlugins(); + List parentPlugins = parent.getPlugins(); if ( ( parentPlugins != null ) && !parentPlugins.isEmpty() ) { - Map assembledPlugins = new TreeMap(); + Map assembledPlugins = new TreeMap(); - Map childPlugins = child.getReportPluginsAsMap(); + Map childPlugins = child.getReportPluginsAsMap(); - for ( Object parentPlugin1 : parentPlugins ) + for ( ReportPlugin parentPlugin : parentPlugins ) { - ReportPlugin parentPlugin = (ReportPlugin) parentPlugin1; - String parentInherited = parentPlugin.getInherited(); if ( !handleAsInheritance || ( parentInherited == null ) || Boolean.valueOf( parentInherited ) ) @@ -391,7 +390,7 @@ public class DefaultModelInheritanceAssembler ReportPlugin assembledPlugin = parentPlugin; - ReportPlugin childPlugin = (ReportPlugin) childPlugins.get( parentPlugin.getKey() ); + ReportPlugin childPlugin = childPlugins.get( parentPlugin.getKey() ); if ( childPlugin != null ) { @@ -409,17 +408,15 @@ public class DefaultModelInheritanceAssembler } } - for ( Iterator it = childPlugins.values().iterator(); it.hasNext(); ) + for ( ReportPlugin childPlugin : childPlugins.values() ) { - ReportPlugin childPlugin = (ReportPlugin) it.next(); - if ( !assembledPlugins.containsKey( childPlugin.getKey() ) ) { assembledPlugins.put( childPlugin.getKey(), childPlugin ); } } - child.setPlugins( new ArrayList( assembledPlugins.values() ) ); + child.setPlugins( new ArrayList( assembledPlugins.values() ) ); child.flushReportPluginMap(); } @@ -427,10 +424,10 @@ public class DefaultModelInheritanceAssembler private static void mergeReportSetDefinitions( ReportSet child, ReportSet parent ) { - List parentReports = parent.getReports(); - List childReports = child.getReports(); + List parentReports = parent.getReports(); + List childReports = child.getReports(); - List reports = new ArrayList(); + List reports = new ArrayList(); if ( ( childReports != null ) && !childReports.isEmpty() ) { @@ -439,10 +436,8 @@ public class DefaultModelInheritanceAssembler if ( parentReports != null ) { - for ( Iterator i = parentReports.iterator(); i.hasNext(); ) + for ( String report : parentReports ) { - String report = (String) i.next(); - if ( !reports.contains( report ) ) { reports.add( report ); @@ -480,23 +475,23 @@ public class DefaultModelInheritanceAssembler boolean parentIsInherited = ( parentInherited == null ) || Boolean.valueOf( parentInherited ); - List parentReportSets = parent.getReportSets(); + List parentReportSets = parent.getReportSets(); if ( ( parentReportSets != null ) && !parentReportSets.isEmpty() ) { - Map assembledReportSets = new TreeMap(); + Map assembledReportSets = new TreeMap(); - Map childReportSets = child.getReportSetsAsMap(); + Map childReportSets = child.getReportSetsAsMap(); - for ( Iterator it = parentReportSets.iterator(); it.hasNext(); ) + for ( Object parentReportSet1 : parentReportSets ) { - ReportSet parentReportSet = (ReportSet) it.next(); + ReportSet parentReportSet = (ReportSet) parentReportSet1; if ( !handleAsInheritance || parentIsInherited ) { ReportSet assembledReportSet = parentReportSet; - ReportSet childReportSet = (ReportSet) childReportSets.get( parentReportSet.getId() ); + ReportSet childReportSet = childReportSets.get( parentReportSet.getId() ); if ( childReportSet != null ) { @@ -513,11 +508,9 @@ public class DefaultModelInheritanceAssembler } } - for ( Iterator it = childReportSets.entrySet().iterator(); it.hasNext(); ) + for ( Map.Entry entry : childReportSets.entrySet() ) { - Map.Entry entry = (Map.Entry) it.next(); - - String id = (String) entry.getKey(); + String id = entry.getKey(); if ( !assembledReportSets.containsKey( id ) ) { @@ -525,7 +518,7 @@ public class DefaultModelInheritanceAssembler } } - child.setReportSets( new ArrayList( assembledReportSets.values() ) ); + child.setReportSets( new ArrayList( assembledReportSets.values() ) ); child.flushReportSetMap(); } diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java index 40d94c2052..914d9d1c3f 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java @@ -78,16 +78,16 @@ public class DefaultArtifactResolverTest boolean seen = false; - for ( int i = 0; i < tgList.length; i++ ) + for ( ThreadGroup aTgList : tgList ) { - if ( !tgList[i].getName().equals( DaemonThreadCreator.THREADGROUP_NAME ) ) + if ( !aTgList.getName().equals( DaemonThreadCreator.THREADGROUP_NAME ) ) { continue; } seen = true; - tg = tgList[i]; + tg = aTgList; Thread[] ts = new Thread[tg.activeCount()]; tg.enumerate( ts ); diff --git a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java index 2bcf7b57c5..808f8f0742 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java @@ -116,7 +116,7 @@ public class ProjectInheritanceTest assertEquals( "4.0.0", project4.getModelVersion() ); Build build = project4.getBuild(); - List plugins = build.getPlugins(); + List plugins = build.getPlugins(); Map validPluginCounts = new HashMap(); @@ -131,13 +131,11 @@ public class ProjectInheritanceTest validPluginCounts.put( "maven-source-plugin", 0 ); Plugin testPlugin = null; - - for ( Iterator it = plugins.iterator(); it.hasNext(); ) + + for ( Plugin plugin : plugins ) { - Plugin plugin = (Plugin) it.next(); - String pluginArtifactId = plugin.getArtifactId(); - + if ( !validPluginCounts.containsKey( pluginArtifactId ) ) { fail( "Illegal plugin found: " + pluginArtifactId ); @@ -148,9 +146,9 @@ public class ProjectInheritanceTest { testPlugin = plugin; } - + Integer count = (Integer) validPluginCounts.get( pluginArtifactId ); - + if ( count.intValue() > 0 ) { fail( "Multiple copies of plugin: " + pluginArtifactId + " found in POM." ); @@ -158,7 +156,7 @@ public class ProjectInheritanceTest else { count = count.intValue() + 1; - + validPluginCounts.put( pluginArtifactId, count ); } }