Source Code Cross Referenced for Enumerations.java in  » Build » ANT » org » apache » tools » ant » taskdefs » optional » junit » 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 » Build » ANT » org.apache.tools.ant.taskdefs.optional.junit 
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:         */
018:        package org.apache.tools.ant.taskdefs.optional.junit;
019:
020:        import java.util.Enumeration;
021:        import java.util.NoSuchElementException;
022:
023:        /**
024:         * A couple of methods related to enumerations that might be useful.
025:         * This class should probably disappear once the required JDK is set to 1.2
026:         * instead of 1.1.
027:         *
028:         */
029:        public final class Enumerations {
030:
031:            private Enumerations() {
032:            }
033:
034:            /**
035:             * creates an enumeration from an array of objects.
036:             * @param       array   the array of object to enumerate.
037:             * @return the enumeration over the array of objects.
038:             */
039:            public static Enumeration fromArray(Object[] array) {
040:                return new ArrayEnumeration(array);
041:            }
042:
043:            /**
044:             * creates an enumeration from an array of enumeration. The created enumeration
045:             * will sequentially enumerate over all elements of each enumeration and skip
046:             * <tt>null</tt> enumeration elements in the array.
047:             * @param        enums   the array of enumerations.
048:             * @return the enumeration over the array of enumerations.
049:             */
050:            public static Enumeration fromCompound(Enumeration[] enums) {
051:                return new CompoundEnumeration(enums);
052:            }
053:
054:        }
055:
056:        /**
057:         * Convenient enumeration over an array of objects.
058:         */
059:        class ArrayEnumeration implements  Enumeration {
060:
061:            /** object array */
062:            private Object[] array;
063:
064:            /** current index */
065:            private int pos;
066:
067:            /**
068:             * Initialize a new enumeration that wraps an array.
069:             * @param       array   the array of object to enumerate.
070:             */
071:            public ArrayEnumeration(Object[] array) {
072:                this .array = array;
073:                this .pos = 0;
074:            }
075:
076:            /**
077:             * Tests if this enumeration contains more elements.
078:             *
079:             * @return  <code>true</code> if and only if this enumeration object
080:             *           contains at least one more element to provide;
081:             *          <code>false</code> otherwise.
082:             */
083:            public boolean hasMoreElements() {
084:                return (pos < array.length);
085:            }
086:
087:            /**
088:             * Returns the next element of this enumeration if this enumeration
089:             * object has at least one more element to provide.
090:             *
091:             * @return     the next element of this enumeration.
092:             * @throws  NoSuchElementException  if no more elements exist.
093:             */
094:            public Object nextElement() throws NoSuchElementException {
095:                if (hasMoreElements()) {
096:                    Object o = array[pos];
097:                    pos++;
098:                    return o;
099:                }
100:                throw new NoSuchElementException();
101:            }
102:        }
103:
104:        /**
105:         * Convenient enumeration over an array of enumeration. For example:
106:         * <pre>
107:         * Enumeration e1 = v1.elements();
108:         * while (e1.hasMoreElements()) {
109:         *    // do something
110:         * }
111:         * Enumeration e2 = v2.elements();
112:         * while (e2.hasMoreElements()) {
113:         *    // do the same thing
114:         * }
115:         * </pre>
116:         * can be written as:
117:         * <pre>
118:         * Enumeration[] enums = { v1.elements(), v2.elements() };
119:         * Enumeration e = Enumerations.fromCompound(enums);
120:         * while (e.hasMoreElements()) {
121:         *    // do something
122:         * }
123:         * </pre>
124:         * Note that the enumeration will skip null elements in the array. The following is
125:         * thus possible:
126:         * <pre>
127:         * Enumeration[] enums = { v1.elements(), null, v2.elements() }; // a null enumeration in the array
128:         * Enumeration e = Enumerations.fromCompound(enums);
129:         * while (e.hasMoreElements()) {
130:         *    // do something
131:         * }
132:         * </pre>
133:         */
134:        class CompoundEnumeration implements  Enumeration {
135:
136:            /** enumeration array */
137:            private Enumeration[] enumArray;
138:
139:            /** index in the enums array */
140:            private int index = 0;
141:
142:            public CompoundEnumeration(Enumeration[] enumarray) {
143:                this .enumArray = enumarray;
144:            }
145:
146:            /**
147:             * Tests if this enumeration contains more elements.
148:             *
149:             * @return  <code>true</code> if and only if this enumeration object
150:             *           contains at least one more element to provide;
151:             *          <code>false</code> otherwise.
152:             */
153:            public boolean hasMoreElements() {
154:                while (index < enumArray.length) {
155:                    if (enumArray[index] != null
156:                            && enumArray[index].hasMoreElements()) {
157:                        return true;
158:                    }
159:                    index++;
160:                }
161:                return false;
162:            }
163:
164:            /**
165:             * Returns the next element of this enumeration if this enumeration
166:             * object has at least one more element to provide.
167:             *
168:             * @return     the next element of this enumeration.
169:             * @throws  NoSuchElementException  if no more elements exist.
170:             */
171:            public Object nextElement() throws NoSuchElementException {
172:                if (hasMoreElements()) {
173:                    return enumArray[index].nextElement();
174:                }
175:                throw new NoSuchElementException();
176:            }
177:        }
www.___j___a__v__a2___s__.c_o__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.