@SuppressWarnings("unchecked") public ImmutableStack<T> reverse() { T[] tmpEntries = (T[]) new Object[entries.length]; for (int i = entries.length - 1, j = 0; i >= 0; i--, j++) { tmpEntries[j] = entries[i]; } return new ImmutableStack<>(tmpEntries); }
@SuppressWarnings("unchecked") public ImmutableStack<T> reverse() { T[] tmpEntries = (T[]) new Object[entries.length]; for (int i = entries.length - 1, j = 0; i >= 0; i--, j++) { tmpEntries[j] = entries[i]; } return new ImmutableStack<>(tmpEntries); }
@SuppressWarnings("unchecked") public ImmutableStack<T> reverse() { T[] tmpEntries = (T[]) new Object[entries.length]; for (int i = entries.length - 1, j = 0; i >= 0; i--, j++) { tmpEntries[j] = entries[i]; } return new ImmutableStack<>(tmpEntries); }
protected ImmutableStack<T> makeStack(T[] tmpEntries) { return new ImmutableStack<>(tmpEntries); }
protected ImmutableStack<T> makeStack(T[] tmpEntries) { return new ImmutableStack<>(tmpEntries); }
protected ImmutableStack<T> makeStack(T[] tmpEntries) { return new ImmutableStack<>(tmpEntries); }
@SuppressWarnings("unchecked") public ImmutableStack<T> popAll(ImmutableStack<T> other) { if (!topMatches(other)) { throw new IllegalArgumentException("top does not match"); } int size = entries.length - other.entries.length; T[] tmpEntries = (T[]) new Object[size]; System.arraycopy(entries, 0, tmpEntries, 0, size); return new ImmutableStack<>(tmpEntries); }
@SuppressWarnings("unchecked") public ImmutableStack<T> popAll(ImmutableStack<T> other) { if (!topMatches(other)) { throw new IllegalArgumentException("top does not match"); } int size = entries.length - other.entries.length; T[] tmpEntries = (T[]) new Object[size]; System.arraycopy(entries, 0, tmpEntries, 0, size); return new ImmutableStack<>(tmpEntries); }
@SuppressWarnings("unchecked") public ImmutableStack<T> popAll(ImmutableStack<T> other) { if (!topMatches(other)) { throw new IllegalArgumentException("top does not match"); } int size = entries.length - other.entries.length; T[] tmpEntries = (T[]) new Object[size]; System.arraycopy(entries, 0, tmpEntries, 0, size); return new ImmutableStack<>(tmpEntries); }
@SuppressWarnings("unchecked") public ImmutableStack<T> pushAll(ImmutableStack<T> other) { if (other == null) { throw new IllegalArgumentException("null other"); } int size = entries.length + other.entries.length; T[] tmpEntries = null; if (size <= MAX_SIZE) { tmpEntries = (T[]) new Object[size]; System.arraycopy(entries, 0, tmpEntries, 0, entries.length); System.arraycopy(other.entries, 0, tmpEntries, entries.length, other.entries.length); } else { tmpEntries = (T[]) new Object[MAX_SIZE]; // other has size at most MAX_SIZE // must keep all in other // top MAX_SIZE - other.size from this int numFromThis = MAX_SIZE - other.entries.length; System.arraycopy(entries, entries.length - numFromThis, tmpEntries, 0, numFromThis); System.arraycopy(other.entries, 0, tmpEntries, numFromThis, other.entries.length); } return new ImmutableStack<>(tmpEntries); }
@SuppressWarnings("unchecked") public ImmutableStack<T> pushAll(ImmutableStack<T> other) { if (other == null) { throw new IllegalArgumentException("null other"); } int size = entries.length + other.entries.length; T[] tmpEntries = null; if (size <= MAX_SIZE) { tmpEntries = (T[]) new Object[size]; System.arraycopy(entries, 0, tmpEntries, 0, entries.length); System.arraycopy(other.entries, 0, tmpEntries, entries.length, other.entries.length); } else { tmpEntries = (T[]) new Object[MAX_SIZE]; // other has size at most MAX_SIZE // must keep all in other // top MAX_SIZE - other.size from this int numFromThis = MAX_SIZE - other.entries.length; System.arraycopy(entries, entries.length - numFromThis, tmpEntries, 0, numFromThis); System.arraycopy(other.entries, 0, tmpEntries, numFromThis, other.entries.length); } return new ImmutableStack<>(tmpEntries); }
@SuppressWarnings("unchecked") public ImmutableStack<T> pushAll(ImmutableStack<T> other) { if (other == null) { throw new IllegalArgumentException("null other"); } int size = entries.length + other.entries.length; T[] tmpEntries = null; if (size <= MAX_SIZE) { tmpEntries = (T[]) new Object[size]; System.arraycopy(entries, 0, tmpEntries, 0, entries.length); System.arraycopy(other.entries, 0, tmpEntries, entries.length, other.entries.length); } else { tmpEntries = (T[]) new Object[MAX_SIZE]; // other has size at most MAX_SIZE // must keep all in other // top MAX_SIZE - other.size from this int numFromThis = MAX_SIZE - other.entries.length; System.arraycopy(entries, entries.length - numFromThis, tmpEntries, 0, numFromThis); System.arraycopy(other.entries, 0, tmpEntries, numFromThis, other.entries.length); } return new ImmutableStack<>(tmpEntries); }