01: /*
02: * Copyright (C) 2007 Jared Alexander Spigner
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or any later version.
08: *
09: * 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 GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * jspigner@openjx.org
19: *
20: * JXStack.java
21: *
22: * Created on June 8, 2007, 11:49 PM
23: *
24: */
25:
26: package org.openjx.core;
27:
28: import java.util.EmptyStackException;
29: import java.util.Stack;
30:
31: import org.openjx.conf.JXGLOBAL;
32:
33: /**
34: * This class allows the JXObjects to be utilized as a stack.
35: *
36: * @author Jared Spigner
37: */
38: public class JXStack {
39:
40: /** The stack is the actual stack device used to store JXObjects. */
41: protected Stack<JXObject> stack;
42:
43: /** This is the constructor for the JXStack class. It creates a new
44: * instance of JXStack.
45: */
46: public JXStack() {
47: this .stack = new Stack<JXObject>();
48: }
49:
50: /**
51: * This method simply returns an element in the stack by an index number.
52: *
53: * @param idx is the index number of the element we want returned.
54: *
55: * @return the corresponding JXObject.
56: */
57: public JXObject getElement(int idx) {
58: return this .stack.elementAt(idx);
59: }
60:
61: /**
62: * This method returns the length of the stack.
63: *
64: * @return the length of the stack.
65: */
66: public int getLength() {
67: return this .stack.size();
68: }
69:
70: /**
71: * This method pops an object onto the stack.
72: *
73: * @return the object we are popping off the stack.
74: */
75: public JXObject Pop() {
76: JXObject obj = null;
77:
78: obj = this .stack.pop();
79:
80: return obj;
81: }
82:
83: /**
84: * This method pushes an object onto the stack.
85: *
86: * @param obj is the object we want to push onto the stack.
87: */
88: public void Push(JXObject obj) {
89: this.stack.push(obj);
90: }
91:
92: }
|