public static <E> ImmutableSortedMultiset<E> copyOf(
      Comparator<? super E> comparator, Iterable<? extends E> elements) {
    """
	Returns an immutable sorted multiset containing the given elements sorted by the given {@code
	Comparator}. This method iterates over {@code elements} at most once.
	
	<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 {@code comparator} or any of {@code elements} is null
    """
    if (elements instanceof ImmutableSortedMultiset) {
      @SuppressWarnings("unchecked") // immutable collections are always safe for covariant casts
      ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
      if (comparator.equals(multiset.comparator())) {
        if (multiset.isPartialView()) {
          return copyOfSortedEntries(comparator, multiset.entrySet().asList());
        } else {
          return multiset;
        }
      }
    }
    elements = Lists.newArrayList(elements); // defensive copy
    TreeMultiset<E> sortedCopy = TreeMultiset.create(checkNotNull(comparator));
    Iterables.addAll(sortedCopy, elements);
    return copyOfSortedEntries(comparator, sortedCopy.entrySet());
  }
public static <E> ImmutableSortedMultiset<E> copyOf(
      Comparator<? super E> comparator, Iterable<? extends E> elements) {
    if (elements instanceof ImmutableSortedMultiset) {
      @SuppressWarnings("unchecked") // immutable collections are always safe for covariant casts
      ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
      if (comparator.equals(multiset.comparator())) {
        if (multiset.isPartialView()) {
          return copyOfSortedEntries(comparator, multiset.entrySet().asList());
        } else {
          return multiset;
        }
      }
    }
    elements = Lists.newArrayList(elements); // defensive copy
    TreeMultiset<E> sortedCopy = TreeMultiset.create(checkNotNull(comparator));
    Iterables.addAll(sortedCopy, elements);
    return copyOfSortedEntries(comparator, sortedCopy.entrySet());
  }
public static < E > ImmutableSortedMultiset < E > copyOf ( Comparator < ? super E > comparator , Iterable < ? extends E > elements ) { if ( elements instanceof ImmutableSortedMultiset ) { @ SuppressWarnings ( "unchecked" ) // immutable collections are always safe for covariant casts ImmutableSortedMultiset < E > multiset = ( ImmutableSortedMultiset < E > ) elements ; if ( comparator . equals ( multiset . comparator ( ) ) ) { if ( multiset . isPartialView ( ) ) { return copyOfSortedEntries ( comparator , multiset . entrySet ( ) . asList ( ) ) ; } else { return multiset ; } } } elements = Lists . newArrayList ( elements ) ; // defensive copy TreeMultiset < E > sortedCopy = TreeMultiset . create ( checkNotNull ( comparator ) ) ; Iterables . addAll ( sortedCopy , elements ) ; return copyOfSortedEntries ( comparator , sortedCopy . entrySet ( ) ) ; }
Returns an immutable sorted multiset containing the given elements sorted by the given {@code
Comparator}. This method iterates over {@code elements} at most once.

<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 {@code comparator} or any of {@code elements} is null
Returns an immutable sorted multiset containing the given elements sorted by the given { @code Comparator } . This method iterates over { @code elements } at most once .