Stream reuse in superclass (original) (raw)

Jose jgetino at telefonica.net
Fri Apr 5 07:31:54 PDT 2013


I checked your suggestion

              singleAdd(R row)

and it works fine. But on the other hand I can't understad your other comment:

Actually this (peek ) won't do anything -- peek is not a terminal operation.

I guess peek() is evaluted when the stream reaches the superclass and enters the forEach. I tested with peek() and everithing works as expected, the table had been registered to the incomming rows. To recheck, I placed a breakpoint on the addReceiver() method and the debugger stops there.

Is there anything bad in using peek() in cases like this?

-----Mensaje original----- De: Brian Goetz [mailto:brian.goetz at oracle.com] Enviado el: viernes, 05 de abril de 2013 15:57 Para: Jose CC: lambda-dev at openjdk.java.net Asunto: Re: Stream reuse in superclass

public void addRows(Stream rows) { rows=rows.peek(row -> row.addReceiver(this));

Actually this won't do anything -- peek is not a terminal operation.

But in your case, I think the issue is the tension between wanting to add the rows in bulk before firing the change event, and wanting to get access to each one as it is added. THat's not a stream problem :) There's a simple refactor here:

public void bulkAdd(Stream rows) { rows.forEach(r -> singleAdd(r)); fireTableDataChanged(); }

protected void singleAdd(R row) { records.add(row); }

Now the subclass overrides singleAdd.



More information about the lambda-dev mailing list