Source Code Cross Referenced for CollectionUtils.java in  » Build » ANT » org » apache » tools » ant » 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 » Build » ANT » org.apache.tools.ant.util 
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.util;
019:
020:        import java.util.Vector;
021:        import java.util.Iterator;
022:        import java.util.Dictionary;
023:        import java.util.Enumeration;
024:        import java.util.NoSuchElementException;
025:
026:        // CheckStyle:HideUtilityClassConstructorCheck OFF - bc
027:
028:        /**
029:         * A set of helper methods related to collection manipulation.
030:         *
031:         * @since Ant 1.5
032:         */
033:        public class CollectionUtils {
034:
035:            /**
036:             * Please use Vector.equals() or List.equals().
037:             * @param v1 the first vector.
038:             * @param v2 the second vector.
039:             * @return true if the vectors are equal.
040:             * @since Ant 1.5
041:             * @deprecated since 1.6.x.
042:             */
043:            public static boolean equals(Vector v1, Vector v2) {
044:                if (v1 == v2) {
045:                    return true;
046:                }
047:
048:                if (v1 == null || v2 == null) {
049:                    return false;
050:                }
051:
052:                return v1.equals(v2);
053:            }
054:
055:            /**
056:             * Dictionary does not have an equals.
057:             * Please use  Map.equals().
058:             *
059:             * <p>Follows the equals contract of Java 2's Map.</p>
060:             * @param d1 the first directory.
061:             * @param d2 the second directory.
062:             * @return true if the directories are equal.
063:             * @since Ant 1.5
064:             * @deprecated since 1.6.x.
065:             */
066:            public static boolean equals(Dictionary d1, Dictionary d2) {
067:                if (d1 == d2) {
068:                    return true;
069:                }
070:
071:                if (d1 == null || d2 == null) {
072:                    return false;
073:                }
074:
075:                if (d1.size() != d2.size()) {
076:                    return false;
077:                }
078:
079:                Enumeration e1 = d1.keys();
080:                while (e1.hasMoreElements()) {
081:                    Object key = e1.nextElement();
082:                    Object value1 = d1.get(key);
083:                    Object value2 = d2.get(key);
084:                    if (value2 == null || !value1.equals(value2)) {
085:                        return false;
086:                    }
087:                }
088:
089:                // don't need the opposite check as the Dictionaries have the
090:                // same size, so we've also covered all keys of d2 already.
091:
092:                return true;
093:            }
094:
095:            /**
096:             * Dictionary does not know the putAll method. Please use Map.putAll().
097:             * @param m1 the to directory.
098:             * @param m2 the from directory.
099:             * @since Ant 1.6
100:             * @deprecated since 1.6.x.
101:             */
102:            public static void putAll(Dictionary m1, Dictionary m2) {
103:                for (Enumeration it = m2.keys(); it.hasMoreElements();) {
104:                    Object key = it.nextElement();
105:                    m1.put(key, m2.get(key));
106:                }
107:            }
108:
109:            /**
110:             * An empty enumeration.
111:             * @since Ant 1.6
112:             */
113:            public static final class EmptyEnumeration implements  Enumeration {
114:                /** Constructor for the EmptyEnumeration */
115:                public EmptyEnumeration() {
116:                }
117:
118:                /**
119:                 * @return false always.
120:                 */
121:                public boolean hasMoreElements() {
122:                    return false;
123:                }
124:
125:                /**
126:                 * @return nothing.
127:                 * @throws NoSuchElementException always.
128:                 */
129:                public Object nextElement() throws NoSuchElementException {
130:                    throw new NoSuchElementException();
131:                }
132:            }
133:
134:            /**
135:             * Append one enumeration to another.
136:             * Elements are evaluated lazily.
137:             * @param e1 the first enumeration.
138:             * @param e2 the subsequent enumeration.
139:             * @return an enumeration representing e1 followed by e2.
140:             * @since Ant 1.6.3
141:             */
142:            public static Enumeration append(Enumeration e1, Enumeration e2) {
143:                return new CompoundEnumeration(e1, e2);
144:            }
145:
146:            /**
147:             * Adapt the specified Iterator to the Enumeration interface.
148:             * @param iter the Iterator to adapt.
149:             * @return an Enumeration.
150:             */
151:            public static Enumeration asEnumeration(final Iterator iter) {
152:                return new Enumeration() {
153:                    public boolean hasMoreElements() {
154:                        return iter.hasNext();
155:                    }
156:
157:                    public Object nextElement() {
158:                        return iter.next();
159:                    }
160:                };
161:            }
162:
163:            /**
164:             * Adapt the specified Enumeration to the Iterator interface.
165:             * @param e the Enumeration to adapt.
166:             * @return an Iterator.
167:             */
168:            public static Iterator asIterator(final Enumeration e) {
169:                return new Iterator() {
170:                    public boolean hasNext() {
171:                        return e.hasMoreElements();
172:                    }
173:
174:                    public Object next() {
175:                        return e.nextElement();
176:                    }
177:
178:                    public void remove() {
179:                        throw new UnsupportedOperationException();
180:                    }
181:                };
182:            }
183:
184:            private static final class CompoundEnumeration implements 
185:                    Enumeration {
186:
187:                private final Enumeration e1, e2;
188:
189:                public CompoundEnumeration(Enumeration e1, Enumeration e2) {
190:                    this .e1 = e1;
191:                    this .e2 = e2;
192:                }
193:
194:                public boolean hasMoreElements() {
195:                    return e1.hasMoreElements() || e2.hasMoreElements();
196:                }
197:
198:                public Object nextElement() throws NoSuchElementException {
199:                    if (e1.hasMoreElements()) {
200:                        return e1.nextElement();
201:                    } else {
202:                        return e2.nextElement();
203:                    }
204:                }
205:
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.