package org.apache.commons.collections;

import java.util.ArrayList;
import java.util.EmptyStackException;

public class ArrayStack extends ArrayList implements Buffer {
  private static final long serialVersionUID = 2130079159931574599L;
  
  public ArrayStack() {}
  
  public ArrayStack(int paramInt) {
    super(paramInt);
  }
  
  public boolean empty() {
    return isEmpty();
  }
  
  public Object get() {
    int i = size();
    if (i == 0)
      throw new BufferUnderflowException(); 
    return get(i - 1);
  }
  
  public Object peek() throws EmptyStackException {
    int i = size();
    if (i <= 0)
      throw new EmptyStackException(); 
    return get(i - 1);
  }
  
  public Object peek(int paramInt) throws EmptyStackException {
    int i = size() - paramInt - 1;
    if (i < 0)
      throw new EmptyStackException(); 
    return get(i);
  }
  
  public Object pop() throws EmptyStackException {
    int i = size();
    if (i <= 0)
      throw new EmptyStackException(); 
    return remove(i - 1);
  }
  
  public Object push(Object paramObject) {
    add((E)paramObject);
    return paramObject;
  }
  
  public Object remove() {
    int i = size();
    if (i == 0)
      throw new BufferUnderflowException(); 
    return remove(i - 1);
  }
  
  public int search(Object paramObject) {
    int i = size() - 1;
    for (byte b = 1; i >= 0; b++) {
      E e = get(i);
      if ((paramObject == null && e == null) || (paramObject != null && paramObject.equals(e)))
        return b; 
      i--;
    } 
    return -1;
  }
}
