// A class that uses an object of the LinkedList class to implement Stack. // Barry Cornelius, 19 June 2000 import java.util. LinkedList; import java.util. Iterator; import java.util. List; public class LinkedStack implements Stack { private List iList; public LinkedStack() { iList = new LinkedList(); } public void add(final Object pObject) { iList.add(0, pObject); } public Object getFirst() { if (iList.isEmpty()) { return null; } return iList.get(0); } //BJCHEREFIRST public Object remove() { if (iList.isEmpty()) { return null; } return iList.remove(0); } public int size() { return iList.size(); } public boolean equals(final Object pObject) { if ( pObject==null || getClass()!=pObject.getClass() ) { return false; } return iList.equals(((LinkedStack)pObject).iList); } public int hashCode() { return 0; } public String toString() { if (iList.isEmpty()) { return new String(""); } final StringBuffer tStringBuffer = new StringBuffer(); final Iterator tIterator = iList.iterator(); while (tIterator.hasNext()) { final Object tObject = tIterator.next(); tStringBuffer.append("@" + tObject); } tStringBuffer.deleteCharAt(0); return tStringBuffer.toString(); } }