19223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet/* 29223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * Copyright (C) 2010 The Android Open Source Project 39223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * 49223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * Licensed under the Apache License, Version 2.0 (the "License"); 59223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * you may not use this file except in compliance with the License. 69223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * You may obtain a copy of the License at 79223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * 89223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * http://www.apache.org/licenses/LICENSE-2.0 99223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * 109223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * Unless required by applicable law or agreed to in writing, software 119223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * distributed under the License is distributed on an "AS IS" BASIS, 129223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * See the License for the specific language governing permissions and 149223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * limitations under the License. 159223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet */ 169223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 179223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohetpackage com.android.layoutlib.bridge.impl; 189223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 199223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohetimport java.util.ArrayList; 209223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 219223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet/** 229223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * Custom Stack implementation on top of an {@link ArrayList} instead of 239223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * using {@link java.util.Stack} which is on top of a vector. 249223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * 259223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * @param <T> 269223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet */ 279223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohetpublic class Stack<T> extends ArrayList<T> { 289223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 299223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet private static final long serialVersionUID = 1L; 309223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 319223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet public Stack() { 329223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet super(); 339223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet } 349223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 359223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet public Stack(int size) { 369223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet super(size); 379223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet } 389223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 399223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet /** 409223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * Pushes the given object to the stack 419223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * @param object the object to push 429223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet */ 439223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet public void push(T object) { 449223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet add(object); 459223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet } 469223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 479223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet /** 489223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * Remove the object at the top of the stack and returns it. 499223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * @return the removed object or null if the stack was empty. 509223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet */ 519223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet public T pop() { 529223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet if (size() > 0) { 539223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet return remove(size() - 1); 549223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet } 559223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 569223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet return null; 579223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet } 589223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 599223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet /** 609223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * Returns the object at the top of the stack. 619223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet * @return the object at the top or null if the stack is empty. 629223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet */ 639223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet public T peek() { 649223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet if (size() > 0) { 659223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet return get(size() - 1); 669223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet } 679223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet 689223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet return null; 699223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet } 709223b6737c56619c02125ce988bb21fc4fde264bXavier Ducrohet} 71