diff --git a/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java b/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java index 553874ce4b..8dc8784b12 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java +++ b/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java @@ -164,12 +164,7 @@ public class StringSearchModelInterpolator } else if ( isQualifiedForInterpolation( cls ) ) { - Field[] fields = FIELDS_BY_CLASS.get( cls ); - if ( fields == null ) - { - fields = cls.getDeclaredFields(); - FIELDS_BY_CLASS.put( cls, fields ); - } + Field[] fields = FIELDS_BY_CLASS.computeIfAbsent( cls, k -> cls.getDeclaredFields() ); for ( Field field : fields ) { diff --git a/maven-core/src/main/java/org/apache/maven/execution/ProfileActivation.java b/maven-core/src/main/java/org/apache/maven/execution/ProfileActivation.java index 52f5e06a91..ad00a74054 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/ProfileActivation.java +++ b/maven-core/src/main/java/org/apache/maven/execution/ProfileActivation.java @@ -133,7 +133,7 @@ public class ProfileActivation { return this.activations.entrySet().stream() .filter( e -> predicate.test( e.getValue() ) ) - .map( e -> e.getKey() ) + .map( Map.Entry::getKey ) .collect( toSet() ); } diff --git a/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java b/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java index 1f422937b1..5216988170 100644 --- a/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java +++ b/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java @@ -154,7 +154,7 @@ public class DefaultProjectDependencyGraph private List getSortedProjects( Set projectIds ) { return projectIds.stream() - .map( id -> projects.get( id ) ) + .map( projects::get ) .sorted( Comparator.comparingInt( order::get ) ) .collect( Collectors.toList() ); } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultBuildPomXMLFilterFactory.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultBuildPomXMLFilterFactory.java index 906584d5a7..d22eaacf0e 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultBuildPomXMLFilterFactory.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultBuildPomXMLFilterFactory.java @@ -58,14 +58,15 @@ public class DefaultBuildPomXMLFilterFactory extends BuildToRawPomXMLFilterFacto @Override protected Function> getRelativePathMapper() { - return p -> Optional.ofNullable( context.getRawModel( p ) ).map( m -> toRelativeProject( m ) ); + return p -> Optional.ofNullable( context.getRawModel( p ) ) + .map( DefaultBuildPomXMLFilterFactory::toRelativeProject ); } @Override protected BiFunction getDependencyKeyToVersionMapper() { return ( g, a ) -> Optional.ofNullable( context.getRawModel( g, a ) ) - .map( m -> toVersion( m ) ) + .map( DefaultBuildPomXMLFilterFactory::toVersion ) .orElse( null ); } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/FileToRawModelMerger.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/FileToRawModelMerger.java index f697d771d0..47af900a9a 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/FileToRawModelMerger.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/FileToRawModelMerger.java @@ -80,7 +80,7 @@ class FileToRawModelMerger extends ModelMerger boolean sourceDominant, Map context ) { Iterator sourceIterator = source.getDependencies().iterator(); - target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant, + target.getDependencies().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant, context ) ); } @@ -124,7 +124,7 @@ class FileToRawModelMerger extends ModelMerger Map context ) { Iterator sourceIterator = source.getProfiles().iterator(); - target.getProfiles().stream().forEach( t -> mergeProfile( t, sourceIterator.next(), sourceDominant, + target.getProfiles().forEach( t -> mergeProfile( t, sourceIterator.next(), sourceDominant, context ) ); } @@ -133,7 +133,7 @@ class FileToRawModelMerger extends ModelMerger Map context ) { Iterator sourceIterator = source.getDependencies().iterator(); - target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant, + target.getDependencies().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant, context ) ); } @@ -156,7 +156,7 @@ class FileToRawModelMerger extends ModelMerger Map context ) { Iterator sourceIterator = source.getDependencies().iterator(); - target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant, + target.getDependencies().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant, context ) ); } diff --git a/maven-model-transform/src/main/java/org/apache/maven/model/transform/AbstractEventXMLFilter.java b/maven-model-transform/src/main/java/org/apache/maven/model/transform/AbstractEventXMLFilter.java index 7264145605..711845f5a6 100644 --- a/maven-model-transform/src/main/java/org/apache/maven/model/transform/AbstractEventXMLFilter.java +++ b/maven-model-transform/src/main/java/org/apache/maven/model/transform/AbstractEventXMLFilter.java @@ -86,16 +86,14 @@ abstract class AbstractEventXMLFilter extends AbstractSAXFilter if ( !lockCharacters ) { - charactersSegments.stream().forEach( e -> - { - saxEvents.add( () -> - { - if ( acceptEvent( eventState ) ) + charactersSegments.forEach( e -> + saxEvents.add( () -> { - e.execute(); - } - } ); - } ); + if ( acceptEvent( eventState ) ) + { + e.execute(); + } + } ) ); charactersSegments.clear(); } @@ -127,16 +125,14 @@ abstract class AbstractEventXMLFilter extends AbstractSAXFilter protected final void executeEvents() throws SAXException { final String eventState = getState(); - charactersSegments.stream().forEach( e -> - { - saxEvents.add( () -> - { - if ( acceptEvent( eventState ) ) + charactersSegments.forEach( e -> + saxEvents.add( () -> { - e.execute(); - } - } ); - } ); + if ( acceptEvent( eventState ) ) + { + e.execute(); + } + } ) ); charactersSegments.clear(); // not with streams due to checked SAXException diff --git a/maven-model-transform/src/main/java/org/apache/maven/model/transform/sax/SAXEventFactory.java b/maven-model-transform/src/main/java/org/apache/maven/model/transform/sax/SAXEventFactory.java index 8625762e24..c9ae4864cb 100644 --- a/maven-model-transform/src/main/java/org/apache/maven/model/transform/sax/SAXEventFactory.java +++ b/maven-model-transform/src/main/java/org/apache/maven/model/transform/sax/SAXEventFactory.java @@ -51,7 +51,7 @@ public final class SAXEventFactory public SAXEvent endDocument() { - return () -> contentHandler.endDocument(); + return contentHandler::endDocument; } public SAXEvent endElement( final String uri, final String localName, final String qName ) @@ -86,7 +86,7 @@ public final class SAXEventFactory public SAXEvent startDocument() { - return () -> contentHandler.startDocument(); + return contentHandler::startDocument; } public SAXEvent startElement( final String uri, final String localName, final String qName, final Attributes atts ) @@ -111,7 +111,7 @@ public final class SAXEventFactory public SAXEvent endDTD() { - return () -> lexicalHandler.endDTD(); + return lexicalHandler::endDTD; } public SAXEvent startEntity( String name ) @@ -127,12 +127,12 @@ public final class SAXEventFactory public SAXEvent startCDATA() { - return () -> lexicalHandler.startCDATA(); + return lexicalHandler::startCDATA; } public SAXEvent endCDATA() { - return () -> lexicalHandler.endCDATA(); + return lexicalHandler::endCDATA; } public SAXEvent comment( char[] ch, int start, int length )