/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null */ public static <E> ImmutableList<E> of( E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11) { return construct(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null */ public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6) { return construct(e1, e2, e3, e4, e5, e6); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null */ public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { return construct(e1, e2, e3, e4, e5, e6, e7, e8, e9); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null */ public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4) { return construct(e1, e2, e3, e4); }
/** * Returns an immutable list containing a single element. This list behaves * and performs comparably to {@link Collections#singleton}, but will not * accept a null element. It is preferable mainly for consistency and * maintainability of your code. * * @throws NullPointerException if {@code element} is null */ public static <E> ImmutableList<E> of(E element) { return construct(element); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null */ public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7) { return construct(e1, e2, e3, e4, e5, e6, e7); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null */ public static <E> ImmutableList<E> of(E e1, E e2) { return construct(e1, e2); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null */ public static <E> ImmutableList<E> of(E e1, E e2, E e3) { return construct(e1, e2, e3); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null */ public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5) { return construct(e1, e2, e3, e4, e5); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null */ public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { return construct(e1, e2, e3, e4, e5, e6, e7, e8); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null */ public static <E> ImmutableList<E> of( E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { return construct(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any element is null * @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> ImmutableList<E> of( E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11, E e12, E... others) { Object[] array = new Object[12 + others.length]; array[0] = e1; array[1] = e2; array[2] = e3; array[3] = e4; array[4] = e5; array[5] = e6; array[6] = e7; array[7] = e8; array[8] = e9; array[9] = e10; array[10] = e11; array[11] = e12; System.arraycopy(others, 0, array, 12, others.length); return construct(array); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any of {@code elements} is null * @since 3.0 */ public static <E> ImmutableList<E> copyOf(E[] elements) { return (elements.length == 0) ? ImmutableList.<E>of() : construct(elements.clone()); }
/** * Returns an immutable list containing the given elements, in order. * * <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. * * <p>Note that if {@code list} is a {@code List<String>}, then {@code * ImmutableList.copyOf(list)} returns an {@code ImmutableList<String>} * containing each of the strings in {@code list}, while * ImmutableList.of(list)} returns an {@code ImmutableList<List<String>>} * containing one element (the given list itself). * * <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 */ public static <E> ImmutableList<E> copyOf(Collection<? extends E> elements) { if (elements instanceof ImmutableCollection) { @SuppressWarnings("unchecked") // all supported methods are covariant ImmutableList<E> list = ((ImmutableCollection<E>) elements).asList(); return list.isPartialView() ? ImmutableList.<E>asImmutableList(list.toArray()) : list; } return construct(elements.toArray()); }