guava/src/com/google/common/collect/ImmutableSet.java
public static <E> ImmutableSet<E> copyOf(Iterable<? extends E> elements) {
    return (elements instanceof Collection)
        ? copyOf((Collection<? extends E>) elements)
        : copyOf(elements.iterator());
  }
public static <E> ImmutableSet<E> copyOf(Iterable<? extends E> elements) {
    return (elements instanceof Collection)
        ? copyOf((Collection<? extends E>) elements)
        : copyOf(elements.iterator());
  }
Returns an immutable set containing each of {@code elements}, minus duplicates, in the order
each appears first in the source iterable. This method iterates over {@code elements} only
once.

<p><b>Performance note:</b> This method will sometimes recognize that the actual copy operation
is unnecessary; for example, {@code copyOf(copyOf(anArrayList))} should copy the data only
once. This reduces the expense of habitually making defensive copies at API boundaries.
However, the precise conditions for skipping the copy operation are undefined.

@throws NullPointerException if any of {@code elements} is null