code: public static <E> ImmutableSet<E> copyOf(Collection<? extends E> elements) {
      /*
       * TODO(user): consider checking for ImmutableAsList here
       * TODO(user): consider checking for Multiset here
       */
      if (elements instanceof ImmutableSet
          && !(elements instanceof ImmutableSortedSet)) {
        @SuppressWarnings("unchecked") // all supported methods are covariant
        ImmutableSet<E> set = (ImmutableSet<E>) elements;
        if (!set.isPartialView()) {
          return set;
        }
      } else if (elements instanceof EnumSet) {
        return copyOfEnumSet((EnumSet) elements);
      }
      Object[] array = elements.toArray();
      return construct(array.length, array);
    }
docs: Returns an immutable set containing the given elements, in order. Repeated
  occurrences of an element (according to {@link Object#equals}) after the
  first are ignored. This method iterates over {@code elements} at most
  once.
  
  <p>Note that if {@code s} is a {@code Set<String>}, then {@code
  ImmutableSet.copyOf(s)} returns an {@code ImmutableSet<String>} containing
  each of the strings in {@code s}, while {@code ImmutableSet.of(s)} returns
  a {@code ImmutableSet<Set<String>>} containing one element (the given set
  itself).
  
  <p><b>Note:</b> Despite what the method name suggests, {@code copyOf} will
  return constant-space views, rather than linear-space copies, of some
  inputs known to be immutable. For some other immutable inputs, such as key
  sets of an {@code ImmutableMap}, it still performs a copy in order to avoid
  holding references to the values of the map. The heuristics used in this
  decision are undocumented and subject to change except that:
  <ul>
  <li>A full copy will be done of any {@code ImmutableSortedSet}.</li>
  <li>{@code ImmutableSet.copyOf()} is idempotent with respect to pointer
  equality.</li>
  </ul>
  
  <p>This method is safe to use even when {@code elements} is a synchronized
  or concurrent collection that is currently being modified by another
  thread.
  
  @throws NullPointerException if any of {@code elements} is null
  @since 7.0 (source-compatible since 2.0)