public static String[] concat(String[] array, String value) { String[] result = new String[array.length + 1]; System.arraycopy(array, 0, result, 0, array.length); result[result.length - 1] = value; return result; }
@Override public Object[] toArray() { Object[] copyTo = new Object[size]; System.arraycopy(queue, 0, copyTo, 0, size); return copyTo; }
@Override public Object[] toArray() { Object[] result = new Object[contents.length]; System.arraycopy(contents, 0, result, 0, contents.length); return result; }
private static byte[] extract(byte[] result, int length) { if (length == result.length) { return result; } else { byte[] trunc = new byte[length]; System.arraycopy(result, 0, trunc, 0, length); return trunc; } }
@Override protected List<String> create(String[] elements) { String[] prefix = {"f", "g"}; String[] suffix = {"h", "i"}; String[] all = new String[2 + elements.length + 2]; System.arraycopy(prefix, 0, all, 0, 2); System.arraycopy(elements, 0, all, 2, elements.length); System.arraycopy(suffix, 0, all, 2 + elements.length, 2); return ImmutableList.copyOf(all).subList(2, elements.length + 2); } }
@Override protected List<String> create(String[] elements) { String[] suffix = {"f", "g"}; String[] all = new String[elements.length + suffix.length]; System.arraycopy(elements, 0, all, 0, elements.length); System.arraycopy(suffix, 0, all, elements.length, suffix.length); return ImmutableList.copyOf(all).subList(0, elements.length); } }
private ArrayTable(ArrayTable<R, C, V> table) { rowList = table.rowList; columnList = table.columnList; rowKeyToIndex = table.rowKeyToIndex; columnKeyToIndex = table.columnKeyToIndex; @SuppressWarnings("unchecked") V[][] copy = (V[][]) new Object[rowList.size()][columnList.size()]; array = copy; for (int i = 0; i < rowList.size(); i++) { System.arraycopy(table.array[i], 0, copy[i], 0, table.array[i].length); } }
private void add(Object[] elements, int n) { getReadyToExpandTo(size + n); System.arraycopy(elements, 0, contents, size, n); size += n; }
/** * Appends {@code values}, in order, to the end of the values the built {@link * ImmutableIntArray} will contain. */ public Builder addAll(int[] values) { ensureRoomFor(values.length); System.arraycopy(values, 0, array, count, values.length); count += values.length; return this; }
private static byte[] prepended(byte b, byte[] array) { byte[] out = new byte[array.length + 1]; out[0] = b; System.arraycopy(array, 0, out, 1, array.length); return out; }
private void growIfNeeded() { if (size > queue.length) { int newCapacity = calculateNewCapacity(); Object[] newQueue = new Object[newCapacity]; System.arraycopy(queue, 0, newQueue, 0, queue.length); queue = newQueue; } }
@Override public byte[] getExpected(byte[] bytes) { if (initialBytes == null) { return checkNotNull(bytes); } else { byte[] result = new byte[initialBytes.length + bytes.length]; System.arraycopy(initialBytes, 0, result, 0, initialBytes.length); System.arraycopy(bytes, 0, result, initialBytes.length, bytes.length); return result; } }
@Override public Set<Entry<K, V>> create(Object... elements) { Entry<K, V>[] entries = createArray(elements.length); System.arraycopy(elements, 0, entries, 0, elements.length); return createFromEntries(entries); }
@Override protected List<String> create(String[] elements) { String[] rest = new String[elements.length - 2]; System.arraycopy(elements, 2, rest, 0, elements.length - 2); return Lists.asList(elements[0], elements[1], rest); } })
@Override protected Set<AnEnum> create(AnEnum[] elements) { AnEnum[] otherElements = new AnEnum[elements.length - 1]; System.arraycopy(elements, 1, otherElements, 0, otherElements.length); return Sets.immutableEnumSet(elements[0], otherElements); } })
@Override protected List<String> create(String[] elements) { String[] rest = new String[elements.length - 1]; System.arraycopy(elements, 1, rest, 0, elements.length - 1); return Lists.asList(elements[0], rest); } })
/** * Appends {@code values}, in order, to the end of the values the built {@link * ImmutableLongArray} will contain. */ public Builder addAll(ImmutableLongArray values) { ensureRoomFor(values.length()); System.arraycopy(values.array, values.start, array, count, values.length()); count += values.length(); return this; }