Clover coverage report - Code Coverage for hivemind release 1.0
Coverage timestamp: Wed Sep 22 2004 08:05:25 EDT
file stats: LOC: 94   Methods: 4
NCLOC: 48   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 87.5% 95% 100% 93.8%
coverage coverage
 1   
 //  Copyright 2004 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.HashSet;
 19   
 import java.util.Set;
 20   
 
 21   
 /**
 22   
  * Utility used to iterate over the visible methods of a class.
 23   
  *
 24   
  * @author Howard Lewis Ship
 25   
  */
 26   
 public class MethodIterator
 27   
 {
 28   
     private Set _seen = new HashSet();
 29   
     private boolean _toString;
 30   
 
 31   
     private int _index = 0;
 32   
     private Method[] _methods;
 33   
     private MethodSignature _next;
 34   
 
 35  1357
     public MethodIterator(Class subjectClass)
 36   
     {
 37  1357
         _methods = subjectClass.getMethods();
 38   
     }
 39   
 
 40  2933
     public boolean hasNext()
 41   
     {
 42  2933
         if (_next != null)
 43  0
             return true;
 44   
 
 45  2933
         _next = next();
 46   
 
 47  2933
         return _next != null;
 48   
     }
 49   
 
 50   
     /**
 51   
      * Returns the next method (as a {@link MethodSignature}, returning null
 52   
      * when all are exhausted.  Each method signature is returned exactly once.
 53   
      */
 54  4517
     public MethodSignature next()
 55   
     {
 56  4517
         if (_next != null)
 57   
         {
 58  1578
             MethodSignature result = _next;
 59  1578
             _next = null;
 60   
 
 61  1578
             return result;
 62   
         }
 63   
 
 64  2939
         while (true)
 65   
         {
 66  2940
             if (_index >= _methods.length)
 67  1359
                 return null;
 68   
 
 69  1581
             Method m = _methods[_index++];
 70   
 
 71  1581
             _toString |= ClassFabUtils.isToString(m);
 72   
 
 73  1581
             MethodSignature result = new MethodSignature(m);
 74   
 
 75  1581
             if (_seen.contains(result))
 76  1
                 continue;
 77   
 
 78  1580
             _seen.add(result);
 79   
 
 80  1580
             return result;
 81   
         }
 82   
     }
 83   
 
 84   
     /**
 85   
      * Returns true if the method <code>public String toString()</code> was returned by
 86   
      * {@link #next()}. This is typically used to avoid overloading toString() if it is
 87   
      * part of a service interface.
 88   
      */
 89  1357
     public boolean getToString()
 90   
     {
 91  1357
         return _toString;
 92   
     }
 93   
 }
 94