Java Stream, How to use below code in java stream -


can 1 please me convert in java stream?

private list<string> takeallpages(long iid, string clientid, list<pagesummarylist> pages) {     issueheader issuetheader = issueapi.get(iid);     string issuesub = issueheader.getsubject();     set<string> samplepagenames = new hashset<>();     (pagesummarylist samplepage : pages) {         string entityid = "issue-" + clientid + "-doc-" + samplepage​.getname().replace(" ", "-");         list<ticktype> ticklist = ticktypeapi.gettickforentity(entitytype.dell_sop, entityid);         (ticktype​ ticktype : ticklist) {                         string tickname = ticktype​​​.getname();             if (issuesub.contains(tickname)) {                 samplepagenames​.add(samplepage.getname());             }         }     }     return lists.newarraylist(samplepagenames); } 

because did not provide every class code uses not test it, here implementation should work (or minor fixes work).

private list<string> takeallpages(long iid, string clientid, list<pagesummarylist> pages){         issueheader issuetheader = issueapi.get(iid);         string issuesub = issueheader.getsubject();          return pages.stream()                 .flatmap(sp -> {                     string entityid = "issue-" + clientid + "-doc-" + sp.getname().replace(" ", "-");                     return ticktypeapi.gettickforentity(entitytype.dell_sop, entityid).stream();                  })                 .filter(ticktype -> !issuesub.contains(ticktype.getname()))                 .collect(collectors.tolist());     } 

edit in base code there conceptions errors (i did not see details in requirements, sorry that) have made version , keep first implementation reference.

here correct code think xd (test , figure out).

private list<string> takeallpages(long iid, string clientid, list<pagesummarylist> pages){     issueheader issuetheader = issueapi.get(iid);     string issuesub = issueheader.getsubject();     // until here same code provided     // code should exact same yours using streams api.      // using @stream() method converting @pages list (list<pagesummarylist>)     // stream<pagesummarylist>, can perform various operations upon every item in list (@pages).     return pages.stream()             // firstly converting every pagesummarylist pair (javafx.util.pair if want can create own).             // pair contains pagesummarylist , corresponding stream<ticktype>, first loop.             // after map operation have stream<pair<pagesummarylist, list<ticktype>>>.             .map(sp -> {                 string entityid = "issue-" + clientid + "-doc-" + sp.getname().replace(" ", "-");                 list<ticktype> stream =  ticktypeapi.gettickforentity(entitytype.dell_sop, entityid);                 return new pair<pagesummarylist, list<ticktype>>(sp, stream);              })               // here have stream<pair<pagesummarylist, list<ticktype>>>              // , want keep list<ticktype> contains element name in @issuesub             .filter(pair -> {                 return pair.getvalue().stream()                     .filter( tp -> !issuesub.contains(tp.getname())                     .count() > 0;              })             // want names (its want stream<string> (it in someway set<string>             .map(pair -> pair.getkey().getname())             .collect(collectors.tolist()); // want return, list<string> (equal return statement. } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -