@Override public Array<T> appendAll(Iterable<? extends T> elements) { Objects.requireNonNull(elements, "elements is null"); final Object[] source = toArray(elements); if (source.length == 0) { return this; } else { final Object[] copy = new Object[length() + source.length]; System.arraycopy(delegate, startIndex, copy, 0, length()); System.arraycopy(source, 0, copy, length(), source.length); return wrap(copy); } }
@Override public Array<T> prepend(T element) { final Object[] copy = new Object[length() + 1]; copy[0] = element; System.arraycopy(delegate, startIndex, copy, 1, length()); return wrap(copy); }
@Override public Array<T> removeAt(int index) { if (index < 0) { throw new IndexOutOfBoundsException("removeAt(" + index + ")"); } else if (index >= length()) { throw new IndexOutOfBoundsException("removeAt(" + index + ")"); } else if (index == 0) { return drop(1); } else if (index == length() - 1) { return dropRight(1); } else { final Object[] arr = new Object[length() - 1]; System.arraycopy(delegate, startIndex, arr, 0, index); System.arraycopy(delegate, startIndex + index + 1, arr, index, length() - index - 1); return wrap(arr); } }
@Override public long[] toArray() { return performOperation( TerminalFunctions.toArrayLongFunction(), false, (v1, v2) -> { long[] array = Arrays.copyOf(v1, v1.length + v2.length); System.arraycopy(v2, 0, array, v1.length, v2.length); return array; }, null, false); }
@Override public Array<T> insertAll(int index, Iterable<? extends T> elements) { if (index < 0) { throw new IndexOutOfBoundsException("insert(" + index + ", e)"); } else if (index > length()) { throw new IndexOutOfBoundsException( "insert(" + index + ", e) on Array of length " + length()); } final Object[] list = toArray(elements); if (list.length == 0) { return this; } else { final Object[] copy = new Object[length() + list.length]; if (index > 0) { System.arraycopy(delegate, startIndex, copy, 0, index); } System.arraycopy(list, 0, copy, index, list.length); if (index < length()) { System.arraycopy(delegate, startIndex + index, copy, index + list.length, length() - index); } return wrap(copy); } }
@Override public Array<T> slice(long beginIndex, long endIndex) { if (beginIndex >= endIndex || beginIndex >= length() || isEmpty()) { return empty(); } if (beginIndex <= 0 && endIndex >= length()) { return this; } final int index = Math.max((int) beginIndex, 0); final int length = Math.min((int) endIndex, length()) - index; final Object[] arr = new Object[length]; System.arraycopy(delegate, index, arr, 0, length); return wrap(arr); }
@Override protected FilterNode any(final FilterNode node0, boolean signor) { Objects.requireNonNull(node0); if (!(node0 instanceof FilterJoinNode)) { throw new IllegalArgumentException( this + (signor ? " or " : " and ") + " a node but " + String.valueOf(node0) + "is not a " + FilterJoinNode.class.getSimpleName()); } final FilterJoinNode node = (FilterJoinNode) node0; if (this.nodes == null) { this.nodes = new FilterNode[] {node}; this.or = signor; return this; } if (or == signor || this.column == null) { FilterNode[] newsiblings = new FilterNode[nodes.length + 1]; System.arraycopy(nodes, 0, newsiblings, 0, nodes.length); newsiblings[nodes.length] = node; this.nodes = newsiblings; if (this.column == null) this.or = signor; return this; } this.nodes = new FilterNode[] {new FilterJoinNode(node), node}; this.column = null; this.express = null; this.value = null; this.joinClass = null; this.joinEntity = null; this.joinColumns = null; this.or = signor; return this; }