/** * @throws EmptyStackException * if stack is empty */ public ImmutableStack<T> pop() { if (entries.length == 0) { throw new EmptyStackException(); } int size = entries.length - 1; T[] tmpEntries = makeInternalArray(size); System.arraycopy(entries, 0, tmpEntries, 0, size); return makeStack(tmpEntries); }
/** * @throws EmptyStackException * if stack is empty */ public ImmutableStack<T> pop() { if (entries.length == 0) { throw new EmptyStackException(); } int size = entries.length - 1; T[] tmpEntries = makeInternalArray(size); System.arraycopy(entries, 0, tmpEntries, 0, size); return makeStack(tmpEntries); }
/** * @throws EmptyStackException * if stack is empty */ public ImmutableStack<T> pop() { if (entries.length == 0) { throw new EmptyStackException(); } int size = entries.length - 1; T[] tmpEntries = makeInternalArray(size); System.arraycopy(entries, 0, tmpEntries, 0, size); return makeStack(tmpEntries); }
@SuppressWarnings("unused") public ImmutableStack<T> push(T entry) { if (entry == null) { throw new IllegalArgumentException("null entry"); } if (MAX_SIZE == 0) { return emptyStack(); } int size = entries.length + 1; T[] tmpEntries = null; if (size <= MAX_SIZE) { tmpEntries = makeInternalArray(size); System.arraycopy(entries, 0, tmpEntries, 0, entries.length); tmpEntries[size - 1] = entry; } else { tmpEntries = makeInternalArray(MAX_SIZE); System.arraycopy(entries, 1, tmpEntries, 0, entries.length - 1); tmpEntries[MAX_SIZE - 1] = entry; } return makeStack(tmpEntries); }
@SuppressWarnings("unused") public ImmutableStack<T> push(T entry) { if (entry == null) { throw new IllegalArgumentException("null entry"); } if (MAX_SIZE == 0) { return emptyStack(); } int size = entries.length + 1; T[] tmpEntries = null; if (size <= MAX_SIZE) { tmpEntries = makeInternalArray(size); System.arraycopy(entries, 0, tmpEntries, 0, entries.length); tmpEntries[size - 1] = entry; } else { tmpEntries = makeInternalArray(MAX_SIZE); System.arraycopy(entries, 1, tmpEntries, 0, entries.length - 1); tmpEntries[MAX_SIZE - 1] = entry; } return makeStack(tmpEntries); }
@SuppressWarnings("unused") public ImmutableStack<T> push(T entry) { if (entry == null) { throw new IllegalArgumentException("null entry"); } if (MAX_SIZE == 0) { return emptyStack(); } int size = entries.length + 1; T[] tmpEntries = null; if (size <= MAX_SIZE) { tmpEntries = makeInternalArray(size); System.arraycopy(entries, 0, tmpEntries, 0, entries.length); tmpEntries[size - 1] = entry; } else { tmpEntries = makeInternalArray(MAX_SIZE); System.arraycopy(entries, 1, tmpEntries, 0, entries.length - 1); tmpEntries[MAX_SIZE - 1] = entry; } return makeStack(tmpEntries); }
/** * return a new stack with the top replaced with t */ public ImmutableStack<T> replaceTop(T t) { if (isEmpty()) { throw new EmptyStackException(); } int size = entries.length; T[] tmpEntries = makeInternalArray(size); System.arraycopy(entries, 0, tmpEntries, 0, entries.length - 1); tmpEntries[size - 1] = t; return makeStack(tmpEntries); } }
/** * return a new stack with the top replaced with t */ public ImmutableStack<T> replaceTop(T t) { if (isEmpty()) { throw new EmptyStackException(); } int size = entries.length; T[] tmpEntries = makeInternalArray(size); System.arraycopy(entries, 0, tmpEntries, 0, entries.length - 1); tmpEntries[size - 1] = t; return makeStack(tmpEntries); } }
/** * return a new stack with the top replaced with t */ public ImmutableStack<T> replaceTop(T t) { if (isEmpty()) { throw new EmptyStackException(); } int size = entries.length; T[] tmpEntries = makeInternalArray(size); System.arraycopy(entries, 0, tmpEntries, 0, entries.length - 1); tmpEntries[size - 1] = t; return makeStack(tmpEntries); } }