Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 150   Methods: 3
NCLOC: 52   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CollectionUtils.java 90.9% 93.1% 100% 92.6%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.util;
 55   
 
 56   
 import java.util.Dictionary;
 57   
 import java.util.Enumeration;
 58   
 import java.util.Vector;
 59   
 
 60   
 /**
 61   
  * A set of helper methods related to collection manipulation.
 62   
  *
 63   
  * @author Stefan Bodewig
 64   
  * @author <a href="mailto:stein@xtramind.com">Ingmar Stein</a>
 65   
  *
 66   
  * @since Ant 1.5
 67   
  */
 68   
 public class CollectionUtils {
 69   
 
 70   
     /**
 71   
      * Vector.equals() doesn't do any good in 1.1
 72   
      *
 73   
      * @since Ant 1.5
 74   
      */
 75  37
     public static boolean equals(Vector v1, Vector v2) {
 76  37
         if (v1 == v2) {
 77  0
             return true;
 78   
         }
 79   
         
 80  37
         if (v1 == null || v2 == null) {
 81  2
             return false;
 82   
         }
 83   
 
 84  35
         if (v1.size() != v2.size()) {
 85  4
             return false;
 86   
         }
 87   
 
 88  31
         Enumeration e1 = v1.elements();
 89  31
         Enumeration e2 = v2.elements();
 90  31
         while (e1.hasMoreElements()) {
 91  42
             if (!e1.nextElement().equals(e2.nextElement())) {
 92  3
                 return false;
 93   
             }
 94   
         }
 95   
         
 96   
         // don't need to check e2.hasMoreElements as the Vectors have
 97   
         // same size.
 98   
 
 99  28
         return true;
 100   
     }
 101   
 
 102   
     /**
 103   
      * Hashtable.equals() doesn't do any good in 1.1.
 104   
      *
 105   
      * <p>Follows the equals contract of Java 2's Map.</p>
 106   
      *
 107   
      * @since Ant 1.5
 108   
      */
 109  61
     public static boolean equals(Dictionary d1, Dictionary d2) {
 110  61
         if (d1 == d2) {
 111  0
             return true;
 112   
         }
 113   
         
 114  61
         if (d1 == null || d2 == null) {
 115  2
             return false;
 116   
         }
 117   
 
 118  59
         if (d1.size() != d2.size()) {
 119  7
             return false;
 120   
         }
 121   
 
 122  52
         Enumeration e1 = d1.keys();
 123  52
         while (e1.hasMoreElements()) {
 124  73
             Object key = e1.nextElement();
 125  73
             Object value1 = d1.get(key);
 126  73
             Object value2 = d2.get(key);
 127  73
             if (value2 == null || !value1.equals(value2)) {
 128  6
                 return false;
 129   
             }
 130   
         }
 131   
         
 132   
         // don't need the opposite check as the Dictionaries have the
 133   
         // same size, so we've also covered all keys of d2 already.
 134   
 
 135  46
         return true;
 136   
     }
 137   
 
 138   
     /**
 139   
      * JDK 1.1 does not know the putAll method for hash tables.
 140   
      *
 141   
      * @since Ant 1.6
 142   
      */
 143  9
     public static void putAll(Dictionary m1, Dictionary m2) {
 144  9
         for(Enumeration it = m2.keys(); it.hasMoreElements();) {
 145  531
             Object key = it.nextElement();
 146  531
             m1.put(key, m2.get(key));
 147   
         }
 148   
     }
 149   
 }
 150