KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bak > pcj > list > DoubleArrayStack


1 /*
2  * Primitive Collections for Java.
3  * Copyright (C) 2003 Søren Bak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package bak.pcj.list;
20
21 import bak.pcj.DoubleCollection;
22
23 /**
24  * This class represents an array implemenation of stacks of
25  * double values.
26  *
27  * @see java.util.ArrayList
28  *
29  * @author Søren Bak
30  * @version 1.1 2003/3/3
31  * @since 1.0
32  */

33 public class DoubleArrayStack extends DoubleArrayList implements DoubleStack {
34
35     /**
36      * Creates a new array stack with capacity 10 and a relative
37      * growth factor of 1.0.
38      *
39      * @see #DoubleArrayStack(int,double)
40      */

41     public DoubleArrayStack() {
42         super();
43     }
44
45     /**
46      * Creates a new array stack with the same elements as a
47      * specified collection. The elements of the specified collection
48      * are pushed in the collection's iteration order.
49      *
50      * @param c
51      * the collection whose elements to add to the new
52      * stack.
53      *
54      * @throws NullPointerException
55      * if <tt>c</tt> is <tt>null</tt>.
56      */

57     public DoubleArrayStack(DoubleCollection c) {
58         super(c);
59     }
60
61     /**
62      * Creates a new array stack with the same elements as a
63      * specified array. The elements of the specified array
64      * are pushed in the order of the array.
65      *
66      * @param a
67      * the array whose elements to add to the new
68      * stack.
69      *
70      * @throws NullPointerException
71      * if <tt>a</tt> is <tt>null</tt>.
72      *
73      * @since 1.1
74      */

75     public DoubleArrayStack(double[] a) {
76         super(a);
77     }
78
79     /**
80      * Creates a new array stack with a specified capacity and a
81      * relative growth factor of 1.0.
82      *
83      * @param capacity
84      * the initial capacity of the stack.
85      *
86      * @see #DoubleArrayStack(int,double)
87      *
88      * @throws IllegalArgumentException
89      * if <tt>capacity</tt> is negative.
90      */

91     public DoubleArrayStack(int capacity) {
92         super(capacity);
93     }
94
95     /**
96      * Creates a new array stack with a specified capacity and
97      * relative growth factor.
98      *
99      * <p>The array capacity increases to <tt>capacity()*(1+growthFactor)</tt>.
100      * This strategy is good for avoiding many capacity increases, but
101      * the amount of wasted memory is approximately the size of the stack.
102      *
103      * @param capacity
104      * the initial capacity of the stack.
105      *
106      * @param growthFactor
107      * the relative amount with which to increase the
108      * the capacity when a capacity increase is needed.
109      *
110      * @throws IllegalArgumentException
111      * if <tt>capacity</tt> is negative;
112      * if <tt>growthFactor</tt> is negative.
113      */

114     public DoubleArrayStack(int capacity, double growthFactor) {
115         super(capacity, growthFactor);
116     }
117
118     /**
119      * Creates a new array stack with a specified capacity and
120      * absolute growth factor.
121      *
122      * <p>The array capacity increases to <tt>capacity()+growthChunk</tt>.
123      * This strategy is good for avoiding wasting memory. However, an
124      * overhead is potentially introduced by frequent capacity increases.
125      *
126      * @param capacity
127      * the initial capacity of the stack.
128      *
129      * @param growthChunk
130      * the absolute amount with which to increase the
131      * the capacity when a capacity increase is needed.
132      *
133      * @throws IllegalArgumentException
134      * if <tt>capacity</tt> is negative;
135      * if <tt>growthChunk</tt> is negative.
136      */

137     public DoubleArrayStack(int capacity, int growthChunk) {
138         super(capacity, growthChunk);
139     }
140
141     public void push(double v)
142     { add(v); }
143
144     public double pop()
145     { return removeElementAt(size()-1); }
146
147     public double peek()
148     { return get(size()-1); }
149
150 }
Popular Tags