Source Code Cross Referenced for CommaListIterator.java in  » Database-ORM » db-ojb » xdoclet » modules » ojb » 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 » Database ORM » db ojb » xdoclet.modules.ojb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package xdoclet.modules.ojb;
002:
003:        /* Copyright 2004-2005 The Apache Software Foundation
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * 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:
018:        import java.util.Iterator;
019:        import java.util.StringTokenizer;
020:
021:        /**
022:         * Small helper class for dealing with comma-separated string lists.
023:         * 
024:         * @author <a href="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
025:         */
026:        public class CommaListIterator implements  Iterator {
027:            /** The tokenizer for the comma-separated list */
028:            private StringTokenizer _list;
029:            /** The current token */
030:            private String _current = "";
031:
032:            /**
033:             * Creates a new string iterator for the given comma-separated list.
034:             *  
035:             * @param list The list
036:             */
037:            public CommaListIterator(String list) {
038:                _list = new StringTokenizer(list == null ? "" : list, ",");
039:            }
040:
041:            /* (non-Javadoc)
042:             * @see java.util.Iterator#remove()
043:             */
044:            public void remove() {
045:                throw new UnsupportedOperationException();
046:            }
047:
048:            /* (non-Javadoc)
049:             * @see java.util.Iterator#hasNext()
050:             */
051:            public boolean hasNext() {
052:                while (_list.hasMoreTokens() && (_current.length() == 0)) {
053:                    _current = _list.nextToken();
054:                }
055:                return (_current.length() > 0);
056:            }
057:
058:            /* (non-Javadoc)
059:             * @see java.util.Iterator#next()
060:             */
061:            public Object next() {
062:                return getNext();
063:            }
064:
065:            /**
066:             * Returns the next string from the list.
067:             * 
068:             * @return The next string
069:             */
070:            public String getNext() {
071:                String result = _current;
072:
073:                _current = "";
074:                return result.trim();
075:            }
076:
077:            /**
078:             * Determines whether one of the remaining elements is the given element. If it is found
079:             * then the iterator is moved after the element, otherwise the iterator is after the end
080:             * of the list.
081:             *  
082:             * @param element The element to search for
083:             * @return <code>true</code> if the element has been found
084:             */
085:            public boolean contains(String element) {
086:                while (hasNext()) {
087:                    if (element.equals(getNext())) {
088:                        return true;
089:                    }
090:                }
091:                return false;
092:            }
093:
094:            /**
095:             * Compares this iterator with the other given one. Note that this consumes
096:             * the iterators, so you should not use them afterwards.
097:             * 
098:             * @param obj The other object
099:             * @return If the other object is a comma list iterator and it delivers the same values
100:             *         as this iterator 
101:             * @see java.lang.Object#equals(java.lang.Object)
102:             */
103:            public boolean equals(Object obj) {
104:                if (!(obj instanceof  CommaListIterator)) {
105:                    return false;
106:                }
107:
108:                CommaListIterator otherIt = (CommaListIterator) obj;
109:
110:                while (hasNext() || otherIt.hasNext()) {
111:                    if (!hasNext() || !otherIt.hasNext()) {
112:                        return false;
113:                    }
114:                    if (!getNext().equals(otherIt.getNext())) {
115:                        return false;
116:                    }
117:                }
118:                return true;
119:            }
120:
121:            /**
122:             * Compares the two comma-separated lists.
123:             * 
124:             * @param list1 The first list
125:             * @param list2 The second list
126:             * @return <code>true</code> if the lists are equal
127:             */
128:            public static boolean sameLists(String list1, String list2) {
129:                return new CommaListIterator(list1)
130:                        .equals(new CommaListIterator(list2));
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.