KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > element > SetStore


1 package jfun.yan.element;
2
3 import java.util.Set JavaDoc;
4
5 import jfun.util.Misc;
6
7 /**
8  * This implementation stores component instances into a java.util.Set.
9  * <p>
10  * @author Ben Yu
11  * Nov 12, 2005 2:29:12 PM
12  */

13 public class SetStore<T> implements ElementStore<T> {
14   private final Set JavaDoc<T> set;
15   
16   /**
17    * Get the Set object storing the component instances.
18    */

19   public Set JavaDoc getSet() {
20     return set;
21   }
22
23   /**
24    * Create a SetStore object.
25    * @param set the set to store component instances.
26    */

27   public SetStore(Set JavaDoc<T> set) {
28     this.set = set;
29   }
30
31   public void storeElement(int ind, T obj) {
32     set.add(obj);
33   }
34
35   public boolean equals(Object JavaDoc obj) {
36     if(obj instanceof SetStore){
37       final SetStore other = (SetStore)obj;
38       return set==other.set;
39     }
40     else return false;
41   }
42
43   public int hashCode() {
44     return System.identityHashCode(set);
45   }
46
47   public String JavaDoc toString() {
48     return Misc.getTypeName(set.getClass());
49   }
50
51 }
52
Popular Tags