KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > RepeatComponent


1 package jfun.yan;
2
3 final class RepeatComponent<T> extends Component<T> {
4   private final Creator<T> cc;
5   private final int times;
6   public boolean isConcrete(){
7     return cc.isConcrete();
8   }
9   public RepeatComponent(Creator<T> cc, int times) {
10     this.cc = cc;
11     this.times = times;
12   }
13
14   public Class JavaDoc getType() {
15     return cc.getType();
16   }
17
18   public T create(Dependency dep){
19     T r = null;
20     for(int i=0; i<times; i++){
21       r = cc.create(dep);
22     }
23     return r;
24   }
25
26   public Class JavaDoc verify(Dependency dep){
27     Class JavaDoc r = null;
28     for(int i=0; i<times; i++){
29       r = cc.verify(dep);
30     }
31     return r;
32   }
33   public boolean equals(Object JavaDoc obj) {
34     if(obj instanceof RepeatComponent){
35       final RepeatComponent other = (RepeatComponent)obj;
36       return times==other.times && cc.equals(other.cc);
37     }
38     else return false;
39   }
40   public int hashCode() {
41     return cc.hashCode()*31+times;
42   }
43   public String JavaDoc toString() {
44     return cc.toString()+".repeat("+times+")";
45   }
46   public boolean isSingleton(){
47     return cc.isSingleton();
48   }
49 }
50
Popular Tags