title: Java 8 stream - filter on nested map and rebuild
body: <p>I have a nested map in the form</p>
  
  <pre><code>TreeMap&lt;LocalDate, Map&lt;Long,TreeMap&lt;BigDecimal,String&gt;&gt;&gt;
  </code></pre>
  
  <p>and I have to process this map and end up with a map of the same structure where the nested TreeMap     </p>
  
  <pre><code>TreeMap&lt;BigDecimal, String&gt;&gt;
  </code></pre>
  
  <p>has exactly two elements.</p>
  
  <p>I can find the elements I want with </p>
  
  <pre><code>values.entrySet().stream().flatMap(date -&gt; date.getValue().entrySet().stream()
                                               .map(type -&gt; type.getValue().entrySet()))
                                               .filter(valueMap -&gt; valueMap.size() == 2 )
  </code></pre>
  
  <p>but I can't work out how to express the .collect() to re-assemble the structure. Any pointers will be welcome. </p>