FileDocCategorySizeDatePackage
CollectionUtils.javaAPI DocApache Ant 1.705842Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.util

CollectionUtils

public class CollectionUtils extends Object
A set of helper methods related to collection manipulation.
since
Ant 1.5

Fields Summary
Constructors Summary
Methods Summary
public static java.util.Enumerationappend(java.util.Enumeration e1, java.util.Enumeration e2)
Append one enumeration to another. Elements are evaluated lazily.

param
e1 the first enumeration.
param
e2 the subsequent enumeration.
return
an enumeration representing e1 followed by e2.
since
Ant 1.6.3

        return new CompoundEnumeration(e1, e2);
    
public static java.util.EnumerationasEnumeration(java.util.Iterator iter)
Adapt the specified Iterator to the Enumeration interface.

param
iter the Iterator to adapt.
return
an Enumeration.

        return new Enumeration() {
            public boolean hasMoreElements() {
                return iter.hasNext();
            }
            public Object nextElement() {
                return iter.next();
            }
        };
    
public static java.util.IteratorasIterator(java.util.Enumeration e)
Adapt the specified Enumeration to the Iterator interface.

param
e the Enumeration to adapt.
return
an Iterator.

        return new Iterator() {
            public boolean hasNext() {
                return e.hasMoreElements();
            }
            public Object next() {
                return e.nextElement();
            }
            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    
public static booleanequals(java.util.Vector v1, java.util.Vector v2)
Please use Vector.equals() or List.equals().

param
v1 the first vector.
param
v2 the second vector.
return
true if the vectors are equal.
since
Ant 1.5
deprecated
since 1.6.x.

        if (v1 == v2) {
            return true;
        }

        if (v1 == null || v2 == null) {
            return false;
        }

        return v1.equals(v2);
    
public static booleanequals(java.util.Dictionary d1, java.util.Dictionary d2)
Dictionary does not have an equals. Please use Map.equals().

Follows the equals contract of Java 2's Map.

param
d1 the first directory.
param
d2 the second directory.
return
true if the directories are equal.
since
Ant 1.5
deprecated
since 1.6.x.

        if (d1 == d2) {
            return true;
        }

        if (d1 == null || d2 == null) {
            return false;
        }

        if (d1.size() != d2.size()) {
            return false;
        }

        Enumeration e1 = d1.keys();
        while (e1.hasMoreElements()) {
            Object key = e1.nextElement();
            Object value1 = d1.get(key);
            Object value2 = d2.get(key);
            if (value2 == null || !value1.equals(value2)) {
                return false;
            }
        }

        // don't need the opposite check as the Dictionaries have the
        // same size, so we've also covered all keys of d2 already.

        return true;
    
public static voidputAll(java.util.Dictionary m1, java.util.Dictionary m2)
Dictionary does not know the putAll method. Please use Map.putAll().

param
m1 the to directory.
param
m2 the from directory.
since
Ant 1.6
deprecated
since 1.6.x.

        for (Enumeration it = m2.keys(); it.hasMoreElements();) {
            Object key = it.nextElement();
            m1.put(key, m2.get(key));
        }