List of usage examples for java.util EmptyStackException EmptyStackException
public EmptyStackException()
From source file:CharacterStack.java
/** * @return//from ww w . ja v a2 s. c om */ public char peek() { final int len = size; if (size == 0) { throw new EmptyStackException(); } return buffer[len - 1]; }
From source file:CharacterStack.java
/** * @return/*w w w. ja v a2s .co m*/ */ public char pop() { int len = size; if (len == 0) { throw new EmptyStackException(); } --len; final char result = buffer[len]; size = len; return result; }
From source file:ArrayListStack.java
/** * Looks at the object at the top of this stack without removing it. * //from w w w .j av a2s.co m * @return The object at the top of this stack * @exception EmptyStackException * If this stack is empty. */ public final T peek() { int size = size(); if (size == 0) { throw new EmptyStackException(); } return get(size - 1); }
From source file:com.cup.digester.ArrayStack.java
/** * Returns the top item off of this stack without removing it. * * @return the top item on the stack/* w w w . jav a2s. co m*/ * @throws EmptyStackException if the stack is empty */ public E peek() throws EmptyStackException { int n = size(); if (n <= 0) { throw new EmptyStackException(); } else { return get(n - 1); } }
From source file:FastStack.java
/** * Returns the object at the top of the stack without removing it. * /* www. j a v a 2s .com*/ * @return The object at the top of the stack. */ public Object peek() { if (this.size == 0) { throw new EmptyStackException(); } return this.contents[this.size - 1]; }
From source file:FastStack.java
/** * Removes and returns the object from the top of the stack. * //from www. ja va 2s . c o m * @return The object. */ public Object pop() { if (this.size == 0) { throw new EmptyStackException(); } this.size -= 1; final Object retval = this.contents[this.size]; this.contents[this.size] = null; return retval; }
From source file:ArrayStack.java
/** * Returns the top item off of this stack without removing it. * * @return the top item on the stack/*w ww . j ava 2s. com*/ * @throws EmptyStackException if the stack is empty */ public Object peek() throws EmptyStackException { int n = size(); if (n <= 0) { throw new EmptyStackException(); } else { return get(n - 1); } }
From source file:com.cup.digester.ArrayStack.java
/** * Returns the n'th item down (zero-relative) from the top of this * stack without removing it.//from www . j av a 2 s .c o m * * @param n the number of items down to go * @return the n'th item on the stack, zero relative * @throws EmptyStackException if there are not enough items on the * stack to satisfy this request */ public E peek(int n) throws EmptyStackException { int m = (size() - n) - 1; if (m < 0) { throw new EmptyStackException(); } else { return get(m); } }
From source file:com.cup.digester.ArrayStack.java
/** * Pops the top item off of this stack and return it. * * @return the top item on the stack/*from w w w. j a v a2s .c o m*/ * @throws EmptyStackException if the stack is empty */ public E pop() throws EmptyStackException { int n = size(); if (n <= 0) { throw new EmptyStackException(); } else { return remove(n - 1); } }
From source file:ArrayStack.java
/** * Returns the n'th item down (zero-relative) from the top of this * stack without removing it.//w ww . j a v a 2 s . co m * * @param n the number of items down to go * @return the n'th item on the stack, zero relative * @throws EmptyStackException if there are not enough items on the * stack to satisfy this request */ public Object peek(int n) throws EmptyStackException { int m = (size() - n) - 1; if (m < 0) { throw new EmptyStackException(); } else { return get(m); } }