KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > util > FastStack


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.util;
12
13 import java.util.ArrayList JavaDoc;
14
15 /**
16  * Fast Stack is similar to java.uiti.Stack, but simplified for speed. It uses
17  * ArrayList as an underlying collection. The methods in this class are not
18  * thread safe.
19  */

20 public class FastStack extends ArrayList JavaDoc {
21
22     private static final long serialVersionUID = 1L;
23     
24     private int last = -1;
25
26     public FastStack() {
27         super();
28     }
29
30     public final Object JavaDoc push(Object JavaDoc item) {
31         super.add(item);
32         last++;
33         return item;
34     }
35
36     public final Object JavaDoc pop() {
37         return super.remove(last--);
38     }
39
40     public final Object JavaDoc peek() {
41         return super.get(last);
42     }
43
44     public final boolean empty() {
45         return last < 0;
46     }
47 }
48
Popular Tags