KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > ValueComponent


1 /*****************************************************************************
2  * Copyright (C) Codehaus.org. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on Mar 5, 2005
10  *
11  * Author Ben Yu
12  * ZBS
13  */

14 package jfun.yan;
15
16 /**
17  * Codehaus.org.
18  *
19  * @author Ben Yu
20  *
21  */

22 final class ValueComponent<T> extends Component<T> {
23   private final T val;
24   
25   ValueComponent(final T val) {
26     this.val = val;
27   }
28   public T create(Dependency ac){
29     return val;
30   }
31   public Class JavaDoc getType(){
32     return val.getClass();
33   }
34   public Class JavaDoc verify(Dependency ac){
35     return getType();
36   }
37   
38   public boolean equals(Object JavaDoc other) {
39     if(other instanceof ValueComponent){
40       final ValueComponent v2 = (ValueComponent)other;
41       return val.equals(v2.val);
42     }
43     return false;
44   }
45   public int hashCode() {
46     return val.hashCode();
47   }
48   public String JavaDoc toString() {
49     return val.toString();
50   }
51   
52   public final Component<T> singleton(){return this;}
53   public final Component<T> guard(){return this;}
54   public final Component proxy(){
55     return this;
56   }
57   public final <I> Component<I> proxy(Class JavaDoc<I> type){
58     return subsume(type);
59   }
60   public boolean isSingleton(){
61     return true;
62   }
63   public boolean isConcrete(){
64     return true;
65   }
66 }
67
Popular Tags