title: Java map with tuple as key, remove/get by tuple key
body: <p>I have scenario where I would like to have a sorted map with a tuple as key:</p>
  
  <pre><code>var scheduledRunnables = new TreeMap&lt;Tuple&lt;Integer, String&gt;, Runnable&gt;(Comparator.comparing(Tuple::getKey));
  </code></pre>
  
  <p>When adding, I want to add a tuple:</p>
  
  <pre><code>scheduledRunnables.put(new Tuple&lt;&gt;(order, taskName), task);
  </code></pre>
  
  <p>When sorting, I want it to be sorted by the order integer, since that determines order of execution of the runnables. I do not necessarily know the value of the variable <code>taskName</code>. When calling <code>get</code>, I want to only supply the order integer, because of the same reason as previously stated. When calling <code>put</code>, I want to take the entire pair into consideration. So something like this:</p>
  
  <pre><code>scheduledRunnables.put(new Tuple&lt;&gt;(1, "Some task"), () -&gt; System.out.println("asdf"));
  scheduledRunnables.get(1).run(); // Should output 'asdf'
  scheduledRunnables.put(new Tuple&lt;&gt;(1, "Some task"), () -&gt; System.out.println("qwerty"));
  scheduledRunnables.get(1).run(); // Should output 'qwerty'
  scheduledRunnables.remove(1).run(); // Should output 'qwerty' and remove from map
  </code></pre>
  
  <p>The <code>Tuple</code> class is just a data holder that looks like this:</p>
  
  <pre><code>@Data
  public class Tuple&lt;K, V&gt; {
  
      private final K key;
      private V value;
  
      public Tuple(K key, V value) {
          this.key = key;
          this.value = value;
      }
  
  }
  </code></pre>
  
  <p>How would this be implemented? Is is possible without making a custom implementation of the SortedMap interface? Is there a better way to achieve what I am after?</p>