/** * Pushes a new item onto the top of this stack. The pushed item is also returned. This is * equivalent to calling <code>add</code>. * * @param item the item to be added * @return the item just pushed */ public Object push(Object item) { add(item); return item; }
/** * Return <code>true</code> if this stack is currently empty. * <p/> * This method exists for compatibility with <code>java.util.Stack</code>. New users of this * class should use <code>isEmpty</code> instead. * * @return true if the stack is currently empty */ public boolean empty() { return isEmpty(); }
public Iterator getPrefixes(String uri) { //create an arraylist that contains the relevant prefixes String[] uris = (String[])uriStack.toArray(new String[uriStack.size()]); ArrayList tempList = new ArrayList(); for (int i = 0; i < uris.length; i++) { if (uris[i].equals(uri)) { tempList.add(prefixStack.get(i)); //we assume that array conversion preserves the order } } //by now all the relevant prefixes are collected //make a new iterator and provide a wrapper iterator to //obey the contract on the API return new WrappingIterator(tempList.iterator()); }
public Iterator getPrefixes(String uri) { //create an arraylist that contains the relevant prefixes String[] uris = (String[])uriStack.toArray(new String[uriStack.size()]); ArrayList tempList = new ArrayList(); for (int i = 0; i < uris.length; i++) { if (uris[i].equals(uri)) { tempList.add(prefixStack.get(i)); //we assume that array conversion preserves the order } } //by now all the relevant prefixes are collected //make a new iterator and provide a wrapper iterator to //obey the contract on the API return new WrappingIterator(tempList.iterator()); }
/** * Pushes a new item onto the top of this stack. The pushed item is also returned. This is * equivalent to calling <code>add</code>. * * @param item the item to be added * @return the item just pushed */ public Object push(Object item) { add(item); return item; }
/** * Return <code>true</code> if this stack is currently empty. * <p/> * This method exists for compatibility with <code>java.util.Stack</code>. New users of this * class should use <code>isEmpty</code> instead. * * @return true if the stack is currently empty */ public boolean empty() { return isEmpty(); }
/** * Returns the top item off of this stack without removing it. * * @return the top item on the stack * @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); } }