Open imagejan opened 6 years ago
@imagejan The iterator()
method will always throw a java.lang.UnsupportedOperationException
because I overrode the method in ResultsTableWrapper
to always throw an exception (see here). It's not implemented in ResultsTableColumnWrapper
either. There are a number of methods in the wrappers which throw UnsupportedOperationException
(which I should have put in the javadoc, sorry!).
That being said, there's (to the best of my knowledge) no reason not to make a custom Iterator
. It just would have been more work, and at the time I didn't need that method.
If you're just trying to view the tables, in the interim you could declare them as outputs and then they should display fine.
@awalter17 the trigger for this issue was this forum post, actually. I wanted to set up an example of doing table calculations in an IJ2 table after retrieving it via script parameters from an IJ1 ResultsTable
. But even the simplest operations on the wrapped table resulted in this iterator
issue.
Is there a reason why we can't use the inherited List
iterator and override the iterator()
implementation here?
I was able to getColumnCount()
and getRowCount()
on the wrapped table, so I wonder why inheriting the iterator wouldn't work. I think it would be great to have the full Table
functionality with wrapped IJ1 ResultsTable
s.
Is there a reason why we can't use the inherited
List
iterator and override theiterator()
implementation here?
The ResultsTableWrapper
doesn't extend any concrete implementation of List
, so we can't use something like super.iterator()
. If we wanted to implement the iterator()
method we'd probably need to create our own Iterator
implementation, or change ResultsTableWrapper
to extend a concrete implementation of List
(similar to AbstractTable
).
Either way, it gets a bit complicated because the Table
s iterator is typed on Column
which doesn't exist in the IJ1 ResultsTable
. So every time we want a Column
we need to wrap the corresponding array in the ResultsTable
.
I think it would be great to have the full
Table
functionality with wrapped IJ1ResultsTable
s.
I agree, but it may not be possible to preserve all functionality due to differences between the IJ2 and IJ1 API.
That being said, there are methods which I didn't implement that could be implemented in the wrapper with a bit of work. At the time, I only implemented methods which had somewhat direct equivalents in the IJ1 ResultsTable
. My use case, (I think it was displaying IJ1 tables in a jupyter notebook) was focused on displaying the tables not mutating them. So I believe most of the accessor methods work, but a lot of the mutators do not 😿
Thanks for your explanations, @awalter17! That helps a lot.
I wonder whether it would be desirable to wrap all columns as ResultsTableColumnWrapper
in the constructor and then be able to provide a functional List
(e.g. by extending AbstractList
as you suggest). I might look into it while migrating the table classes to scijava-table
(see https://github.com/scijava/scijava-common/issues/314), but it might take a while.
So I believe most of the accessor methods work, but a lot of the mutators do not
That's funny, because appendColumn
worked fine when I tried, but simply trying to iterate over the columns to display their names created the aforementioned problems.
I just stumbled upon this issue again while trying if a quick solution for this forum question exists with SciJava tables.
I would have been great if you could just write:
#@ ResultsTable rt
#@ ConvertService cs
#@ OpService ops
import org.scijava.table.Table
table = cs.convert(rt, Table.class)
targetColumn = table.get(0)
columnHistogram = ops.image().histogram(targetColumn)
mode = ops.stats().max(columnHistogram)
But whenever you want to access any column of the table or similar, you get:
java.lang.UnsupportedOperationException: iterator()
at net.imagej.legacy.convert.ResultsTableWrapper.iterator(ResultsTableWrapper.java:374)
or
java.lang.UnsupportedOperationException: iterator()
at net.imagej.legacy.convert.ResultsTableColumnWrapper.iterator(ResultsTableColumnWrapper.java:97)
While the following script works as expected:
it will fails when using a
ResultsTableWrapper
like this:While the returned object is indeed a
ResultsTableWrapper
, the stack trace indicates that there's noiterator()
implementation:I suppose the issue is with the
Table
interface having aniterator()
declaration which leads to the one ofAbstractList
not being taken, but I don't understand multiple inheritance enough to be able to fully explain this. @awalter17, @ctrueden maybe you have a clue here?