Source Code Cross Referenced for NamedIterator.java in  » Code-Analyzer » beautyJ » de » gulden » util » javasource » 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 » Code Analyzer » beautyJ » de.gulden.util.javasource 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Project: BeautyJ - Customizable Java Source Code Transformer
003:         * Class:   de.gulden.util.javasource.NamedIterator
004:         * Version: 1.0
005:         *
006:         * Date:    2002-10-27
007:         *
008:         * Note:    Contains auto-generated Javadoc comments created by BeautyJ.
009:         *  
010:         * This is licensed under the GNU General Public License (GPL)
011:         * and comes with NO WARRANTY. See file license.txt for details.
012:         *
013:         * Author:  Jens Gulden
014:         * Email:   beautyj@jensgulden.de
015:         */
016:
017:        package de.gulden.util.javasource;
018:
019:        import java.lang.Class;
020:        import java.io.*;
021:        import java.util.*;
022:
023:        /**
024:         * Tool class providing a mechanism to access elements from a set of named elements
025:         * either in sequence or by name.
026:         *  
027:         * @author  Jens Gulden
028:         * @version  1.0
029:         */
030:        public class NamedIterator implements  Serializable {
031:
032:            // ------------------------------------------------------------------------
033:            // --- fields                                                           ---
034:            // ------------------------------------------------------------------------
035:            /**
036:             * The data.
037:             */
038:            public Vector data;
039:
040:            /**
041:             * The hash.
042:             */
043:            protected Hashtable hash;
044:
045:            /**
046:             * The pos.
047:             */
048:            protected int pos;
049:
050:            /**
051:             * The readonly.
052:             */
053:            protected boolean readonly = false;
054:
055:            // ------------------------------------------------------------------------
056:            // --- constructors                                                     ---
057:            // ------------------------------------------------------------------------
058:            /**
059:             * Creates a new instance of NamedIterator.
060:             */
061:            public NamedIterator() {
062:                data = new Vector();
063:                hash = new Hashtable();
064:                reset();
065:            }
066:
067:            /**
068:             * Create new NeamedIterator that gets populated with the value of Vector
069:             * <code>v</code>. The reference to <code>v</code> is kept, so changes to
070:             * to the iterator will have effect on the original Vector.
071:             */
072:            public NamedIterator(Vector v) {
073:                data = v; // same _pointer_: changes will have effect in original Vector
074:                hash = new Hashtable();
075:                for (Enumeration e = v.elements(); e.hasMoreElements();) {
076:                    Named n = (Named) e.nextElement();
077:                    hash.put(n.getName(), n);
078:                }
079:                reset();
080:            }
081:
082:            /**
083:             * Special constructor called from Class.
084:             */
085:            NamedIterator(Vector v, Object type, int modifierMask) {
086:                // Using type 'Object' instead of 'java.lang.Class' for parameter type
087:                // is a workaround to avoid having to generate fully qualified class names
088:                // when applying BeatyJ to this code. (Otherwise, would confuse with class
089:                // 'Class' in this package.)
090:                this ();
091:                for (Enumeration e = v.elements(); e.hasMoreElements();) {
092:                    Member m = (Member) e.nextElement();
093:                    int mod = m.getModifier();
094:                    if (((modifierMask & mod) != 0)
095:                            && (m.getClass()
096:                                    .isAssignableFrom((java.lang.Class) type))) {
097:                        data.addElement(m);
098:                    }
099:                }
100:                reset();
101:                lockReadonly(); // read-only in this mode
102:            }
103:
104:            /**
105:             * Creates a new instance of NamedIterator.
106:             */
107:            private NamedIterator(boolean dummy) {
108:                // dummy constructor for cloning
109:            }
110:
111:            // ------------------------------------------------------------------------
112:            // --- methods                                                          ---
113:            // ------------------------------------------------------------------------
114:            public Object clone() {
115:                NamedIterator c = new NamedIterator(true);
116:                synchronized (this ) {
117:                    c.data = (Vector) data.clone();
118:                    c.hash = (Hashtable) hash.clone();
119:                    c.pos = pos;
120:                    c.readonly = readonly;
121:                }
122:                return c;
123:            }
124:
125:            /**
126:             * Get next element.
127:             *  
128:             * @return  The next element, or null if <code>hasMore()==false</code>.
129:             */
130:            public Named next() {
131:                if (hasMore()) {
132:                    return (Named) data.elementAt(pos++);
133:                } else {
134:                    return null;
135:                }
136:            }
137:
138:            /**
139:             * Tests whether there are more elements that can beretrieved using <code>next()</code>.
140:             */
141:            public boolean hasMore() {
142:                return (pos < data.size());
143:            }
144:
145:            /**
146:             * Get an element by name.
147:             */
148:            public Named find(String n) {
149:                return (Named) hash.get(n);
150:            }
151:
152:            /**
153:             * Sets the iterator back to element position 0.
154:             */
155:            public void reset() {
156:                pos = 0;
157:            }
158:
159:            /**
160:             * Tests whether elements can be added to or removed from this iterator.
161:             *  
162:             * @see  #addHere
163:             * @see  #add
164:             * @see  #remove
165:             * @see  #removeAll
166:             */
167:            public boolean isReadOnly() {
168:                return readonly;
169:            }
170:
171:            /**
172:             * Adds an element at the current position.
173:             */
174:            public void addHere(Named n) {
175:                if (!readonly) {
176:                    synchronized (this ) {
177:                        data.insertElementAt(n, pos);
178:                        hash.put(n.getName(), n);
179:                    }
180:                }
181:            }
182:
183:            /**
184:             * Adds an element at the end of the iterator-list.
185:             */
186:            public void add(Named n) {
187:                if (!readonly) {
188:                    synchronized (this ) {
189:                        data.addElement(n);
190:                        hash.put(n.getName(), n);
191:                    }
192:                }
193:            }
194:
195:            /**
196:             * Removes an element from the iterator-list.
197:             */
198:            public void remove(Named n) {
199:                if (!readonly) {
200:                    synchronized (this ) {
201:                        data.addElement(n);
202:                        hash.put(n.getName(), n);
203:                    }
204:                }
205:            }
206:
207:            /**
208:             * Removes all elements from the iterator-list.
209:             */
210:            public void removeAll() {
211:                if (!readonly) {
212:                    synchronized (this ) {
213:                        data.removeAllElements();
214:                        hash.clear();
215:                    }
216:                }
217:            }
218:
219:            /**
220:             * Adds all elements of the NamedIterator to this.
221:             */
222:            public void add(NamedIterator it) {
223:                it.reset();
224:                synchronized (this ) {
225:                    while (it.hasMore()) {
226:                        data.addElement(it.next());
227:                    }
228:                }
229:            }
230:
231:            /**
232:             * Returns the number of elements in the iterator-list.
233:             */
234:            public int size() {
235:                return data.size();
236:            }
237:
238:            /**
239:             * Set this iterator to read-only mode.
240:             */
241:            void lockReadonly() {
242:                readonly = true;
243:            }
244:
245:            /**
246:             * Gets the orignal Vector that stores the iterator-list.
247:             */
248:            Vector getVector() {
249:                return (Vector) data.clone();
250:            }
251:
252:        } // end NamedIterator
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.