001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/util/tags/sakai_2-4-1/util-util/util/src/java/org/sakaiproject/util/StackIterator.java $
003: * $Id: StackIterator.java 22113 2007-03-03 02:21:20Z jimeng@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.util;
021:
022: import java.util.Iterator;
023: import java.util.Stack;
024:
025: /**
026: * StackIterator is both a java.util.Iterator and a stack (though not a java.util.Collection)
027: *
028: */
029: public class StackIterator<E> implements Iterator<E> {
030: protected Stack<E> stack;
031:
032: /**
033: * @param stack
034: */
035: public StackIterator() {
036: this .stack = new Stack<E>();
037: }
038:
039: /* (non-Javadoc)
040: * @see java.util.Iterator#hasNext()
041: */
042: public boolean hasNext() {
043: return !this .stack.empty();
044: }
045:
046: /* (non-Javadoc)
047: * @see java.util.Iterator#next()
048: */
049: public E next() {
050: return this .stack.pop();
051: }
052:
053: /* (non-Javadoc)
054: * @see java.util.Iterator#remove()
055: */
056: public void remove() {
057: this .stack.pop();
058: }
059:
060: /* (non-Javadoc)
061: * @see java.util.Stack#empty()
062: */
063: public boolean empty() {
064: // TODO Auto-generated method stub
065: return stack.empty();
066: }
067:
068: /* (non-Javadoc)
069: * @see java.util.Stack#peek()
070: */
071: public synchronized E peek() {
072: // TODO Auto-generated method stub
073: return stack.peek();
074: }
075:
076: /* (non-Javadoc)
077: * @see java.util.Stack#pop()
078: */
079: public synchronized E pop() {
080: // TODO Auto-generated method stub
081: return stack.pop();
082: }
083:
084: /* (non-Javadoc)
085: * @see java.util.Stack#push(java.lang.Object)
086: */
087: public E push(E arg0) {
088: // TODO Auto-generated method stub
089: return stack.push(arg0);
090: }
091:
092: /* (non-Javadoc)
093: * @see java.util.Stack#search(java.lang.Object)
094: */
095: public synchronized int search(Object arg0) {
096: // TODO Auto-generated method stub
097: return stack.search(arg0);
098: }
099:
100: }
|