Source Code Cross Referenced for ListBuffer.java in  » 6.0-JDK-Modules-sun » javac-compiler » com » sun » tools » javac » 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 » 6.0 JDK Modules sun » javac compiler » com.sun.tools.javac.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2006 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 com.sun.tools.javac.util;
027:
028:        import java.util.Collection;
029:        import java.util.Iterator;
030:        import java.util.NoSuchElementException;
031:
032:        /** A class for constructing lists by appending elements. Modelled after
033:         *  java.lang.StringBuffer.
034:         *
035:         *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
036:         *  you write code that depends on this, you do so at your own risk.
037:         *  This code and its internal interfaces are subject to change or
038:         *  deletion without notice.</b>
039:         */
040:        @Version("@(#)ListBuffer.java	1.34 07/05/05")
041:        public class ListBuffer<A> implements  Collection<A> {
042:
043:            public static <T> ListBuffer<T> lb() {
044:                return new ListBuffer<T>();
045:            }
046:
047:            /** The list of elements of this buffer.
048:             */
049:            public List<A> elems;
050:
051:            /** A pointer pointing to the last, sentinel element of `elems'.
052:             */
053:            public List<A> last;
054:
055:            /** The number of element in this buffer.
056:             */
057:            public int count;
058:
059:            /** Has a list been created from this buffer yet?
060:             */
061:            public boolean shared;
062:
063:            /** Create a new initially empty list buffer.
064:             */
065:            public ListBuffer() {
066:                clear();
067:            }
068:
069:            public final void clear() {
070:                this .elems = new List<A>(null, null);
071:                this .last = this .elems;
072:                count = 0;
073:                shared = false;
074:            }
075:
076:            /** Return the number of elements in this buffer.
077:             */
078:            public int length() {
079:                return count;
080:            }
081:
082:            public int size() {
083:                return count;
084:            }
085:
086:            /** Is buffer empty?
087:             */
088:            public boolean isEmpty() {
089:                return count == 0;
090:            }
091:
092:            /** Is buffer not empty?
093:             */
094:            public boolean nonEmpty() {
095:                return count != 0;
096:            }
097:
098:            /** Copy list and sets last.
099:             */
100:            private void copy() {
101:                List<A> p = elems = new List<A>(elems.head, elems.tail);
102:                while (true) {
103:                    List<A> tail = p.tail;
104:                    if (tail == null)
105:                        break;
106:                    tail = new List<A>(tail.head, tail.tail);
107:                    p.setTail(tail);
108:                    p = tail;
109:                }
110:                last = p;
111:                shared = false;
112:            }
113:
114:            /** Prepend an element to buffer.
115:             */
116:            public ListBuffer<A> prepend(A x) {
117:                elems = elems.prepend(x);
118:                count++;
119:                return this ;
120:            }
121:
122:            /** Append an element to buffer.
123:             */
124:            public ListBuffer<A> append(A x) {
125:                if (shared)
126:                    copy();
127:                last.head = x;
128:                last.setTail(new List<A>(null, null));
129:                last = last.tail;
130:                count++;
131:                return this ;
132:            }
133:
134:            /** Append all elements in a list to buffer.
135:             */
136:            public ListBuffer<A> appendList(List<A> xs) {
137:                while (xs.nonEmpty()) {
138:                    append(xs.head);
139:                    xs = xs.tail;
140:                }
141:                return this ;
142:            }
143:
144:            /** Append all elements in a list to buffer.
145:             */
146:            public ListBuffer<A> appendList(ListBuffer<A> xs) {
147:                return appendList(xs.toList());
148:            }
149:
150:            /** Append all elements in an array to buffer.
151:             */
152:            public ListBuffer<A> appendArray(A[] xs) {
153:                for (int i = 0; i < xs.length; i++) {
154:                    append(xs[i]);
155:                }
156:                return this ;
157:            }
158:
159:            /** Convert buffer to a list of all its elements.
160:             */
161:            public List<A> toList() {
162:                shared = true;
163:                return elems;
164:            }
165:
166:            /** Does the list contain the specified element?
167:             */
168:            public boolean contains(Object x) {
169:                return elems.contains(x);
170:            }
171:
172:            /** Convert buffer to an array
173:             */
174:            public <T> T[] toArray(T[] vec) {
175:                return elems.toArray(vec);
176:            }
177:
178:            public Object[] toArray() {
179:                return toArray(new Object[size()]);
180:            }
181:
182:            /** The first element in this buffer.
183:             */
184:            public A first() {
185:                return elems.head;
186:            }
187:
188:            /** Remove the first element in this buffer.
189:             */
190:            public void remove() {
191:                if (elems != last) {
192:                    elems = elems.tail;
193:                    count--;
194:                }
195:            }
196:
197:            /** Return first element in this buffer and remove
198:             */
199:            public A next() {
200:                A x = elems.head;
201:                remove();
202:                return x;
203:            }
204:
205:            /** An enumeration of all elements in this buffer.
206:             */
207:            public Iterator<A> iterator() {
208:                return new Iterator<A>() {
209:                    List<A> elems = ListBuffer.this .elems;
210:
211:                    public boolean hasNext() {
212:                        return elems != last;
213:                    }
214:
215:                    public A next() {
216:                        if (elems == last)
217:                            throw new NoSuchElementException();
218:                        A elem = elems.head;
219:                        elems = elems.tail;
220:                        return elem;
221:                    }
222:
223:                    public void remove() {
224:                        throw new UnsupportedOperationException();
225:                    }
226:                };
227:            }
228:
229:            public boolean add(A a) {
230:                throw new UnsupportedOperationException();
231:            }
232:
233:            public boolean remove(Object o) {
234:                throw new UnsupportedOperationException();
235:            }
236:
237:            public boolean containsAll(Collection<?> c) {
238:                throw new UnsupportedOperationException();
239:            }
240:
241:            public boolean addAll(Collection<? extends A> c) {
242:                throw new UnsupportedOperationException();
243:            }
244:
245:            public boolean removeAll(Collection<?> c) {
246:                throw new UnsupportedOperationException();
247:            }
248:
249:            public boolean retainAll(Collection<?> c) {
250:                throw new UnsupportedOperationException();
251:            }
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.