[MNG-7290] Java8 improvements

Closes #571
This commit is contained in:
Arturo Bernal 2021-10-08 18:08:43 +02:00 committed by Sylwester Lachiewicz
parent d61fcf7da1
commit 16afe061c9
7 changed files with 29 additions and 37 deletions

View File

@ -164,12 +164,7 @@ public class StringSearchModelInterpolator
} }
else if ( isQualifiedForInterpolation( cls ) ) else if ( isQualifiedForInterpolation( cls ) )
{ {
Field[] fields = FIELDS_BY_CLASS.get( cls ); Field[] fields = FIELDS_BY_CLASS.computeIfAbsent( cls, k -> cls.getDeclaredFields() );
if ( fields == null )
{
fields = cls.getDeclaredFields();
FIELDS_BY_CLASS.put( cls, fields );
}
for ( Field field : fields ) for ( Field field : fields )
{ {

View File

@ -133,7 +133,7 @@ public class ProfileActivation
{ {
return this.activations.entrySet().stream() return this.activations.entrySet().stream()
.filter( e -> predicate.test( e.getValue() ) ) .filter( e -> predicate.test( e.getValue() ) )
.map( e -> e.getKey() ) .map( Map.Entry::getKey )
.collect( toSet() ); .collect( toSet() );
} }

View File

@ -154,7 +154,7 @@ public class DefaultProjectDependencyGraph
private List<MavenProject> getSortedProjects( Set<String> projectIds ) private List<MavenProject> getSortedProjects( Set<String> projectIds )
{ {
return projectIds.stream() return projectIds.stream()
.map( id -> projects.get( id ) ) .map( projects::get )
.sorted( Comparator.comparingInt( order::get ) ) .sorted( Comparator.comparingInt( order::get ) )
.collect( Collectors.toList() ); .collect( Collectors.toList() );
} }

View File

@ -58,14 +58,15 @@ public class DefaultBuildPomXMLFilterFactory extends BuildToRawPomXMLFilterFacto
@Override @Override
protected Function<Path, Optional<RelativeProject>> getRelativePathMapper() protected Function<Path, Optional<RelativeProject>> getRelativePathMapper()
{ {
return p -> Optional.ofNullable( context.getRawModel( p ) ).map( m -> toRelativeProject( m ) ); return p -> Optional.ofNullable( context.getRawModel( p ) )
.map( DefaultBuildPomXMLFilterFactory::toRelativeProject );
} }
@Override @Override
protected BiFunction<String, String, String> getDependencyKeyToVersionMapper() protected BiFunction<String, String, String> getDependencyKeyToVersionMapper()
{ {
return ( g, a ) -> Optional.ofNullable( context.getRawModel( g, a ) ) return ( g, a ) -> Optional.ofNullable( context.getRawModel( g, a ) )
.map( m -> toVersion( m ) ) .map( DefaultBuildPomXMLFilterFactory::toVersion )
.orElse( null ); .orElse( null );
} }

View File

@ -80,7 +80,7 @@ class FileToRawModelMerger extends ModelMerger
boolean sourceDominant, Map<Object, Object> context ) boolean sourceDominant, Map<Object, Object> context )
{ {
Iterator<Dependency> sourceIterator = source.getDependencies().iterator(); Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant, target.getDependencies().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant,
context ) ); context ) );
} }
@ -124,7 +124,7 @@ class FileToRawModelMerger extends ModelMerger
Map<Object, Object> context ) Map<Object, Object> context )
{ {
Iterator<Profile> sourceIterator = source.getProfiles().iterator(); Iterator<Profile> sourceIterator = source.getProfiles().iterator();
target.getProfiles().stream().forEach( t -> mergeProfile( t, sourceIterator.next(), sourceDominant, target.getProfiles().forEach( t -> mergeProfile( t, sourceIterator.next(), sourceDominant,
context ) ); context ) );
} }
@ -133,7 +133,7 @@ class FileToRawModelMerger extends ModelMerger
Map<Object, Object> context ) Map<Object, Object> context )
{ {
Iterator<Dependency> sourceIterator = source.getDependencies().iterator(); Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant, target.getDependencies().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant,
context ) ); context ) );
} }
@ -156,7 +156,7 @@ class FileToRawModelMerger extends ModelMerger
Map<Object, Object> context ) Map<Object, Object> context )
{ {
Iterator<Dependency> sourceIterator = source.getDependencies().iterator(); Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
target.getDependencies().stream().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant, target.getDependencies().forEach( t -> mergeDependency( t, sourceIterator.next(), sourceDominant,
context ) ); context ) );
} }

View File

@ -86,16 +86,14 @@ abstract class AbstractEventXMLFilter extends AbstractSAXFilter
if ( !lockCharacters ) if ( !lockCharacters )
{ {
charactersSegments.stream().forEach( e -> charactersSegments.forEach( e ->
{
saxEvents.add( () -> saxEvents.add( () ->
{ {
if ( acceptEvent( eventState ) ) if ( acceptEvent( eventState ) )
{ {
e.execute(); e.execute();
} }
} ); } ) );
} );
charactersSegments.clear(); charactersSegments.clear();
} }
@ -127,16 +125,14 @@ abstract class AbstractEventXMLFilter extends AbstractSAXFilter
protected final void executeEvents() throws SAXException protected final void executeEvents() throws SAXException
{ {
final String eventState = getState(); final String eventState = getState();
charactersSegments.stream().forEach( e -> charactersSegments.forEach( e ->
{
saxEvents.add( () -> saxEvents.add( () ->
{ {
if ( acceptEvent( eventState ) ) if ( acceptEvent( eventState ) )
{ {
e.execute(); e.execute();
} }
} ); } ) );
} );
charactersSegments.clear(); charactersSegments.clear();
// not with streams due to checked SAXException // not with streams due to checked SAXException

View File

@ -51,7 +51,7 @@ public final class SAXEventFactory
public SAXEvent endDocument() public SAXEvent endDocument()
{ {
return () -> contentHandler.endDocument(); return contentHandler::endDocument;
} }
public SAXEvent endElement( final String uri, final String localName, final String qName ) public SAXEvent endElement( final String uri, final String localName, final String qName )
@ -86,7 +86,7 @@ public final class SAXEventFactory
public SAXEvent startDocument() public SAXEvent startDocument()
{ {
return () -> contentHandler.startDocument(); return contentHandler::startDocument;
} }
public SAXEvent startElement( final String uri, final String localName, final String qName, final Attributes atts ) 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() public SAXEvent endDTD()
{ {
return () -> lexicalHandler.endDTD(); return lexicalHandler::endDTD;
} }
public SAXEvent startEntity( String name ) public SAXEvent startEntity( String name )
@ -127,12 +127,12 @@ public final class SAXEventFactory
public SAXEvent startCDATA() public SAXEvent startCDATA()
{ {
return () -> lexicalHandler.startCDATA(); return lexicalHandler::startCDATA;
} }
public SAXEvent endCDATA() public SAXEvent endCDATA()
{ {
return () -> lexicalHandler.endCDATA(); return lexicalHandler::endCDATA;
} }
public SAXEvent comment( char[] ch, int start, int length ) public SAXEvent comment( char[] ch, int start, int length )