|
|||||||||||||||||||
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% |
|
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 | 1356 |
public MethodIterator(Class subjectClass)
|
36 |
{ |
|
37 | 1356 |
_methods = subjectClass.getMethods(); |
38 |
} |
|
39 |
|
|
40 | 2931 |
public boolean hasNext() |
41 |
{ |
|
42 | 2931 |
if (_next != null) |
43 | 0 |
return true; |
44 |
|
|
45 | 2931 |
_next = next(); |
46 |
|
|
47 | 2931 |
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 | 4514 |
public MethodSignature next()
|
55 |
{ |
|
56 | 4514 |
if (_next != null) |
57 |
{ |
|
58 | 1577 |
MethodSignature result = _next; |
59 | 1577 |
_next = null;
|
60 |
|
|
61 | 1577 |
return result;
|
62 |
} |
|
63 |
|
|
64 | 2937 |
while (true) |
65 |
{ |
|
66 | 2938 |
if (_index >= _methods.length)
|
67 | 1358 |
return null; |
68 |
|
|
69 | 1580 |
Method m = _methods[_index++]; |
70 |
|
|
71 | 1580 |
_toString |= ClassFabUtils.isToString(m); |
72 |
|
|
73 | 1580 |
MethodSignature result = new MethodSignature(m);
|
74 |
|
|
75 | 1580 |
if (_seen.contains(result))
|
76 | 1 |
continue;
|
77 |
|
|
78 | 1579 |
_seen.add(result); |
79 |
|
|
80 | 1579 |
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 | 1356 |
public boolean getToString() |
90 |
{ |
|
91 | 1356 |
return _toString;
|
92 |
} |
|
93 |
} |
|
94 |
|
|