1 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 31 public class MethodIterator 32 { 33 private boolean _toString; 34 35 private int _index = 0; 36 37 38 private int _count; 39 40 41 private List _signatures; 42 43 public MethodIterator(Class subjectClass) 44 { 45 Defense.notNull(subjectClass, "subjectClass"); 46 47 Method [] methods = subjectClass.getMethods(); 48 49 Map map = new HashMap (); 50 51 for (int i = 0; i < methods.length; i++) 52 processMethod(methods[i], map); 53 54 _signatures = new ArrayList (map.values()); 55 _count = _signatures.size(); 56 } 57 58 59 private void processMethod(Method m, Map map) 60 { 61 _toString |= ClassFabUtils.isToString(m); 62 63 MethodSignature sig = new MethodSignature(m); 64 String uid = sig.getUniqueId(); 65 66 MethodSignature existing = (MethodSignature) map.get(uid); 67 68 if (existing == null || sig.isOverridingSignatureOf(existing)) 69 map.put(uid, sig); 70 } 71 72 public boolean hasNext() 73 { 74 return _index < _count; 75 } 76 77 86 public MethodSignature next() 87 { 88 if (_index >= _count) 89 throw new NoSuchElementException (); 90 91 return (MethodSignature) _signatures.get(_index++); 92 } 93 94 97 public boolean getToString() 98 { 99 return _toString; 100 } 101 } | Popular Tags |