Source Code Cross Referenced for ArrayStack.java in  » Library » Apache-commons-beanutils-1.8.0-BETA-src » org » apache » commons » collections » 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 » Library » Apache commons beanutils 1.8.0 BETA src » org.apache.commons.collections 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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