1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
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 |
| |
28 |
| |
29 |
| |
30 |
| |
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 |
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 |
| |
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 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
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 |
| |
96 |
| |
97 |
2082
| public boolean getToString()
|
98 |
| { |
99 |
2082
| return _toString;
|
100 |
| } |
101 |
| } |