Stream reuse in superclass
Jose
jgetino at telefonica.net
Fri Apr 5 06:48:49 PDT 2013
>Maybe you could zoom out and actually tell people what problem you are
>trying to solve? There is almost certainly a better solution here.
OK, ill try
- The base class, called PropertyTable<R>, extends AbstractTableModel. It
maintains a List<R> of records.
The fields visible in the table are defined by a list of properties of R.
- A method of this class add rows (records) to the table:
public void addRows(Stream<R> rows) {
rows.forEach(records::add);
fireTableDataChanged();
}
- A subclass LevelTable extends PropertyTable<Foo> for a certain type Foo
A LevelTable instance needs to be notified on user input changes on the
individual cells of the table
to ensure they satify some global relations between records. I particular
it must clamp the values of some fields of a row between
the values on the previous and the next row.
So, when adding new rows to the table I must also register the table as a
listener to the added rows, which forces me to override
the base method that consumes the stream of Foos.
This is the point I'm now. The cuurent code is below, I can't imagine any
bad with it:
public void addRows(Stream<Foo> rows) {
rows=rows.peek(row -> row.addReceiver(this));
super.addRows(rows);
}
More information about the lambda-dev
mailing list