Returns an immutable set containing each of elements, minus duplicates, in the order each appears first in the source collection. Performance note: This method will sometimes recognize that the actual copy operation is unnecessary; for example, copyOf(copyOf(anArrayList))
(Collection<? extends E> elements)
| 246 | |
| 247 | |
| 248 | public static <E> ImmutableSet<E> copyOf(Collection<? extends E> elements) { |
| 249 | /* |
| 250 | * TODO(lowasser): consider checking for ImmutableAsList here |
| 251 | * TODO(lowasser): consider checking for Multiset here |
| 252 | */ |
| 253 | if (elements instanceof ImmutableSet |
| 254 | && !(elements instanceof ImmutableSortedSet)) { |
| 255 | @SuppressWarnings("unchecked") // all supported methods are covariant |
| 256 | ImmutableSet<E> set = (ImmutableSet<E>) elements; |
| 257 | if (!set.isPartialView()) { |
| 258 | return set; |
| 259 | } |
| 260 | } else if (elements instanceof EnumSet) { |
| 261 | return copyOfEnumSet((EnumSet) elements); |
| 262 | } |
| 263 | Object[] array = elements.toArray(); |
| 264 | return construct(array.length, array); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Returns an immutable set containing each of {@code elements}, minus duplicates, in the order |
no test coverage detected