Source Code Cross Referenced for Stack.java in  » Net » Terracotta » com » tc » util » 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 » Net » Terracotta » com.tc.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */package com.tc.util;
004:
005:        import java.util.ArrayList;
006:        import java.util.EmptyStackException;
007:        import java.util.Iterator;
008:        import java.util.List;
009:
010:        /*
011:         * This stack implementation uses ArrayList internally. This is mainly created so that we dont have synchronization
012:         * overheads that java.util.Stack imposses since it is based on Vector. This class maintains an interface level compatibility
013:         * with java.util.Stack but doesnot implement all of Vector interfaces.
014:         */
015:        public class Stack {
016:
017:            private final List list = new ArrayList();
018:
019:            /**
020:             * Creates an empty Stack.
021:             */
022:            public Stack() {
023:            }
024:
025:            /**
026:             * Pushes an item onto the top of this stack. This has exactly the same effect as: <blockquote>
027:             * 
028:             * @param item the item to be pushed onto this stack.
029:             * @return the <code>item</code> argument.
030:             * @see java.util.Vector#addElement
031:             */
032:            public Object push(Object item) {
033:                list.add(item);
034:                return item;
035:            }
036:
037:            /**
038:             * Removes the object at the top of this stack and returns that object as the value of this function.
039:             * 
040:             * @return The object at the top of this stack (the last item of the <tt>Vector</tt> object).
041:             * @exception EmptyStackException if this stack is empty.
042:             */
043:            public Object pop() {
044:                int len = size();
045:
046:                if (len == 0)
047:                    throw new EmptyStackException();
048:                return list.remove(len - 1);
049:            }
050:
051:            /**
052:             * Looks at the object at the top of this stack without removing it from the stack.
053:             * 
054:             * @return the object at the top of this stack (the last item of the <tt>Vector</tt> object).
055:             * @exception EmptyStackException if this stack is empty.
056:             */
057:            public Object peek() {
058:                int len = size();
059:
060:                if (len == 0)
061:                    throw new EmptyStackException();
062:                return list.get(len - 1);
063:            }
064:
065:            /**
066:             * Tests if this stack is empty.
067:             * 
068:             * @return <code>true</code> if and only if this stack contains no items; <code>false</code> otherwise.
069:             */
070:            public boolean empty() {
071:                return size() == 0;
072:            }
073:
074:            /**
075:             * Size of this Stack
076:             * 
077:             * @return the size of the stack
078:             */
079:            public int size() {
080:                return list.size();
081:            }
082:
083:            /**
084:             * Returns the 1-based position where an object is on this stack. If the object <tt>o</tt> occurs as an item in this
085:             * stack, this method returns the distance from the top of the stack of the occurrence nearest the top of the stack;
086:             * the topmost item on the stack is considered to be at distance <tt>1</tt>. The <tt>equals</tt> method is used
087:             * to compare <tt>o</tt> to the items in this stack.
088:             * 
089:             * @param o the desired object.
090:             * @return the 1-based position from the top of the stack where the object is located; the return value
091:             *         <code>-1</code> indicates that the object is not on the stack.
092:             */
093:            public int search(Object o) {
094:                int i = list.lastIndexOf(o);
095:
096:                if (i >= 0) {
097:                    return size() - i;
098:                }
099:                return -1;
100:            }
101:
102:            private static final long serialVersionUID = 343422342343423234L;
103:
104:            /* I am not in big favor of having these interfaces */
105:
106:            public Object get(int index) {
107:                return list.get(index);
108:            }
109:
110:            public Object remove(int index) {
111:                return list.remove(index);
112:            }
113:
114:            public Iterator iterator() {
115:                return list.iterator();
116:            }
117:
118:            public boolean isEmpty() {
119:                return empty();
120:            }
121:
122:            public boolean contains(Object o) {
123:                return list.contains(o);
124:            }
125:
126:            public boolean remove(Object o) {
127:                return list.remove(o);
128:            }
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.