1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 ///////////////////////////////////////////////////////////////////////////////
23 * A stack of int primitives, backed by a TIntArrayList.
25 * @author Eric D. Friedman, Rob Eden
26 * @version $Id: PStack.template,v 1.2 2007/02/28 23:03:57 robeden Exp $
29 public class TIntStack {
31 /** the list used to hold the stack values. */
32 protected TIntArrayList _list;
34 public static final int DEFAULT_CAPACITY = TIntArrayList.DEFAULT_CAPACITY;
37 * Creates a new <code>TIntStack</code> instance with the default
41 this(DEFAULT_CAPACITY);
45 * Creates a new <code>TIntStack</code> instance with the
48 * @param capacity the initial depth of the stack
50 public TIntStack(int capacity) {
51 _list = new TIntArrayList(capacity);
55 * Pushes the value onto the top of the stack.
57 * @param val an <code>int</code> value
59 public void push(int val) {
64 * Removes and returns the value at the top of the stack.
66 * @return an <code>int</code> value
69 return _list.remove(_list.size() - 1);
73 * Returns the value at the top of the stack.
75 * @return an <code>int</code> value
78 return _list.get(_list.size() - 1);
82 * Returns the current depth of the stack.
89 * Clears the stack, reseting its capacity to the default.
92 _list.clear(DEFAULT_CAPACITY);
96 * Clears the stack without releasing its internal capacity allocation.
103 * Copies the contents of the stack into a native array. Note that this will NOT
104 * pop them out of the stack.
106 * @return an <code>int[]</code> value
108 public int[] toNativeArray() {
109 return _list.toNativeArray();
113 * Copies a slice of the list into a native array. Note that this will NOT
114 * pop them out of the stack.
116 * @param dest the array to copy into.
118 public void toNativeArray(int[] dest) {
119 _list.toNativeArray(dest, 0, size());