/** * Returns the element on the top of the stack. * * @return the element on the top of the stack * @throws EmptyStackException if the stack is empty */ public Object get() { int size = size(); if (size == 0) { throw new EmptyStackException(); } return get(size - 1); }
/** * Returns the element on the top of the stack. * * @return the element on the top of the stack * @throws EmptyStackException if the stack is empty */ public Object get() { int size = size(); if (size == 0) { throw new EmptyStackException(); } return get(size - 1); }
/** * 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); } }
/** * 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); } }
/** * Returns the n'th item down (zero-relative) from the top of this stack without removing it. * * @param n the number of items down to go * @return the n'th item on the stack, zero relative * @throws EmptyStackException if there are not enough items on the stack to satisfy this * request */ public Object peek(int n) throws EmptyStackException { int m = (size() - n) - 1; if (m < 0) { throw new EmptyStackException(); } else { return get(m); } }
/** * Returns the n'th item down (zero-relative) from the top of this stack without removing it. * * @param n the number of items down to go * @return the n'th item on the stack, zero relative * @throws EmptyStackException if there are not enough items on the stack to satisfy this * request */ public Object peek(int n) throws EmptyStackException { int m = (size() - n) - 1; if (m < 0) { throw new EmptyStackException(); } else { return get(m); } }
/** * Returns the one-based position of the distance from the top that the specified object exists * on this stack, where the top-most element is considered to be at distance <code>1</code>. If * the object is not present on the stack, return <code>-1</code> instead. The * <code>equals()</code> method is used to compare to the items in this stack. * * @param object the object to be searched for * @return the 1-based depth into the stack of the object, or -1 if not found */ public int search(Object object) { int i = size() - 1; // Current index int n = 1; // Current distance while (i >= 0) { Object current = get(i); if ((object == null && current == null) || (object != null && object.equals(current))) { return n; } i--; n++; } return -1; }
/** * Returns the one-based position of the distance from the top that the specified object exists * on this stack, where the top-most element is considered to be at distance <code>1</code>. If * the object is not present on the stack, return <code>-1</code> instead. The * <code>equals()</code> method is used to compare to the items in this stack. * * @param object the object to be searched for * @return the 1-based depth into the stack of the object, or -1 if not found */ public int search(Object object) { int i = size() - 1; // Current index int n = 1; // Current distance while (i >= 0) { Object current = get(i); if ((object == null && current == null) || (object != null && object.equals(current))) { return n; } i--; n++; } return -1; }
public String getPrefix(String uri) { //do the corrections as per the javadoc int index = uriStack.indexOf(uri); if (index != -1) { return (String)prefixStack.get(index); } if (parentNsContext != null) { return parentNsContext.getPrefix(uri); } return null; }
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 String getPrefix(String uri) { //do the corrections as per the javadoc int index = uriStack.indexOf(uri); if (index != -1) { return (String)prefixStack.get(index); } if (parentNsContext != null) { return parentNsContext.getPrefix(uri); } return null; }
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 String getNamespaceURI(String prefix) { //do the corrections as per the javadoc if (prefixStack.contains(prefix)) { int index = prefixStack.indexOf(prefix); return (String)uriStack.get(index); } if (parentNsContext != null) { return parentNsContext.getPrefix(prefix); } return null; }
public String getNamespaceURI(String prefix) { //do the corrections as per the javadoc if (prefixStack.contains(prefix)) { int index = prefixStack.indexOf(prefix); return (String)uriStack.get(index); } if (parentNsContext != null) { return parentNsContext.getPrefix(prefix); } return null; }