Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your code is as good as it gets. However, it seems to me that the overall design of the data structure needs some overhaul: You are using <code>SortedMap&lt;?, SortedMap&lt;?, ?&gt;</code>, yet the keys of the parent map are not used.</p> <p>Do you want to express a tree with nested elements with that and your task is it to flatten the tree? If so, either create a Tree class that supports your approach, or use an intelligent way to merge the keys:</p> <pre><code>public class NestedKey implements Comparable&lt;NestedKey&gt; { private Comparable[] entries; public NestedKey(Comparable... entries) { assert entries != null; this.entries = entries; } public int compareTo(NestedKey other) { for(int i = 0; i &lt; other.entries.length; i++) { if (i == entries.length) return -1; // other is longer then self &lt;=&gt; self is smaller than other int cmp = entries[i].compareTo(other.entries[i]); if (cmp != 0) return cmp; } if (entries.length &gt; other.entries.length) return 1; // self is longer than others &lt;=&gt; self is larger than other else return 0; } } </code></pre> <p>The <code>NestedKey</code> entry used as a key for a SortedMap compares to other <code>NestedKey</code> objects by comparing each of its entries. NestedKeys that are in all elements present, but that have more entries are assumed to be larger. Thus, you have a relationship like this:</p> <ul> <li>NestedKey(1, 2, 3) &lt; NestedKey(1, 2, 4)</li> <li>NestedKey(1, 3, 3) &lt; NestedKey(2, 1, 1)</li> <li>NestedKey(1, 2, 3) &lt; NestedKey(2)</li> </ul> <p>If you use only one SortedMap that uses NestedKey as its keys, then its <code>.values()</code> set automatically returns all entries, flattened out. However, if you want to use only parts of the SortedMap, then you must use <code>.subMap</code>. For example, if you want all entries wite NestedKeys between 2 and 3 , use <code>.subMap(new NestedKey(2), new NestedKey(3))</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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