@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); }
/** * 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); } }
@Override public CallStack pop() { final CallStack ret = (CallStack) super.pop(); return ret; }
/** * @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("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); }
/** * @return {@code true} iff {@code other.size() = k}, {@code k <= this.size()}, and the * top k elements of this equal other * @throws IllegalArgumentException * if other == null */ public boolean topMatches(ImmutableStack<T> other) throws IllegalArgumentException { if (other == null) { throw new IllegalArgumentException("other == null"); } if (other.size() > size()) { return false; } for (int i = other.size() - 1, j = this.size() - 1; i >= 0; i--, j--) { if (!other.get(i).equals(get(j))) return false; } return true; }
@Override public CallStack push(CallerSiteContext entry) { final CallStack ret = (CallStack) super.push(entry); return ret; }
/** * @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("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); }
/** * @return {@code true} iff {@code other.size() = k}, {@code k <= this.size()}, and the * top k elements of this equal other * @throws IllegalArgumentException * if other == null */ public boolean topMatches(ImmutableStack<T> other) throws IllegalArgumentException { if (other == null) { throw new IllegalArgumentException("other == null"); } if (other.size() > size()) { return false; } for (int i = other.size() - 1, j = this.size() - 1; i >= 0; i--, j--) { if (!other.get(i).equals(get(j))) return false; } return true; }
@Override public CallStack push(CallerSiteContext entry) { final CallStack ret = (CallStack) super.push(entry); return ret; }
/** * 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); } }
/** * @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("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); }
/** * @return {@code true} iff {@code other.size() = k}, {@code k <= this.size()}, and the * top k elements of this equal other * @throws IllegalArgumentException * if other == null */ public boolean topMatches(ImmutableStack<T> other) throws IllegalArgumentException { if (other == null) { throw new IllegalArgumentException("other == null"); } if (other.size() > size()) { return false; } for (int i = other.size() - 1, j = this.size() - 1; i >= 0; i--, j--) { if (!other.get(i).equals(get(j))) return false; } return true; }
@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); }
@Override public CallStack pop() { final CallStack ret = (CallStack) super.pop(); return ret; }
/** * 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); } }
@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("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); }