1 21 package com.db4o; 22 23 import java.util.*; 24 25 import com.db4o.inside.*; 26 import com.db4o.reflect.*; 27 28 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 o) { 40 throw new UnsupportedOperationException (); 41 } 42 43 public boolean addAll(Collection c) { 44 throw new UnsupportedOperationException (); 45 } 46 47 public void clear() { 48 i_map.clear(); 49 } 50 51 public boolean contains(Object 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 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 (); 99 } 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 = 129 (Object [])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 |