Is this code convertible to a lambda style?

Marcos Antonio marcos_antonio_ps at hotmail.com
Sat Dec 28 06:37:09 PST 2013


Hello, Howard. Thanks for the suggestions to improve the code.

I really liked the increased abstraction by the introduction of the static hasChildAssociation() method. That really made the code more clear and readable. The tip about the findAny() method was also useful, I will change it, although I have my doubts if the introduction of a convertToPropertyOrNull() method is needed.

Thank you once again.

Marcos

________________________________
> Date: Sat, 28 Dec 2013 11:56:59 +1100 
> Subject: Re: Is this code convertible to a lambda style? 
> From: howard.lovatt at gmail.com 
> To: marcos_antonio_ps at hotmail.com 
> CC: lambda-dev at openjdk.java.net 
> 
> Hi Marcos, 
> 
> I would make some small changes: 
> 
> private static boolean hasChildAssociation(PropertyDescriptor d) { 
> return 
> DataFactory.getInstance().getMetadataReader(d.getReaderMethod().getReturnType()).getCollectionDescriptors().stream() 
> .anyMatch(c -> c.isChildAssociation(d))); 
> } 
> 
> private static Property 
> convertToPropertyOrNull(Optional<PropertyDescriptor> d) { 
> if (d.isPresent()) { 
> return d.get().convertToProperty() 
> } 
> return null; 
> } 
> 
> return getMetadataReader().getPropertyDescriptors().stream() 
> .unordered() // Assuming that order is not important 
> .parallel() // Assuming that there are a lot of Properties 
> .filter(d -> d.getType() == PropertyType.ENTITY) 
> .filter(ThisClass::hasChildAssociation) 
> .findAny() // Potentially faster 
> .map(ThisClass::convertToPropertyOrNull); 
> 
> Cheers, 
> 
> -- Howard. 		 	   		  


More information about the lambda-dev mailing list