Clover coverage report - Code Coverage for hivemind release 1.1-alpha-2
Coverage timestamp: Wed Feb 23 2005 09:59:04 EST
file stats: LOC: 101   Methods: 5
NCLOC: 47   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
MethodIterator.java 83.3% 100% 100% 96.6%
coverage coverage
 1   
 // Copyright 2004, 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.service;
 16   
 
 17   
 import java.lang.reflect.Method;
 18   
 import java.util.ArrayList;
 19   
 import java.util.HashMap;
 20   
 import java.util.List;
 21   
 import java.util.Map;
 22   
 import java.util.NoSuchElementException;
 23   
 
 24   
 import org.apache.hivemind.util.Defense;
 25   
 
 26   
 /**
 27   
  * Utility used to iterate over the visible methods of a class.
 28   
  * 
 29   
  * @author Howard Lewis Ship
 30   
  */
 31   
 public class MethodIterator
 32   
 {
 33   
     private boolean _toString;
 34   
 
 35   
     private int _index = 0;
 36   
 
 37   
     /** @since 1.1 */
 38   
     private int _count;
 39   
 
 40   
     /** @since 1.1 */
 41   
     private List _signatures;
 42   
 
 43  1817
     public MethodIterator(Class subjectClass)
 44   
     {
 45  1817
         Defense.notNull(subjectClass, "subjectClass");
 46   
 
 47  1817
         Method[] methods = subjectClass.getMethods();
 48   
 
 49  1817
         Map map = new HashMap();
 50   
 
 51  1817
         for (int i = 0; i < methods.length; i++)
 52  2125
             processMethod(methods[i], map);
 53   
 
 54  1817
         _signatures = new ArrayList(map.values());
 55  1817
         _count = _signatures.size();
 56   
     }
 57   
 
 58   
     /** @since 1.1 */
 59  2125
     private void processMethod(Method m, Map map)
 60   
     {
 61  2125
         _toString |= ClassFabUtils.isToString(m);
 62   
 
 63  2125
         MethodSignature sig = new MethodSignature(m);
 64  2125
         String uid = sig.getUniqueId();
 65   
 
 66  2125
         MethodSignature existing = (MethodSignature) map.get(uid);
 67   
 
 68  2125
         if (existing == null || sig.isOverridingSignatureOf(existing))
 69  2125
             map.put(uid, sig);
 70   
     }
 71   
 
 72  3933
     public boolean hasNext()
 73   
     {
 74  3933
         return _index < _count;
 75   
     }
 76   
 
 77   
     /**
 78   
      * Returns the next method (as a {@link MethodSignature}, returning null when all are
 79   
      * exhausted. Each method signature is returned exactly once (even if the same method signature
 80   
      * is defined in multiple inherited classes or interfaces). The order in which method signatures
 81   
      * are returned is not specified.
 82   
      * 
 83   
      * @throws NoSuchElementException
 84   
      *             if there are no more signatures
 85   
      */
 86  2124
     public MethodSignature next()
 87   
     {
 88  2124
         if (_index >= _count)
 89  1
             throw new NoSuchElementException();
 90   
 
 91  2123
         return (MethodSignature) _signatures.get(_index++);
 92   
     }
 93   
 
 94   
     /**
 95   
      * Returns true if the method <code>public String toString()</code> is part of the interface.
 96   
      */
 97  1814
     public boolean getToString()
 98   
     {
 99  1814
         return _toString;
 100   
     }
 101   
 }