okaywit / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Unable to copy ArrayTable with ImmutableTable.copyOf #1442

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The attached test fails. Thanks.

Original issue reported on code.google.com by corin.la...@gmail.com on 10 Jun 2013 at 6:56

Attachments:

GoogleCodeExporter commented 9 years ago
ArrayTable seems rather problematic with its use of nulls... (is it the only 
collection that is allowed to contain null?)

ArrayTable needs better implementations for cellSet, cellIterator, size, etc. 
...or maybe ArrayTable should only be filled with Optionals?

For me and now, I will avoid using ArrayTable...

Original comment by corin.la...@gmail.com on 10 Jun 2013 at 7:39

GoogleCodeExporter commented 9 years ago
ArrayTable's documentation makes it clear that cell values are null unless 
another value is set, so I'd say that's working as intended. Most of our 
general purpose mutable collections allow null elements.

> ArrayTable needs better implementations for cellSet, cellIterator, size, etc.

What's wrong with the current implementations?

Original comment by cgdecker@google.com on 25 Jun 2013 at 6:49

GoogleCodeExporter commented 9 years ago
Also HashBasedTable.create(Table) fails (with a NPE) to copy an ArrayTable 
where some values are null as in the following example:

      ArrayTable<Integer, String, Object> arrayTable = ArrayTable.create(Lists.newArrayList(1, 2, 3),
         Lists.newArrayList("a", "b", "c"));

      HashBasedTable<Integer, String, Object> hashBasedTable = HashBasedTable.create(arrayTable);

This makes it tricky to use. A method receiving a Table with the intention to 
copy it to an ImmutableTable or HashBasedTable has to check its type and in 
case of an ArrayTable handle null values properly. Or is there a better way?

I would prefer ArrayTable to treat cells with null values as cells that are not 
in the table. This would also impact all views on ArrayTable and size, isEmpty 
etc. but would be more concise with other Table implementations (for example 
remove could be used instead of erase). However it would not be obvious which 
rows and keys are supported.

Original comment by markus.s...@gmail.com on 17 Sep 2013 at 5:16

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:17

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08