1 37 package org.webharvest.utils; 38 39 import org.webharvest.exception.BaseException; 40 41 import java.util.LinkedList ; 42 import java.util.NoSuchElementException ; 43 44 47 public class Stack { 48 49 private LinkedList list = new LinkedList (); 50 51 public void push(Object o) { 52 list.addLast(o); 53 } 54 55 public Object pop() { 56 try { 57 return list.removeLast(); 58 } catch (NoSuchElementException e) { 59 throw new BaseException("Cannot pop element from the empty stack!", e); 60 } 61 } 62 63 public Object [] popAll() { 64 Object [] res = list.toArray(); 65 list.clear(); 66 67 return res; 68 } 69 70 public Object peek() { 71 return list.getLast(); 72 } 73 74 public boolean isEmpty() { 75 return list.isEmpty(); 76 } 77 78 public int size() { 79 return list.size(); 80 } 81 82 } | Popular Tags |