guava/src/com/google/common/collect/ImmutableListMultimap.java
public static <K, V> ImmutableListMultimap<K, V> copyOf(
      Multimap<? extends K, ? extends V> multimap) {
    if (multimap.isEmpty()) {
      return of();
    }

    // TODO(lowasser): copy ImmutableSetMultimap by using asList() on the sets
    if (multimap instanceof ImmutableListMultimap) {
      @SuppressWarnings("unchecked") // safe since multimap is not writable
      ImmutableListMultimap<K, V> kvMultimap = (ImmutableListMultimap<K, V>) multimap;
      if (!kvMultimap.isPartialView()) {
        return kvMultimap;
      }
    }

    return fromMapEntries(multimap.asMap().entrySet(), null);
  }
public static <K, V> ImmutableListMultimap<K, V> copyOf(
      Multimap<? extends K, ? extends V> multimap) {
    if (multimap.isEmpty()) {
      return of();
    }

    // TODO(lowasser): copy ImmutableSetMultimap by using asList() on the sets
    if (multimap instanceof ImmutableListMultimap) {
      @SuppressWarnings("unchecked") // safe since multimap is not writable
      ImmutableListMultimap<K, V> kvMultimap = (ImmutableListMultimap<K, V>) multimap;
      if (!kvMultimap.isPartialView()) {
        return kvMultimap;
      }
    }

    return fromMapEntries(multimap.asMap().entrySet(), null);
  }
public static < K , V > ImmutableListMultimap < K , V > copyOf ( Multimap < ? extends K , ? extends V > multimap ) { if ( multimap . isEmpty ( ) ) { return of ( ) ; } // TODO(lowasser): copy ImmutableSetMultimap by using asList() on the sets if ( multimap instanceof ImmutableListMultimap ) { @ SuppressWarnings ( "unchecked" ) // safe since multimap is not writable ImmutableListMultimap < K , V > kvMultimap = ( ImmutableListMultimap < K , V > ) multimap ; if ( ! kvMultimap . isPartialView ( ) ) { return kvMultimap ; } } return fromMapEntries ( multimap . asMap ( ) . entrySet ( ) , null ) ; }
Returns an immutable multimap containing the same mappings as {@code multimap}. The generated
multimap's key and value orderings correspond to the iteration ordering of the {@code
multimap.asMap()} view.

<p>Despite the method name, this method attempts to avoid actually copying the data when it is
safe to do so. The exact circumstances under which a copy will or will not be performed are
undocumented and subject to change.

@throws NullPointerException if any key or value in {@code multimap} is null
Returns an immutable multimap containing the same mappings as { @code multimap } . The generated multimap s key and value orderings correspond to the iteration ordering of the { @code multimap . asMap () } view .