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();
|
||||
|
||||
List<ArtifactRepository> aliasedRepos = reposByKey.get( key );
|
||||
|
||||
if ( aliasedRepos == null )
|
||||
{
|
||||
aliasedRepos = new ArrayList<>();
|
||||
reposByKey.put( key, aliasedRepos );
|
||||
}
|
||||
List<ArtifactRepository> aliasedRepos = reposByKey.computeIfAbsent( key, k -> new ArrayList<>() );
|
||||
|
||||
aliasedRepos.add( repository );
|
||||
}
|
||||
|
|
|
@ -331,24 +331,14 @@ public class MetadataGraph
|
|||
vFrom.setCompareVersion( versionedVertices );
|
||||
vFrom.setCompareScope( scopedVertices );
|
||||
|
||||
List<MetadataGraphEdge> exList = excidentEdges.get( vFrom );
|
||||
if ( exList == null )
|
||||
{
|
||||
exList = new ArrayList<>();
|
||||
excidentEdges.put( vFrom, exList );
|
||||
}
|
||||
List<MetadataGraphEdge> exList = excidentEdges.computeIfAbsent( vFrom, k -> new ArrayList<>() );
|
||||
|
||||
if ( !exList.contains( e ) )
|
||||
{
|
||||
exList.add( e );
|
||||
}
|
||||
|
||||
List<MetadataGraphEdge> inList = incidentEdges.get( vTo );
|
||||
if ( inList == null )
|
||||
{
|
||||
inList = new ArrayList<>();
|
||||
incidentEdges.put( vTo, inList );
|
||||
}
|
||||
List<MetadataGraphEdge> inList = incidentEdges.computeIfAbsent( vTo, k -> new ArrayList<>() );
|
||||
|
||||
if ( !inList.contains( e ) )
|
||||
{
|
||||
|
|
|
@ -73,13 +73,7 @@ class ReactorReader
|
|||
{
|
||||
String key = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
||||
|
||||
List<MavenProject> projects = projectsByGA.get( key );
|
||||
|
||||
if ( projects == null )
|
||||
{
|
||||
projects = new ArrayList<>( 1 );
|
||||
projectsByGA.put( key, projects );
|
||||
}
|
||||
List<MavenProject> projects = projectsByGA.computeIfAbsent( key, k -> new ArrayList<>( 1 ) );
|
||||
|
||||
projects.add( project );
|
||||
}
|
||||
|
|
|
@ -621,13 +621,7 @@ public class MavenRepositorySystem
|
|||
{
|
||||
String key = repository.getId();
|
||||
|
||||
List<ArtifactRepository> aliasedRepos = reposByKey.get( key );
|
||||
|
||||
if ( aliasedRepos == null )
|
||||
{
|
||||
aliasedRepos = new ArrayList<>();
|
||||
reposByKey.put( key, aliasedRepos );
|
||||
}
|
||||
List<ArtifactRepository> aliasedRepos = reposByKey.computeIfAbsent( key, k -> new ArrayList<>() );
|
||||
|
||||
aliasedRepos.add( repository );
|
||||
}
|
||||
|
|
|
@ -70,23 +70,10 @@ public class ReactorManager
|
|||
|
||||
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 )
|
||||
{
|
||||
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;
|
||||
return pluginContextsByKey.computeIfAbsent( plugin.getPluginLookupKey(), k -> new HashMap<>() );
|
||||
}
|
||||
|
||||
public void setFailureBehavior( String failureBehavior )
|
||||
|
|
|
@ -149,13 +149,7 @@ public class DefaultLifecycleMappingDelegate
|
|||
private void addMojoExecution( Map<Integer, List<MojoExecution>> phaseBindings, MojoExecution mojoExecution,
|
||||
int priority )
|
||||
{
|
||||
List<MojoExecution> mojoExecutions = phaseBindings.get( priority );
|
||||
|
||||
if ( mojoExecutions == null )
|
||||
{
|
||||
mojoExecutions = new ArrayList<>();
|
||||
phaseBindings.put( priority, mojoExecutions );
|
||||
}
|
||||
List<MojoExecution> mojoExecutions = phaseBindings.computeIfAbsent( priority, k -> new ArrayList<>() );
|
||||
|
||||
mojoExecutions.add( mojoExecution );
|
||||
}
|
||||
|
|
|
@ -99,12 +99,8 @@ public class ProjectSorter
|
|||
|
||||
String projectKey = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
||||
|
||||
Map<String, Vertex> vertices = vertexMap.get( projectKey );
|
||||
if ( vertices == null )
|
||||
{
|
||||
vertices = new HashMap<>( 2, 1 );
|
||||
vertexMap.put( projectKey, vertices );
|
||||
}
|
||||
Map<String, Vertex> vertices = vertexMap.computeIfAbsent( projectKey, k -> new HashMap<>( 2, 1 ) );
|
||||
|
||||
vertices.put( project.getVersion(), dag.addVertex( projectId ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -708,10 +708,7 @@ public class DefaultModelBuilder
|
|||
for ( Plugin plugin : mgmt.getPlugins() )
|
||||
{
|
||||
String key = plugin.getKey();
|
||||
if ( managedVersions.get( key ) == null )
|
||||
{
|
||||
managedVersions.put( key, plugin.getVersion() );
|
||||
}
|
||||
managedVersions.computeIfAbsent( key, k -> plugin.getVersion() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue