class EntryIterator implements Iterator<Pair<K, V>> {

    Iterator<K> keyIterator = keySet().iterator();
    Iterator<V> valueIterator = null;
    K currentKey = null;

    @Override
    public boolean hasNext() {<FILL_FUNCTION_BODY>}

    @Override
    public Pair<K, V> next() {
      // Obtain the next key
      if (valueIterator == null) {
        currentKey = keyIterator.next();
        valueIterator = get(currentKey).iterator();
      }
      return new Pair<K, V>(currentKey, valueIterator.next());
    }

    @Override
    public void remove() {
      if (valueIterator == null) {
        // Removing an element twice or removing no valid element does not make sense
        return;
      }
      valueIterator.remove();

      if (get(currentKey).isEmpty()) {
        keyIterator.remove();
        valueIterator = null;
        currentKey = null;
      }
    }
  }

      if (valueIterator != null && valueIterator.hasNext()) {
        return true;
      }

      // Prepare for the next key
      valueIterator = null;
      currentKey = null;
      return keyIterator.hasNext();
    
<no_super_class>