2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Clover coverage report - Code Coverage for hivemind release 1.2.1
Coverage timestamp: Fri Feb 10 2006 16:33:43 PST
file stats: LOC: 101   Methods: 5
NCLOC: 47   Classes: 1
 
 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  2085 public MethodIterator(Class subjectClass)
 44    {
 45  2085 Defense.notNull(subjectClass, "subjectClass");
 46   
 47  2085 Method[] methods = subjectClass.getMethods();
 48   
 49  2085 Map map = new HashMap();
 50   
 51  2085 for (int i = 0; i < methods.length; i++)
 52  2470 processMethod(methods[i], map);
 53   
 54  2085 _signatures = new ArrayList(map.values());
 55  2085 _count = _signatures.size();
 56    }
 57   
 58    /** @since 1.1 */
 59  2470 private void processMethod(Method m, Map map)
 60    {
 61  2470 _toString |= ClassFabUtils.isToString(m);
 62   
 63  2470 MethodSignature sig = new MethodSignature(m);
 64  2470 String uid = sig.getUniqueId();
 65   
 66  2470 MethodSignature existing = (MethodSignature) map.get(uid);
 67   
 68  2470 if (existing == null || sig.isOverridingSignatureOf(existing))
 69  2470 map.put(uid, sig);
 70    }
 71   
 72  4546 public boolean hasNext()
 73    {
 74  4546 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  2469 public MethodSignature next()
 87    {
 88  2469 if (_index >= _count)
 89  1 throw new NoSuchElementException();
 90   
 91  2468 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  2082 public boolean getToString()
 98    {
 99  2082 return _toString;
 100    }
 101    }