001: /*
002: * Primitive Collections for Java.
003: * Copyright (C) 2003 Søren Bak
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package bak.pcj.list;
020:
021: import bak.pcj.ShortCollection;
022:
023: /**
024: * This class represents an array implemenation of stacks of
025: * short values.
026: *
027: * @see java.util.ArrayList
028: *
029: * @author Søren Bak
030: * @version 1.1 2003/3/3
031: * @since 1.0
032: */
033: public class ShortArrayStack extends ShortArrayList implements
034: ShortStack {
035:
036: /**
037: * Creates a new array stack with capacity 10 and a relative
038: * growth factor of 1.0.
039: *
040: * @see #ShortArrayStack(int,double)
041: */
042: public ShortArrayStack() {
043: super ();
044: }
045:
046: /**
047: * Creates a new array stack with the same elements as a
048: * specified collection. The elements of the specified collection
049: * are pushed in the collection's iteration order.
050: *
051: * @param c
052: * the collection whose elements to add to the new
053: * stack.
054: *
055: * @throws NullPointerException
056: * if <tt>c</tt> is <tt>null</tt>.
057: */
058: public ShortArrayStack(ShortCollection c) {
059: super (c);
060: }
061:
062: /**
063: * Creates a new array stack with the same elements as a
064: * specified array. The elements of the specified array
065: * are pushed in the order of the array.
066: *
067: * @param a
068: * the array whose elements to add to the new
069: * stack.
070: *
071: * @throws NullPointerException
072: * if <tt>a</tt> is <tt>null</tt>.
073: *
074: * @since 1.1
075: */
076: public ShortArrayStack(short[] a) {
077: super (a);
078: }
079:
080: /**
081: * Creates a new array stack with a specified capacity and a
082: * relative growth factor of 1.0.
083: *
084: * @param capacity
085: * the initial capacity of the stack.
086: *
087: * @see #ShortArrayStack(int,double)
088: *
089: * @throws IllegalArgumentException
090: * if <tt>capacity</tt> is negative.
091: */
092: public ShortArrayStack(int capacity) {
093: super (capacity);
094: }
095:
096: /**
097: * Creates a new array stack with a specified capacity and
098: * relative growth factor.
099: *
100: * <p>The array capacity increases to <tt>capacity()*(1+growthFactor)</tt>.
101: * This strategy is good for avoiding many capacity increases, but
102: * the amount of wasted memory is approximately the size of the stack.
103: *
104: * @param capacity
105: * the initial capacity of the stack.
106: *
107: * @param growthFactor
108: * the relative amount with which to increase the
109: * the capacity when a capacity increase is needed.
110: *
111: * @throws IllegalArgumentException
112: * if <tt>capacity</tt> is negative;
113: * if <tt>growthFactor</tt> is negative.
114: */
115: public ShortArrayStack(int capacity, double growthFactor) {
116: super (capacity, growthFactor);
117: }
118:
119: /**
120: * Creates a new array stack with a specified capacity and
121: * absolute growth factor.
122: *
123: * <p>The array capacity increases to <tt>capacity()+growthChunk</tt>.
124: * This strategy is good for avoiding wasting memory. However, an
125: * overhead is potentially introduced by frequent capacity increases.
126: *
127: * @param capacity
128: * the initial capacity of the stack.
129: *
130: * @param growthChunk
131: * the absolute amount with which to increase the
132: * the capacity when a capacity increase is needed.
133: *
134: * @throws IllegalArgumentException
135: * if <tt>capacity</tt> is negative;
136: * if <tt>growthChunk</tt> is negative.
137: */
138: public ShortArrayStack(int capacity, int growthChunk) {
139: super (capacity, growthChunk);
140: }
141:
142: public void push(short v) {
143: add(v);
144: }
145:
146: public short pop() {
147: return removeElementAt(size() - 1);
148: }
149:
150: public short peek() {
151: return get(size() - 1);
152: }
153:
154: }
|