Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37712

Re: Can I put a filter into a lambda?

Newsgroups comp.lang.java.programmer
Date 2017-12-04 05:03 -0800
References <321ee28f-bbea-4565-a48e-c0476d9a78d4@googlegroups.com> <ovshh6$8q1$1@dont-email.me>
Message-ID <a7f8b0f0-79cb-4f83-bf77-2ce7d94a2a19@googlegroups.com> (permalink)
Subject Re: Can I put a filter into a lambda?
From Eric Douglas <e.d.programmer@gmail.com>

Show all headers | View raw


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<Integer>, possibly List<Integer>).
> 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<Integer>.

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.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Can I put a filter into a lambda? Eric Douglas <e.d.programmer@gmail.com> - 2017-12-01 12:52 -0800
  Re: Can I put a filter into a lambda? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-12-01 16:28 -0500
    Re: Can I put a filter into a lambda? Eric Douglas <e.d.programmer@gmail.com> - 2017-12-04 05:03 -0800
      Re: Can I put a filter into a lambda? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-12-04 08:20 -0500
        Re: Can I put a filter into a lambda? Eric Douglas <e.d.programmer@gmail.com> - 2017-12-04 05:32 -0800
          Re: Can I put a filter into a lambda? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-12-04 09:29 -0500
            Re: Can I put a filter into a lambda? Eric Douglas <e.d.programmer@gmail.com> - 2017-12-04 07:14 -0800
            Re: Can I put a filter into a lambda? Sebastian <nowhere@nirvana.org> - 2017-12-08 15:00 +0100

csiph-web