KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > P2HashMapKeySet


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o;
22
23 import java.util.*;
24
25 import com.db4o.inside.*;
26 import com.db4o.reflect.*;
27
28 /**
29  * @persistent
30  */

31 class P2HashMapKeySet implements Set {
32
33     private final P2HashMap i_map;
34
35     P2HashMapKeySet(P2HashMap a_map) {
36         i_map = a_map;
37     }
38
39     public boolean add(Object JavaDoc o) {
40         throw new UnsupportedOperationException JavaDoc();
41     }
42
43     public boolean addAll(Collection c) {
44         throw new UnsupportedOperationException JavaDoc();
45     }
46
47     public void clear() {
48         i_map.clear();
49     }
50
51     public boolean contains(Object JavaDoc o) {
52         return i_map.containsKey(o);
53     }
54
55     public boolean containsAll(Collection c) {
56         synchronized (i_map.streamLock()) {
57             i_map.checkActive();
58             Iterator i = c.iterator();
59             while (i.hasNext()) {
60                 if (i_map.get4(i.next()) == null) {
61                     return false;
62                 }
63             }
64         }
65         return true;
66     }
67
68     public boolean isEmpty() {
69         return i_map.isEmpty();
70     }
71
72     public Iterator iterator() {
73         synchronized (i_map.streamLock()) {
74             i_map.checkActive();
75             return new P2HashMapIterator(i_map);
76         }
77     }
78
79     public boolean remove(Object JavaDoc o) {
80         return i_map.remove(o) != null;
81     }
82
83     public boolean removeAll(Collection c) {
84         synchronized (i_map.streamLock()) {
85             i_map.checkActive();
86             boolean ret = false;
87             Iterator i = c.iterator();
88             while (i.hasNext()) {
89                 if (i_map.remove4(i.next()) != null) {
90                     ret = true;
91                 }
92             }
93             return ret;
94         }
95     }
96
97     public boolean retainAll(Collection c) {
98         throw new UnsupportedOperationException JavaDoc();
99     }
100
101     public int size() {
102         return i_map.size();
103     }
104
105     public Object JavaDoc[] toArray() {
106         synchronized (i_map.streamLock()) {
107             i_map.checkActive();
108             Object JavaDoc[] arr = new Object JavaDoc[i_map.i_size];
109             int j = 0;
110             Iterator i = new P2HashMapIterator(i_map);
111             while (i.hasNext()) {
112                 arr[j++] = i.next();
113             }
114             return arr;
115         }
116     }
117
118     public Object JavaDoc[] toArray(Object JavaDoc[] a) {
119         synchronized (i_map.streamLock()) {
120             i_map.checkActive();
121             int size = i_map.i_size;
122             if (a.length < size) {
123                 Transaction trans = i_map.getTrans();
124                 if(trans == null){
125                     Exceptions4.throwRuntimeException(29);
126                 }
127                 Reflector reflector = trans.reflector();
128                 a =
129                     (Object JavaDoc[])reflector.array().newInstance(
130                         reflector.forObject(a).getComponentType(),
131                         size);
132             }
133             int j = 0;
134             Iterator i = new P2HashMapIterator(i_map);
135             while (i.hasNext()) {
136                 a[j++] = i.next();
137             }
138             if (a.length > size) {
139                 a[size] = null;
140             }
141             return a;
142         }
143     }
144
145 }
146
Popular Tags