001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o;
022:
023: import java.util.*;
024:
025: import com.db4o.internal.*;
026: import com.db4o.reflect.*;
027:
028: /**
029: * @persistent
030: */
031: class P2HashMapKeySet implements Set {
032:
033: private final P2HashMap i_map;
034:
035: P2HashMapKeySet(P2HashMap a_map) {
036: i_map = a_map;
037: }
038:
039: public boolean add(Object o) {
040: throw new UnsupportedOperationException();
041: }
042:
043: public boolean addAll(Collection c) {
044: throw new UnsupportedOperationException();
045: }
046:
047: public void clear() {
048: i_map.clear();
049: }
050:
051: public boolean contains(Object o) {
052: return i_map.containsKey(o);
053: }
054:
055: public boolean containsAll(Collection c) {
056: synchronized (i_map.streamLock()) {
057: i_map.checkActive();
058: Iterator i = c.iterator();
059: while (i.hasNext()) {
060: if (i_map.get4(i.next()) == null) {
061: return false;
062: }
063: }
064: }
065: return true;
066: }
067:
068: public boolean isEmpty() {
069: return i_map.isEmpty();
070: }
071:
072: public Iterator iterator() {
073: synchronized (i_map.streamLock()) {
074: i_map.checkActive();
075: return new P2HashMapIterator(i_map);
076: }
077: }
078:
079: public boolean remove(Object o) {
080: return i_map.remove(o) != null;
081: }
082:
083: public boolean removeAll(Collection c) {
084: synchronized (i_map.streamLock()) {
085: i_map.checkActive();
086: boolean ret = false;
087: Iterator i = c.iterator();
088: while (i.hasNext()) {
089: if (i_map.remove4(i.next()) != null) {
090: ret = true;
091: }
092: }
093: return ret;
094: }
095: }
096:
097: public boolean retainAll(Collection c) {
098: throw new UnsupportedOperationException();
099: }
100:
101: public int size() {
102: return i_map.size();
103: }
104:
105: public Object[] toArray() {
106: synchronized (i_map.streamLock()) {
107: i_map.checkActive();
108: Object[] arr = new Object[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[] toArray(Object[] 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 = (Object[]) reflector.array()
129: .newInstance(
130: reflector.forObject(a)
131: .getComponentType(), 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: }
|