Use for each

This commit is contained in:
Stephen Connolly 2014-01-06 10:30:42 +00:00
parent 3480789f18
commit 71f73b29fa
3 changed files with 31 additions and 40 deletions

View File

@ -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<ReportPlugin> parentPlugins = parent.getPlugins();
if ( ( parentPlugins != null ) && !parentPlugins.isEmpty() )
{
Map assembledPlugins = new TreeMap();
Map<String, ReportPlugin> assembledPlugins = new TreeMap<String, ReportPlugin>();
Map childPlugins = child.getReportPluginsAsMap();
Map<String, ReportPlugin> 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<ReportPlugin>( 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<String> parentReports = parent.getReports();
List<String> childReports = child.getReports();
List reports = new ArrayList();
List<String> reports = new ArrayList<String>();
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<ReportSet> parentReportSets = parent.getReportSets();
if ( ( parentReportSets != null ) && !parentReportSets.isEmpty() )
{
Map assembledReportSets = new TreeMap();
Map<String, ReportSet> assembledReportSets = new TreeMap<String, ReportSet>();
Map childReportSets = child.getReportSetsAsMap();
Map<String, ReportSet> 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<String, ReportSet> 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<ReportSet>( assembledReportSets.values() ) );
child.flushReportSetMap();
}

View File

@ -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 );

View File

@ -116,7 +116,7 @@ public class ProjectInheritanceTest
assertEquals( "4.0.0", project4.getModelVersion() );
Build build = project4.getBuild();
List plugins = build.getPlugins();
List<Plugin> 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 );
}
}