/** * Returns an immutable set containing the given elements, minus duplicates, in the order each was * first specified. That is, if multiple elements are {@linkplain Object#equals equal}, all except * the first are ignored. */ public static <E> ImmutableSet<E> of(E e1, E e2, E e3, E e4, E e5) { return construct(5, e1, e2, e3, e4, e5); }
/** * Returns an immutable set containing the given elements, minus duplicates, in the order each was * first specified. That is, if multiple elements are {@linkplain Object#equals equal}, all except * the first are ignored. */ public static <E> ImmutableSet<E> of(E e1, E e2, E e3, E e4) { return construct(4, e1, e2, e3, e4); }
/** * Returns an immutable set containing the given elements, minus duplicates, in the order each was * first specified. That is, if multiple elements are {@linkplain Object#equals equal}, all except * the first are ignored. */ public static <E> ImmutableSet<E> of(E e1, E e2) { return construct(2, e1, e2); }
/** * Returns an immutable set containing the given elements, minus duplicates, in the order each was * first specified. That is, if multiple elements are {@linkplain Object#equals equal}, all except * the first are ignored. */ public static <E> ImmutableSet<E> of(E e1, E e2, E e3) { return construct(3, e1, e2, e3); }
/** * Returns an immutable set containing the given elements, minus duplicates, in the order each was * first specified. That is, if multiple elements are {@linkplain Object#equals equal}, all except * the first are ignored. * * @since 3.0 (source-compatible since 2.0) */ @SafeVarargs // For Eclipse. For internal javac we have disabled this pointless type of warning. public static <E> ImmutableSet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... others) { final int paramCount = 6; Object[] elements = new Object[paramCount + others.length]; elements[0] = e1; elements[1] = e2; elements[2] = e3; elements[3] = e4; elements[4] = e5; elements[5] = e6; System.arraycopy(others, 0, elements, paramCount, others.length); return construct(elements.length, elements); }
/** * Returns an immutable set containing each of {@code elements}, minus duplicates, in the order * each appears first in the source collection. * * <p><b>Performance note:</b> This method will sometimes recognize that the actual copy operation * is unnecessary; for example, {@code copyOf(copyOf(anArrayList))} will 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 * @since 7.0 (source-compatible since 2.0) */ public static <E> ImmutableSet<E> copyOf(Collection<? extends E> elements) { /* * TODO(lowasser): consider checking for ImmutableAsList here * TODO(lowasser): consider checking for Multiset here */ // Don't refer to ImmutableSortedSet by name so it won't pull in all that code if (elements instanceof ImmutableSet && !(elements instanceof SortedSet)) { @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); }
/** * Returns an immutable set containing each of {@code elements}, minus duplicates, in the order * each appears first in the source array. * * @throws NullPointerException if any of {@code elements} is null * @since 3.0 */ public static <E> ImmutableSet<E> copyOf(E[] elements) { switch (elements.length) { case 0: return of(); case 1: return of(elements[0]); default: return construct(elements.length, elements.clone()); } }
return construct(uniques, elements); } else { Object[] uniqueElements =