| 68 | 1 package fschmidt.util.java; | 
|  | 2 | 
|  | 3 import java.util.Collection; | 
|  | 4 import java.util.List; | 
|  | 5 import java.util.ArrayList; | 
|  | 6 import java.util.EmptyStackException; | 
|  | 7 | 
|  | 8 | 
|  | 9 public class ArrayStack<E> extends ArrayList<E> implements Stack<E> { | 
|  | 10 | 
|  | 11 	public ArrayStack() {} | 
|  | 12 | 
|  | 13 	public ArrayStack(Collection<E> c) { | 
|  | 14 		super(c); | 
|  | 15 	} | 
|  | 16 | 
|  | 17 	@Override public void push(E item) { | 
|  | 18 		add(item); | 
|  | 19 	} | 
|  | 20 | 
|  | 21 	@Override public E pop() throws EmptyStackException { | 
|  | 22 		int	len = size(); | 
|  | 23 		if (len == 0) | 
|  | 24 			throw new EmptyStackException(); | 
|  | 25 		return remove(len - 1); | 
|  | 26 	} | 
|  | 27 | 
|  | 28 	@Override public E peek() throws EmptyStackException { | 
|  | 29 		int	len = size(); | 
|  | 30 		if (len == 0) | 
|  | 31 			throw new EmptyStackException(); | 
|  | 32 		return get(len - 1); | 
|  | 33 	} | 
|  | 34 | 
|  | 35 } |