1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.layoutlib.bridge.impl; 18 19import java.util.ArrayList; 20 21/** 22 * Custom Stack implementation on top of an {@link ArrayList} instead of 23 * using {@link java.util.Stack} which is on top of a vector. 24 * 25 * @param <T> 26 */ 27public class Stack<T> extends ArrayList<T> { 28 29 private static final long serialVersionUID = 1L; 30 31 public Stack() { 32 super(); 33 } 34 35 public Stack(int size) { 36 super(size); 37 } 38 39 /** 40 * Pushes the given object to the stack 41 * @param object the object to push 42 */ 43 public void push(T object) { 44 add(object); 45 } 46 47 /** 48 * Remove the object at the top of the stack and returns it. 49 * @return the removed object or null if the stack was empty. 50 */ 51 public T pop() { 52 if (size() > 0) { 53 return remove(size() - 1); 54 } 55 56 return null; 57 } 58 59 /** 60 * Returns the object at the top of the stack. 61 * @return the object at the top or null if the stack is empty. 62 */ 63 public T peek() { 64 if (size() > 0) { 65 return get(size() - 1); 66 } 67 68 return null; 69 } 70} 71