/** * Creates a new instance wrapping the given array. A direct reference to the given array is * retained (i.e. the array is <strong>not</strong> cloned). Consequently the given array * shall not be modified after construction if the returned list is intended to be immutable. * * <div class="section">WARNING! Type safety hole</div> * Callers <strong>must</strong> ensure that the type of array elements in exactly {@code E}, * not a subtype of {@code E}. If the caller is okay with {@code List<? extends E>}, then (s)he * should use {@link org.apache.sis.util.collection.Containers#unmodifiableList(Object[])} instead. * See class javadoc for more information. * * <p>The argument type is intentionally {@code E[]} instead than {@code E...} in order to force * the caller to instantiate the array explicitly, in order to make sure that the array type is * the intended one.</p> * * @param <E> the type of elements in the list. * @param array the array to wrap, or {@code null} if none. * @return the given array wrapped in an unmodifiable list, or {@code null} if the given array was null. */ public static <E> UnmodifiableArrayList<E> wrap(final E[] array) { // NOT "E..." - see javadoc. return (array != null) ? new UnmodifiableArrayList<>(array) : null; }
/** * Creates a new instance wrapping the given array. A direct reference to the given array is * retained (i.e. the array is <strong>not</strong> cloned). Consequently the given array * shall not be modified after construction if the returned list is intended to be immutable. * * <div class="section">WARNING! Type safety hole</div> * Callers <strong>must</strong> ensure that the type of array elements in exactly {@code E}, * not a subtype of {@code E}. If the caller is okay with {@code List<? extends E>}, then (s)he * should use {@link org.apache.sis.util.collection.Containers#unmodifiableList(Object[])} instead. * See class javadoc for more information. * * <p>The argument type is intentionally {@code E[]} instead than {@code E...} in order to force * the caller to instantiate the array explicitely, in order to make sure that the array type is * the intended one.</p> * * @param <E> the type of elements in the list. * @param array the array to wrap, or {@code null} if none. * @return the given array wrapped in an unmodifiable list, or {@code null} if the given array was null. */ public static <E> UnmodifiableArrayList<E> wrap(final E[] array) { // NOT "E..." - see javadoc. return (array != null) ? new UnmodifiableArrayList<>(array) : null; }
/** * Creates a new instance wrapping a subregion of the given array. A direct reference to the * given array is retained (i.e. the array is <strong>not</strong> cloned). Consequently the * specified sub-region of the given array shall not be modified after construction if the * returned list is intended to be immutable. * * <p>This method does not check the validity of the given index. * The check must be done by the caller.</p> * * <div class="section">WARNING! Type safety hole</div> * Callers <strong>must</strong> ensure that the type of array elements in exactly {@code E}, * not a subtype of {@code E}. If the caller is okay with {@code List<? extends E>}, then (s)he * should use {@link org.apache.sis.util.collection.Containers#unmodifiableList(Object[])} instead. * See class javadoc for more information. * * @param <E> the type of elements in the list. * @param array the array to wrap. * @param lower low endpoint (inclusive) of the sublist. * @param upper high endpoint (exclusive) of the sublist. * @return the given array wrapped in an unmodifiable list. */ public static <E> UnmodifiableArrayList<E> wrap(final E[] array, final int lower, final int upper) { if (lower == 0 && upper == array.length) { return new UnmodifiableArrayList<>(array); } return new UnmodifiableArrayList.SubList<>(array, lower, upper - lower); }
/** * Creates a new instance wrapping a subregion of the given array. A direct reference to the * given array is retained (i.e. the array is <strong>not</strong> cloned). Consequently the * specified sub-region of the given array shall not be modified after construction if the * returned list is intended to be immutable. * * <p>This method does not check the validity of the given index. * The check must be done by the caller.</p> * * <div class="section">WARNING! Type safety hole</div> * Callers <strong>must</strong> ensure that the type of array elements in exactly {@code E}, * not a subtype of {@code E}. If the caller is okay with {@code List<? extends E>}, then (s)he * should use {@link org.apache.sis.util.collection.Containers#unmodifiableList(Object[])} instead. * See class javadoc for more information. * * @param <E> the type of elements in the list. * @param array the array to wrap. * @param lower low endpoint (inclusive) of the sublist. * @param upper high endpoint (exclusive) of the sublist. * @return the given array wrapped in an unmodifiable list. */ public static <E> UnmodifiableArrayList<E> wrap(final E[] array, final int lower, final int upper) { if (lower == 0 && upper == array.length) { return new UnmodifiableArrayList<>(array); } return new UnmodifiableArrayList.SubList<>(array, lower, upper - lower); }