java - How can I convert these streamed Map keys from Longs to Objects? -


i've current got method looks like:

public map<long, list<referraldetailsdto>> getwaiting() {         return referraldao.findall()                 .stream()                 .map(referraldetailsdto::new)                 .collect(collectors.groupingby(referraldetailsdto::getlocationid, collectors.tolist()));     } } 

it returns me map of location ids referraldetailsdto objects. however, i'd swap out location id locationdto object.

i'd have naively imagined might work:

public map<long, list<referraldetailsdto>> getwaiting() {     return referraldao.findall()             .stream()             .map(referraldetailsdto::new)             .collect(collectors.groupingby(locationdao.findbyid(referraldetailsdto::getlocationid), collectors.tolist())); } 

obviously, i'm here because doesn't - java complains findbyid method expecting long value, not method reference. suggestions how can neatly address this? in advance.

first of all, change key type of map long relevant class (is locationdto or other class?)

second of all, use lambda expression instead of method reference lookup :

public map<locationdto, list<referraldetailsdto>> getwaiting() {     return referraldao.findall()             .stream()             .map(referraldetailsdto::new)             .collect(collectors.groupingby(r -> locationdao.findbyid(r.getlocationid())); } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -