Path: csiph.com!news.bbs.geek.nz!.POSTED.agency.bbs.geek.nz!not-for-mail From: Eric Douglas (Eric Douglas) Newsgroups: comp.lang.java.programmer Subject: Re: Can I put a filter into a lambda? Date: Mon, 04 Dec 2017 05:03:56 +1200 Organization: fsxNet Usenet Gateway | bbs.geek.nz/#fsxNet Message-ID: <4175562947@f38.n261.z1.binkp.net> References: <282294394@f38.n261.z1.binkp.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: news.bbs.geek.nz; posting-host="M6YmRdZYyc42DJk0lNlt/X4dpP4dzvceBNabSmESN3E"; logging-data="25937"; mail-complaints-to="abuse@news.bbs.geek.nz" User-Agent: VSoup v1.2.9.47Beta [95/NT] X-MailConverter: SoupGate-Win32 v1.05 X-Comment-To: Eric Sosman Xref: csiph.com comp.lang.java.programmer:37748 On Friday, December 1, 2017 at 4:28:26 PM UTC-5, Eric Sosman wrote: > It's not clear what your filter loop is actually doing: > the RowFilter seems never to be used, and I can't find any > one-argument include() method in any Java SE (8 or 9) class. > (You also haven't shown what rowToModelIndex is, but I'll > guess it's a Collection, possibly List). > So I'll restate the problem without the table trappings: > > 1) If getRowFilter() returns null, you want a List of > all the values 0 through modelRowCount-1, in order. > > 2) If getRowFilter() returns non-null, you want a List > of the same values, excluding those for which the > boolean-valued include(int) method returns false. > > If that's not the goal, read no further. But if it is > (or is close enough for jazz), both cases can be written > more simply: > > // Case 1: > rowModelIndex = IntStream.range(0, modelRowCount) > .mapToObj(Integer::valueOf) > .collect(Collectors.toList()); > > // Case 2: > rowModelIndex = IntStream.range(0, modelRowCount) > .filter((value) -> include(value)) > .mapToObj(Integer::valueOf) > .collect(Collectors.toList()); > > Final point: If you can't stop worrying about efficiency, > at the very least stop *guessing* about it! > rowToModelIndex is an ArrayList. Yes the include method says if the row filter is null then include every row number, if not null then include rows based on the boolean value from the row filter include method. Milliseconds do count in a row filtering method which executes thousands of times.