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

View File

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

View File

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

View File

@ -58,14 +58,15 @@ public class DefaultBuildPomXMLFilterFactory extends BuildToRawPomXMLFilterFacto
@Override
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
protected BiFunction<String, String, String> getDependencyKeyToVersionMapper()
{
return ( g, a ) -> Optional.ofNullable( context.getRawModel( g, a ) )
.map( m -> toVersion( m ) )
.map( DefaultBuildPomXMLFilterFactory::toVersion )
.orElse( null );
}

View File

@ -80,7 +80,7 @@ class FileToRawModelMerger extends ModelMerger
boolean sourceDominant, Map<Object, Object> context )
{
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 ) );
}
@ -124,7 +124,7 @@ class FileToRawModelMerger extends ModelMerger
Map<Object, Object> context )
{
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 ) );
}
@ -133,7 +133,7 @@ class FileToRawModelMerger extends ModelMerger
Map<Object, Object> context )
{
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 ) );
}
@ -156,7 +156,7 @@ class FileToRawModelMerger extends ModelMerger
Map<Object, Object> context )
{
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 ) );
}

View File

@ -86,16 +86,14 @@ abstract class AbstractEventXMLFilter extends AbstractSAXFilter
if ( !lockCharacters )
{
charactersSegments.stream().forEach( e ->
{
charactersSegments.forEach( e ->
saxEvents.add( () ->
{
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 ->
{
charactersSegments.forEach( e ->
saxEvents.add( () ->
{
if ( acceptEvent( eventState ) )
{
e.execute();
}
} );
} );
} ) );
charactersSegments.clear();
// not with streams due to checked SAXException

View File

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