Source Code Cross Referenced for ArrayStack.java in  » Web-Services-AXIS2 » adb » org » apache » axis2 » 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 » Web Services AXIS2 » adb » org.apache.axis2.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.util;
020:
021:        import java.util.ArrayList;
022:        import java.util.EmptyStackException;
023:
024:        /**
025:         * An implementation of the {@link java.util.Stack} API that is based on an <code>ArrayList</code>
026:         * instead of a <code>Vector</code>, so it is not synchronized to protect against multi-threaded
027:         * access.  The implementation is therefore operates faster in environments where you do not need to
028:         * worry about multiple thread contention.
029:         * <p/>
030:         * The removal order of an <code>ArrayStack</code> is based on insertion order: The most recently
031:         * added element is removed first.  The iteration order is <i>not</i> the same as the removal order.
032:         *  The iterator returns elements from the bottom up, whereas the {@link #remove()} method removes
033:         * them from the top down.
034:         * <p/>
035:         * Unlike <code>Stack</code>, <code>ArrayStack</code> accepts null entries.
036:         */
037:        public class ArrayStack extends ArrayList {
038:
039:            /** Ensure serialization compatibility */
040:            private static final long serialVersionUID = 2130079159931574599L;
041:
042:            /**
043:             * Constructs a new empty <code>ArrayStack</code>. The initial size is controlled by
044:             * <code>ArrayList</code> and is currently 10.
045:             */
046:            public ArrayStack() {
047:                super ();
048:            }
049:
050:            /**
051:             * Constructs a new empty <code>ArrayStack</code> with an initial size.
052:             *
053:             * @param initialSize the initial size to use
054:             * @throws IllegalArgumentException if the specified initial size is negative
055:             */
056:            public ArrayStack(int initialSize) {
057:                super (initialSize);
058:            }
059:
060:            /**
061:             * Return <code>true</code> if this stack is currently empty.
062:             * <p/>
063:             * This method exists for compatibility with <code>java.util.Stack</code>. New users of this
064:             * class should use <code>isEmpty</code> instead.
065:             *
066:             * @return true if the stack is currently empty
067:             */
068:            public boolean empty() {
069:                return isEmpty();
070:            }
071:
072:            /**
073:             * Returns the top item off of this stack without removing it.
074:             *
075:             * @return the top item on the stack
076:             * @throws EmptyStackException if the stack is empty
077:             */
078:            public Object peek() throws EmptyStackException {
079:                int n = size();
080:                if (n <= 0) {
081:                    throw new EmptyStackException();
082:                } else {
083:                    return get(n - 1);
084:                }
085:            }
086:
087:            /**
088:             * Returns the n'th item down (zero-relative) from the top of this stack without removing it.
089:             *
090:             * @param n the number of items down to go
091:             * @return the n'th item on the stack, zero relative
092:             * @throws EmptyStackException if there are not enough items on the stack to satisfy this
093:             *                             request
094:             */
095:            public Object peek(int n) throws EmptyStackException {
096:                int m = (size() - n) - 1;
097:                if (m < 0) {
098:                    throw new EmptyStackException();
099:                } else {
100:                    return get(m);
101:                }
102:            }
103:
104:            /**
105:             * Pops the top item off of this stack and return it.
106:             *
107:             * @return the top item on the stack
108:             * @throws EmptyStackException if the stack is empty
109:             */
110:            public Object pop() throws EmptyStackException {
111:                int n = size();
112:                if (n <= 0) {
113:                    throw new EmptyStackException();
114:                } else {
115:                    return remove(n - 1);
116:                }
117:            }
118:
119:            /**
120:             * Pushes a new item onto the top of this stack. The pushed item is also returned. This is
121:             * equivalent to calling <code>add</code>.
122:             *
123:             * @param item the item to be added
124:             * @return the item just pushed
125:             */
126:            public Object push(Object item) {
127:                add(item);
128:                return item;
129:            }
130:
131:            /**
132:             * Returns the one-based position of the distance from the top that the specified object exists
133:             * on this stack, where the top-most element is considered to be at distance <code>1</code>.  If
134:             * the object is not present on the stack, return <code>-1</code> instead.  The
135:             * <code>equals()</code> method is used to compare to the items in this stack.
136:             *
137:             * @param object the object to be searched for
138:             * @return the 1-based depth into the stack of the object, or -1 if not found
139:             */
140:            public int search(Object object) {
141:                int i = size() - 1; // Current index
142:                int n = 1; // Current distance
143:                while (i >= 0) {
144:                    Object current = get(i);
145:                    if ((object == null && current == null)
146:                            || (object != null && object.equals(current))) {
147:                        return n;
148:                    }
149:                    i--;
150:                    n++;
151:                }
152:                return -1;
153:            }
154:
155:            /**
156:             * Returns the element on the top of the stack.
157:             *
158:             * @return the element on the top of the stack
159:             * @throws EmptyStackException if the stack is empty
160:             */
161:            public Object get() {
162:                int size = size();
163:                if (size == 0) {
164:                    throw new EmptyStackException();
165:                }
166:                return get(size - 1);
167:            }
168:
169:            /**
170:             * Removes the element on the top of the stack.
171:             *
172:             * @return the removed element
173:             * @throws EmptyStackException if the stack is empty
174:             */
175:            public Object remove() {
176:                int size = size();
177:                if (size == 0) {
178:                    throw new EmptyStackException();
179:                }
180:                return remove(size - 1);
181:            }
182:
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.