Note that there are some explanatory texts on larger screens.

plurals
  1. POFirst element in tree becoming null? Guava TreebasedTable
    text
    copied!<p>So I am having a problem with a Guava TreeBasedTable (if you're unfamiliar, it's a tree that accesses its elements based on a pair of keys) which over the past week has been a bear to figure out. I'll do my best to explain, removing superfluous code:</p> <pre><code>TreeBasedTable&lt;RowValue, Data, Result&gt; results = TreeBasedTable.create(); for (Data d : data.getData()) { for (Operation o: data.getOperations()) { Result r = o.calculate(...); results.put(r.rowValue, d, r); } } </code></pre> <p>Basically, I iterate over some data that I have, do some calculations, and stick the results in the table. What's strange though, is when I try to access the elements. If I simply iterate over them as follows:</p> <pre><code>for(Result r : results.values()){ System.out.println(r); } </code></pre> <p>everything works normally. However, if I instead try to access them as follows:</p> <pre><code>for(RowValue row : results.rowKeySet()){ for(Data d : results.columnKeySet()){ System.out.println(results.get(row, d)); } } </code></pre> <p>The first element is null somehow. If however the tree is of size 1, it works fine. Could it be there is something about Trees going on here that I am not understanding? Sorry for the long question, I hope it was clear.</p> <p>::EDIT:: The first value passed into the tree is always non-null. When the tree reaches size 3 however, it turns from non-null, to null. Sorry if it wasn't exactly clear what my problem was. As requested, here is the actual code with the actual keys:</p> <p>public void createResults(Options options, MeasuredData data, ArrayList methods) {</p> <pre><code>private TreeBasedTable&lt;MethodDescriptor, Compound, Result&gt; results = TreeBasedTable.create(); for (Compound c : data.getCompounds()) { for (Method method : methods) { ArrayList&lt;Result&gt; calcResults = method.calculate(c, options); for (Result r : calcResults) { results.put(r.getMethod(), c, r); } } } </code></pre> <p>So I run a number of computations on a number of compounds, each of which can produce multiple results. Is there any way I can clarify this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload