[MNG-6855] Simplify code - computeIfAbsent()

This commit is contained in:
Sylwester Lachiewicz 2020-01-25 21:10:01 +01:00
parent 1697e7a06b
commit ace32fdbe0
8 changed files with 12 additions and 66 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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