@Override public ImmutableList<E> subList(int fromIndex, int toIndex) { Preconditions.checkPositionIndexes(fromIndex, toIndex, size); return (fromIndex == toIndex) ? ImmutableList.<E>of() : new RegularImmutableList<E>(array, offset + fromIndex, toIndex - fromIndex); }
private static <E> ImmutableList<E> copyOfInternal(ArrayList<? extends E> list) { return (list.isEmpty()) ? ImmutableList.<E>of() : new RegularImmutableList<E>(nullChecked(list.toArray())); }
private static <E> ImmutableList<E> copyOfInternal(Collection<? extends E> collection) { int size = collection.size(); return (size == 0) ? ImmutableList.<E>of() : ImmutableList.<E>createFromIterable(collection, size); }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any of {@code elements} is null */ public static <E> ImmutableList<E> of(E... elements) { return (elements.length == 0) ? ImmutableList.<E>of() : new RegularImmutableList<E>(copyIntoArray(elements)); }