Skip to content

Commit

Permalink
[MNG-7290] Java8 improvements
Browse files Browse the repository at this point in the history
Closes #571
  • Loading branch information
arturobernalg authored and slachiewicz committed Oct 10, 2021
1 parent d61fcf7 commit 16afe06
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,7 @@ private void traverseObjectWithParents( Class<?> cls, Object target )
}
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 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private Set<String> getProfileIds( final Predicate<ActivationSettings> predicate
{
return this.activations.entrySet().stream()
.filter( e -> predicate.test( e.getValue() ) )
.map( e -> e.getKey() )
.map( Map.Entry::getKey )
.collect( toSet() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private void getUpstreamProjects( String projectId, Collection<String> projectId
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() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ public DefaultBuildPomXMLFilterFactory( TransformerContext context,
@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 );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected void mergeDependencyManagement_Dependencies( DependencyManagement targ
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 ) );
}

Expand Down Expand Up @@ -124,7 +124,7 @@ protected void mergeModel_Profiles( Model target, Model source, boolean sourceDo
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 ) );
}

Expand All @@ -133,7 +133,7 @@ protected void mergeModelBase_Dependencies( ModelBase target, ModelBase source,
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 ) );
}

Expand All @@ -156,7 +156,7 @@ protected void mergePlugin_Dependencies( Plugin target, Plugin source, boolean s
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 ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,14 @@ private void processEvent( final SAXEvent event )

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

Expand Down Expand Up @@ -127,16 +125,14 @@ protected Includer include()
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SAXEvent characters( final char[] ch, final int start, final int length )

public SAXEvent endDocument()
{
return () -> contentHandler.endDocument();
return contentHandler::endDocument;
}

public SAXEvent endElement( final String uri, final String localName, final String qName )
Expand Down Expand Up @@ -86,7 +86,7 @@ public SAXEvent skippedEntity( final String name )

public SAXEvent startDocument()
{
return () -> contentHandler.startDocument();
return contentHandler::startDocument;
}

public SAXEvent startElement( final String uri, final String localName, final String qName, final Attributes atts )
Expand All @@ -111,7 +111,7 @@ public SAXEvent startDTD( String name, String publicId, String systemId )

public SAXEvent endDTD()
{
return () -> lexicalHandler.endDTD();
return lexicalHandler::endDTD;
}

public SAXEvent startEntity( String name )
Expand All @@ -127,12 +127,12 @@ public SAXEvent endEntity( String name )

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 )
Expand Down

0 comments on commit 16afe06

Please sign in to comment.