Is this code convertible to a lambda style?
Marcos Antonio
marcos_antonio_ps at hotmail.com
Tue Dec 24 07:21:08 PST 2013
I'd been trying a little more and maybe this is the solution I was looking for (I haven't tested it yet).
return getMetadataReader().getPropertyDescriptors().stream().
filter(d -> d.getType() == PropertyType.ENTITY).
filter(d -> DataFactory.getInstance().getMetadataReader(d.getReaderMethod().getReturnType()).
getCollectionDescriptors().stream().
anyMatch(c -> c.isChildAssociation(d))).
findFirst().
map(d -> d.convertToProperty()).
orElse(null);
Does it look right?
Thank you.
Marcos
----------------------------------------
> From: marcos_antonio_ps at hotmail.com
> To: lambda-dev at openjdk.java.net
> Subject: Is this code convertible to a lambda style?
> Date: Tue, 24 Dec 2013 17:48:31 +0300
>
> I'm really having trouble trying to convert this piece of code to lambda style, which makes me think if it is even possible.
>
> Property getParent()
> {
> for (PropertyDescriptor parent : getMetadataReader().getPropertyDescriptors())
> {
> if (parent.getType() == PropertyType.ENTITY)
> {
> MetadataReader metadataReader =
> DataFactory.getInstance().getMetadataReader(parent.getReaderMethod().getReturnType());
> for (CollectionDescriptor collection : metadataReader.getCollectionDescriptors())
> {
> if (collection.isChildAssociation(parent))
> {
> return parent.convertToProperty()
> }
> }
> }
> }
> return null;
> }
>
> I think this code seems very simple but in trying to convert it I'm not able to keep the reference to the parent to later methods in the stream pipeline.
>
> Any help?
>
> Thank you.
>
> Marcos
>
More information about the lambda-dev
mailing list