1 /*
2 * Copyright 2007-2008 Naoki NOSE.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package jp.liq.container.reflect;
17
18 import java.lang.reflect.Method;
19 import java.util.Iterator;
20
21 import jp.liq.container.util.ArrayIterator;
22 import jp.liq.container.util.IteratorWrapper;
23
24 /**
25 * あるオブジェクトが保持するメソッドの中から、
26 * 指定された条件にマッチするものを順に返す、Iterable の実装です。
27 * @author nosen
28 *
29 */
30 public class ObjectMethodFinder extends MemberFinder<ObjectMethod, ObjectMethodFinder>
31 implements Iterable<ObjectMethod> {
32
33 private final Object target;
34
35 /**
36 * このクラスのインスタンスを構築します。
37 * @param target 対象オブジェクト
38 */
39 public ObjectMethodFinder(Object target) {
40 this.target = target;
41
42 }
43
44 /**
45 * @see jp.liq.container.reflect.MemberFinder#getThis()
46 */
47 @Override
48 protected ObjectMethodFinder getThis() {
49 return this;
50 }
51
52 @Override
53 protected Iterator<ObjectMethod> getCandidates() {
54 return new ObjectMethodIterator(
55 new ArrayIterator<Method>(target.getClass().getMethods()));
56 }
57
58 private class ObjectMethodIterator extends IteratorWrapper<ObjectMethod, Method> {
59 public ObjectMethodIterator(Iterator<Method> iterator) {
60 super(iterator);
61 }
62
63 public ObjectMethod next() {
64 return new ObjectMethod(iterator.next(), target);
65 }
66 }
67 }