Source Code Cross Referenced for Stack.java in  » 6.0-JDK-Core » Collections-Jar-Zip-Logging-regex » java » 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
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Core » Collections Jar Zip Logging regex » java.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1994-2005 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package java.util;
027:
028:        /**
029:         * The <code>Stack</code> class represents a last-in-first-out
030:         * (LIFO) stack of objects. It extends class <tt>Vector</tt> with five
031:         * operations that allow a vector to be treated as a stack. The usual
032:         * <tt>push</tt> and <tt>pop</tt> operations are provided, as well as a
033:         * method to <tt>peek</tt> at the top item on the stack, a method to test
034:         * for whether the stack is <tt>empty</tt>, and a method to <tt>search</tt>
035:         * the stack for an item and discover how far it is from the top.
036:         * <p>
037:         * When a stack is first created, it contains no items.
038:         *
039:         * <p>A more complete and consistent set of LIFO stack operations is
040:         * provided by the {@link Deque} interface and its implementations, which
041:         * should be used in preference to this class.  For example:
042:         * <pre>   {@code
043:         *   Deque<Integer> stack = new ArrayDeque<Integer>();}</pre>
044:         *
045:         * @author  Jonathan Payne
046:         * @version 1.36, 05/05/07
047:         * @since   JDK1.0
048:         */
049:        public class Stack<E> extends Vector<E> {
050:            /**
051:             * Creates an empty Stack.
052:             */
053:            public Stack() {
054:            }
055:
056:            /**
057:             * Pushes an item onto the top of this stack. This has exactly
058:             * the same effect as:
059:             * <blockquote><pre>
060:             * addElement(item)</pre></blockquote>
061:             *
062:             * @param   item   the item to be pushed onto this stack.
063:             * @return  the <code>item</code> argument.
064:             * @see     java.util.Vector#addElement
065:             */
066:            public E push(E item) {
067:                addElement(item);
068:
069:                return item;
070:            }
071:
072:            /**
073:             * Removes the object at the top of this stack and returns that
074:             * object as the value of this function.
075:             *
076:             * @return     The object at the top of this stack (the last item
077:             *             of the <tt>Vector</tt> object).
078:             * @exception  EmptyStackException  if this stack is empty.
079:             */
080:            public synchronized E pop() {
081:                E obj;
082:                int len = size();
083:
084:                obj = peek();
085:                removeElementAt(len - 1);
086:
087:                return obj;
088:            }
089:
090:            /**
091:             * Looks at the object at the top of this stack without removing it
092:             * from the stack.
093:             *
094:             * @return     the object at the top of this stack (the last item
095:             *             of the <tt>Vector</tt> object).
096:             * @exception  EmptyStackException  if this stack is empty.
097:             */
098:            public synchronized E peek() {
099:                int len = size();
100:
101:                if (len == 0)
102:                    throw new EmptyStackException();
103:                return elementAt(len - 1);
104:            }
105:
106:            /**
107:             * Tests if this stack is empty.
108:             *
109:             * @return  <code>true</code> if and only if this stack contains
110:             *          no items; <code>false</code> otherwise.
111:             */
112:            public boolean empty() {
113:                return size() == 0;
114:            }
115:
116:            /**
117:             * Returns the 1-based position where an object is on this stack.
118:             * If the object <tt>o</tt> occurs as an item in this stack, this
119:             * method returns the distance from the top of the stack of the
120:             * occurrence nearest the top of the stack; the topmost item on the
121:             * stack is considered to be at distance <tt>1</tt>. The <tt>equals</tt>
122:             * method is used to compare <tt>o</tt> to the
123:             * items in this stack.
124:             *
125:             * @param   o   the desired object.
126:             * @return  the 1-based position from the top of the stack where
127:             *          the object is located; the return value <code>-1</code>
128:             *          indicates that the object is not on the stack.
129:             */
130:            public synchronized int search(Object o) {
131:                int i = lastIndexOf(o);
132:
133:                if (i >= 0) {
134:                    return size() - i;
135:                }
136:                return -1;
137:            }
138:
139:            /** use serialVersionUID from JDK 1.0.2 for interoperability */
140:            private static final long serialVersionUID = 1224463164541339165L;
141:        }
w__w_w_.j___av_a_2_s___.___c___o___m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.