/** * Returns the 1-based position where an object is on this stack. If the object <tt>o</tt> * occurs as an item in this stack, this method returns the distance from the top of the stack * of the occurrence nearest the top of the stack; the topmost item on the stack is considered * to be at distance <tt>1</tt>. The <tt>equals</tt> method is used to compare <tt>o</tt> to the * items in this stack. * * @param o * the desired object. * @return the 1-based position from the top of the stack where the object is located; the * return value <code>-1</code> indicates that the object is not on the stack. */ public final int search(final T o) { int i = lastIndexOf(o); if (i >= 0) { return size() - i; } return -1; } }
/** * Returns the 1-based position where an object is on this stack. If the object <tt>o</tt> * occurs as an item in this stack, this method returns the distance from the top of the stack * of the occurrence nearest the top of the stack; the topmost item on the stack is considered * to be at distance <tt>1</tt>. The <tt>equals</tt> method is used to compare <tt>o</tt> * to the items in this stack. * * @param o * the desired object. * @return the 1-based position from the top of the stack where the object is located; the * return value <code>-1</code> indicates that the object is not on the stack. */ public final int search(final Object o) { int i = lastIndexOf(o); if (i >= 0) { return size() - i; } return -1; } }
/** * Returns the 1-based position where an object is on this stack. If the object <tt>o</tt> * occurs as an item in this stack, this method returns the distance from the top of the stack * of the occurrence nearest the top of the stack; the topmost item on the stack is considered * to be at distance <tt>1</tt>. The <tt>equals</tt> method is used to compare <tt>o</tt> to the * items in this stack. * * @param o * the desired object. * @return the 1-based position from the top of the stack where the object is located; the * return value <code>-1</code> indicates that the object is not on the stack. */ public final int search(final T o) { int i = lastIndexOf(o); if (i >= 0) { return size() - i; } return -1; } }