| /*=============================================================================# |
| # Copyright (c) 2020, 2021 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.internal.jcommons.collections; |
| |
| import static org.eclipse.statet.jcommons.lang.NullDefaultLocation.FIELD; |
| import static org.eclipse.statet.jcommons.lang.NullDefaultLocation.PARAMETER; |
| import static org.eclipse.statet.jcommons.lang.NullDefaultLocation.RETURN_TYPE; |
| |
| import java.util.List; |
| |
| import org.eclipse.statet.jcommons.lang.NonNullByDefault; |
| |
| |
| @NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD }) |
| public final class ArrayUtils { |
| |
| |
| public static <E> E[] copyRemoveElement(final List<? extends E> l, final int n, final int index) { |
| @SuppressWarnings("unchecked") |
| final E[] a= (E[])new Object[n]; |
| if (l instanceof AbstractImList<?>) { |
| if (index > 0) { |
| ((AbstractImList<?>)l).copyTo(0, a, 0, index); |
| } |
| if (index < n) { |
| ((AbstractImList<?>)l).copyTo(index + 1, a, index, n - index); |
| } |
| } |
| else { |
| final Object[] src= l.toArray(); |
| if (index > 0) { |
| System.arraycopy(src, 0, a, 0, index); |
| } |
| if (index < n) { |
| System.arraycopy(src, index + 1, a, index, n - index); |
| } |
| } |
| return a; |
| } |
| |
| |
| private ArrayUtils() { |
| } |
| |
| } |