Source Code Cross Referenced for OperandStack.java in  » Development » jdec » net » sf » jdec » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » jdec » net.sf.jdec.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  OperandStack.java Copyright (c) 2006,07 Swaroop Belur 
003:         *  
004:         * This program is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU General Public License
006:         * as published by the Free Software Foundation; either version 2
007:         * of the License, or (at your option) any later version.
008:
009:         * This program is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         * GNU General Public License for more details.
013:
014:         * You should have received a copy of the GNU General Public License
015:         * along with this program; if not, write to the Free Software
016:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
017:         *
018:         */
019:
020:        package net.sf.jdec.core;
021:
022:        import java.util.EmptyStackException;
023:        import java.util.Stack;
024:
025:        import net.sf.jdec.exceptions.StackOperationException;
026:        import net.sf.jdec.util.AllExceptionHandler;
027:
028:        public class OperandStack extends Stack {
029:
030:            public OperandStack() {
031:                super ();
032:            }
033:
034:            /***
035:             * Below are methods which may be useful 
036:             * while doing some Error checking 
037:             * Actually Not Needed directly as the variable
038:             * can be accessed....BUT Added Them
039:             * Since it is extending Stack Class and not
040:             * doing anything else
041:             * @return
042:             */
043:
044:            public int getEntryCount() {
045:                return this .elementCount;
046:            }
047:
048:            public Operand getTopOfStack() {
049:                Operand topofstack = (Operand) this .pop();
050:                return topofstack;
051:            }
052:
053:            public Operand peekTopOfStack() {
054:                if (this .isEmpty() == false) {
055:                    Operand topofstack = (Operand) this .peek();
056:                    return topofstack;
057:                }
058:                return null;
059:            }
060:
061:            public Integer getStackTopType() {
062:                Operand topofstack = (Operand) this .peek();
063:                return new Integer(topofstack.getOperandType());
064:            }
065:
066:            /**
067:             * Just A error or Debug method ...Can be used in case of ClassCastException
068:             * The Advantage of This method is that it will set the position of the First 
069:             * corrupt Object in the stack...(If there are many , it will set the first)
070:             * Usage 
071:             * 1> Call checkStackSanity
072:             * 2>Then Either
073:             *  Call getWrongClassEntryPos For That operandStack(this class) Object
074:             * Or
075:             *  Call getCorruptObject
076:             *  
077:             * @return
078:             */
079:
080:            public boolean checkStackSanity() {
081:                boolean ok = true;
082:                int count = this .getEntryCount();
083:                for (int i = 0; i < count; i++) {
084:                    Object o = this .peek();
085:                    if (o instanceof  Operand) {
086:                        ok = true;
087:                        continue;
088:                    } else {
089:                        ok = false;
090:                        setCorruptEntryPosition(i);
091:                        break;
092:                    }
093:                }
094:                return ok;
095:
096:            }
097:
098:            private void setCorruptEntryPosition(int i) {
099:                wrongClassEntryPos = i;
100:            }
101:
102:            private int wrongClassEntryPos = -1;
103:
104:            /***
105:             * 
106:             * @return position in stack of First corrupt object
107:             * If the user desires the object itself Then
108:             *  See getCorruptObject() Method
109:             * 
110:             */
111:
112:            public int getWrongClassEntryPos() {
113:                return wrongClassEntryPos;
114:            }
115:
116:            /***
117:             *  
118:             * @return Either null or the corruptObject
119:             * NOTE: This method returns null in case the 
120:             * user calls this method before calling
121:             * checkStackSanity and ClassCastException
122:             * has occurred OR There is no corrupt 
123:             * object in stack.
124:             */
125:
126:            public Object getCorruptObject() {
127:                if (wrongClassEntryPos != -1) {
128:                    Object corruptObj = this .get(wrongClassEntryPos);
129:                    return corruptObj;
130:                } else {
131:                    return null;
132:                }
133:
134:            }
135:
136:            public Object push(Object value) {
137:
138:                try {
139:                    if (value == null) {
140:                        throw new StackOperationException(
141:                                "Error while Pushing operand into Stack...\nnull Object Passed while trying to push operand to stack");
142:                    } else if (!(value instanceof  Operand)) {
143:                        throw new StackOperationException(
144:                                "Error while Pushing operand into Stack... \nObject Passed is not type of Operand Class....");
145:                    }
146:
147:                    else // OK
148:                    {
149:                        Operand newtopofstack = (Operand) value;
150:                        return super .push(newtopofstack);
151:                    }
152:
153:                } catch (StackOperationException stoe) {
154:                    AllExceptionHandler handler = new AllExceptionHandler(stoe);
155:                    handler.reportException();
156:                    return null;
157:
158:                }
159:
160:            }
161:
162:            /***
163:             * What was i thinking here..? can be removed i guess..
164:             * @return
165:             */
166:            public boolean emptyMe() {
167:                try {
168:                    for (;;) {
169:                        Object temp = this .getTopOfStack();
170:                    }
171:
172:                } catch (EmptyStackException ese) {
173:                    // OK
174:                    return (this .getEntryCount() == 0); // Should Be True 
175:                }
176:
177:            }
178:
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.