KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > coffer > types > KeySet_c


1 package polyglot.ext.coffer.types;
2
3 import polyglot.ext.jl.types.*;
4 import polyglot.types.*;
5 import polyglot.visit.*;
6 import polyglot.util.*;
7
8 import java.util.*;
9
10 public class KeySet_c extends TypeObject_c implements KeySet
11 {
12     HashSet set;
13
14     public KeySet_c(TypeSystem ts, Position pos) {
15         super(ts, pos);
16         this.set = new HashSet();
17     }
18
19     public int size() {
20         return set.size();
21     }
22
23     public Iterator iterator() {
24         return set.iterator();
25     }
26
27     public boolean contains(Key key) {
28         return set.contains(key);
29     }
30
31     public KeySet add(Key key) {
32         if (set.contains(key)) return this;
33         KeySet_c s = (KeySet_c) copy();
34         s.set = new HashSet(set);
35         s.set.add(key);
36         return s;
37     }
38
39     public KeySet remove(Key key) {
40         if (! set.contains(key)) return this;
41         KeySet_c s = (KeySet_c) copy();
42         s.set = new HashSet(set);
43         s.set.remove(key);
44         return s;
45     }
46
47     public KeySet addAll(KeySet keys) {
48         KeySet_c other = (KeySet_c) keys;
49         KeySet_c s = (KeySet_c) copy();
50         s.set = new HashSet(set);
51         s.set.addAll(other.set);
52         return s;
53     }
54
55     public KeySet removeAll(KeySet keys) {
56         KeySet_c other = (KeySet_c) keys;
57         KeySet_c s = (KeySet_c) copy();
58         s.set = new HashSet(set);
59         s.set.removeAll(other.set);
60         return s;
61     }
62
63     public KeySet retainAll(KeySet keys) {
64         KeySet_c other = (KeySet_c) keys;
65         KeySet_c s = (KeySet_c) copy();
66         s.set = new HashSet(set);
67         s.set.retainAll(other.set);
68         return s;
69     }
70
71     public boolean containsAll(KeySet keys) {
72         KeySet_c other = (KeySet_c) keys;
73         return set.containsAll(other.set);
74     }
75
76     public boolean equalsImpl(TypeObject o) {
77         if (o instanceof KeySet_c) {
78             KeySet_c other = (KeySet_c) o;
79             return set.equals(other.set);
80         }
81         return false;
82     }
83
84     public boolean isEmpty() {
85         return set.isEmpty();
86     }
87
88     public boolean isCanonical() {
89         for (Iterator i = iterator(); i.hasNext(); ) {
90             Key k = (Key) i.next();
91             if (! k.isCanonical())
92                 return false;
93         }
94         return true;
95     }
96
97     public String JavaDoc toString() {
98         return set.toString().replace('[', '{').replace(']', '}');
99     }
100 }
101
Popular Tags