mirror of https://github.com/apache/maven.git
[MNG-6855] Simplify code - computeIfAbsent()
This commit is contained in:
parent
1697e7a06b
commit
ace32fdbe0
|
@ -396,13 +396,7 @@ public class LegacyRepositorySystem
|
||||||
{
|
{
|
||||||
String key = repository.getId();
|
String key = repository.getId();
|
||||||
|
|
||||||
List<ArtifactRepository> aliasedRepos = reposByKey.get( key );
|
List<ArtifactRepository> aliasedRepos = reposByKey.computeIfAbsent( key, k -> new ArrayList<>() );
|
||||||
|
|
||||||
if ( aliasedRepos == null )
|
|
||||||
{
|
|
||||||
aliasedRepos = new ArrayList<>();
|
|
||||||
reposByKey.put( key, aliasedRepos );
|
|
||||||
}
|
|
||||||
|
|
||||||
aliasedRepos.add( repository );
|
aliasedRepos.add( repository );
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,24 +331,14 @@ public class MetadataGraph
|
||||||
vFrom.setCompareVersion( versionedVertices );
|
vFrom.setCompareVersion( versionedVertices );
|
||||||
vFrom.setCompareScope( scopedVertices );
|
vFrom.setCompareScope( scopedVertices );
|
||||||
|
|
||||||
List<MetadataGraphEdge> exList = excidentEdges.get( vFrom );
|
List<MetadataGraphEdge> exList = excidentEdges.computeIfAbsent( vFrom, k -> new ArrayList<>() );
|
||||||
if ( exList == null )
|
|
||||||
{
|
|
||||||
exList = new ArrayList<>();
|
|
||||||
excidentEdges.put( vFrom, exList );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !exList.contains( e ) )
|
if ( !exList.contains( e ) )
|
||||||
{
|
{
|
||||||
exList.add( e );
|
exList.add( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MetadataGraphEdge> inList = incidentEdges.get( vTo );
|
List<MetadataGraphEdge> inList = incidentEdges.computeIfAbsent( vTo, k -> new ArrayList<>() );
|
||||||
if ( inList == null )
|
|
||||||
{
|
|
||||||
inList = new ArrayList<>();
|
|
||||||
incidentEdges.put( vTo, inList );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !inList.contains( e ) )
|
if ( !inList.contains( e ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -73,13 +73,7 @@ class ReactorReader
|
||||||
{
|
{
|
||||||
String key = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
String key = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
||||||
|
|
||||||
List<MavenProject> projects = projectsByGA.get( key );
|
List<MavenProject> projects = projectsByGA.computeIfAbsent( key, k -> new ArrayList<>( 1 ) );
|
||||||
|
|
||||||
if ( projects == null )
|
|
||||||
{
|
|
||||||
projects = new ArrayList<>( 1 );
|
|
||||||
projectsByGA.put( key, projects );
|
|
||||||
}
|
|
||||||
|
|
||||||
projects.add( project );
|
projects.add( project );
|
||||||
}
|
}
|
||||||
|
|
|
@ -621,13 +621,7 @@ public class MavenRepositorySystem
|
||||||
{
|
{
|
||||||
String key = repository.getId();
|
String key = repository.getId();
|
||||||
|
|
||||||
List<ArtifactRepository> aliasedRepos = reposByKey.get( key );
|
List<ArtifactRepository> aliasedRepos = reposByKey.computeIfAbsent( key, k -> new ArrayList<>() );
|
||||||
|
|
||||||
if ( aliasedRepos == null )
|
|
||||||
{
|
|
||||||
aliasedRepos = new ArrayList<>();
|
|
||||||
reposByKey.put( key, aliasedRepos );
|
|
||||||
}
|
|
||||||
|
|
||||||
aliasedRepos.add( repository );
|
aliasedRepos.add( repository );
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,23 +70,10 @@ public class ReactorManager
|
||||||
|
|
||||||
public Map getPluginContext( PluginDescriptor plugin, MavenProject project )
|
public Map getPluginContext( PluginDescriptor plugin, MavenProject project )
|
||||||
{
|
{
|
||||||
Map<String, Map> pluginContextsByKey = pluginContextsByProjectAndPluginKey.get( project.getId() );
|
Map<String, Map> pluginContextsByKey =
|
||||||
|
pluginContextsByProjectAndPluginKey.computeIfAbsent( project.getId(), k -> new HashMap<>() );
|
||||||
|
|
||||||
if ( pluginContextsByKey == null )
|
return pluginContextsByKey.computeIfAbsent( plugin.getPluginLookupKey(), k -> new HashMap<>() );
|
||||||
{
|
|
||||||
pluginContextsByKey = new HashMap<>();
|
|
||||||
pluginContextsByProjectAndPluginKey.put( project.getId(), pluginContextsByKey );
|
|
||||||
}
|
|
||||||
|
|
||||||
Map pluginContext = pluginContextsByKey.get( plugin.getPluginLookupKey() );
|
|
||||||
|
|
||||||
if ( pluginContext == null )
|
|
||||||
{
|
|
||||||
pluginContext = new HashMap<>();
|
|
||||||
pluginContextsByKey.put( plugin.getPluginLookupKey(), pluginContext );
|
|
||||||
}
|
|
||||||
|
|
||||||
return pluginContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFailureBehavior( String failureBehavior )
|
public void setFailureBehavior( String failureBehavior )
|
||||||
|
|
|
@ -149,13 +149,7 @@ public class DefaultLifecycleMappingDelegate
|
||||||
private void addMojoExecution( Map<Integer, List<MojoExecution>> phaseBindings, MojoExecution mojoExecution,
|
private void addMojoExecution( Map<Integer, List<MojoExecution>> phaseBindings, MojoExecution mojoExecution,
|
||||||
int priority )
|
int priority )
|
||||||
{
|
{
|
||||||
List<MojoExecution> mojoExecutions = phaseBindings.get( priority );
|
List<MojoExecution> mojoExecutions = phaseBindings.computeIfAbsent( priority, k -> new ArrayList<>() );
|
||||||
|
|
||||||
if ( mojoExecutions == null )
|
|
||||||
{
|
|
||||||
mojoExecutions = new ArrayList<>();
|
|
||||||
phaseBindings.put( priority, mojoExecutions );
|
|
||||||
}
|
|
||||||
|
|
||||||
mojoExecutions.add( mojoExecution );
|
mojoExecutions.add( mojoExecution );
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,12 +99,8 @@ public class ProjectSorter
|
||||||
|
|
||||||
String projectKey = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
String projectKey = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
||||||
|
|
||||||
Map<String, Vertex> vertices = vertexMap.get( projectKey );
|
Map<String, Vertex> vertices = vertexMap.computeIfAbsent( projectKey, k -> new HashMap<>( 2, 1 ) );
|
||||||
if ( vertices == null )
|
|
||||||
{
|
|
||||||
vertices = new HashMap<>( 2, 1 );
|
|
||||||
vertexMap.put( projectKey, vertices );
|
|
||||||
}
|
|
||||||
vertices.put( project.getVersion(), dag.addVertex( projectId ) );
|
vertices.put( project.getVersion(), dag.addVertex( projectId ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -708,10 +708,7 @@ public class DefaultModelBuilder
|
||||||
for ( Plugin plugin : mgmt.getPlugins() )
|
for ( Plugin plugin : mgmt.getPlugins() )
|
||||||
{
|
{
|
||||||
String key = plugin.getKey();
|
String key = plugin.getKey();
|
||||||
if ( managedVersions.get( key ) == null )
|
managedVersions.computeIfAbsent( key, k -> plugin.getVersion() );
|
||||||
{
|
|
||||||
managedVersions.put( key, plugin.getVersion() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue