1 4 package com.tc.util; 5 6 import com.tc.object.SerializationUtil; 7 import com.tc.object.bytecode.ManagerUtil; 8 import com.tc.object.lockmanager.api.LockLevel; 9 10 import java.util.Collection ; 11 import java.util.Hashtable ; 12 import java.util.Iterator ; 13 import java.util.Set ; 14 15 public class HashtableKeySetWrapper implements Set { 16 17 private final Set realKeySet; 18 private final Hashtable hashtable; 19 20 public HashtableKeySetWrapper(Hashtable hashtable, Set realKeySet) { 21 this.hashtable = hashtable; 22 this.realKeySet = realKeySet; 23 } 24 25 public final boolean add(Object o) { 26 return realKeySet.add(o); 28 } 29 30 public final boolean addAll(Collection c) { 31 return realKeySet.addAll(c); 33 } 34 35 public final void clear() { 36 realKeySet.clear(); 38 } 39 40 public final boolean contains(Object o) { 41 return realKeySet.contains(o); 42 } 43 44 public final boolean containsAll(Collection c) { 45 return realKeySet.containsAll(c); 46 } 47 48 public final boolean equals(Object o) { 49 return realKeySet.equals(o); 50 } 51 52 public final int hashCode() { 53 return realKeySet.hashCode(); 54 } 55 56 public final boolean isEmpty() { 57 return realKeySet.isEmpty(); 58 } 59 60 public final Iterator iterator() { 61 return new IteratorWrapper(hashtable, realKeySet.iterator()); 62 } 63 64 public final boolean remove(Object o) { 65 return realKeySet.remove(o); 67 } 68 69 public final boolean removeAll(Collection c) { 70 return realKeySet.removeAll(c); 72 } 73 74 public final boolean retainAll(Collection c) { 75 boolean modified = false; 76 Iterator i = iterator(); 77 while (i.hasNext()) { 78 if (!c.contains(i.next())) { 79 i.remove(); 80 modified = true; 81 } 82 } 83 return modified; 84 } 85 86 public final int size() { 87 return realKeySet.size(); 88 } 89 90 public final Object [] toArray() { 91 return realKeySet.toArray(); 92 } 93 94 public final Object [] toArray(Object [] a) { 95 return realKeySet.toArray(a); 96 } 97 98 public static class IteratorWrapper implements Iterator { 99 100 private final Iterator realIterator; 101 private final Hashtable hashtable; 102 private Object last; 103 104 public IteratorWrapper(Hashtable hashtable, Iterator realIterator) { 105 this.hashtable = hashtable; 106 this.realIterator = realIterator; 107 } 108 109 public final void remove() { 110 ManagerUtil.monitorEnter(hashtable, LockLevel.WRITE); 111 try { 112 realIterator.remove(); 113 ManagerUtil.logicalInvoke(hashtable, SerializationUtil.REMOVE_KEY_SIGNATURE, new Object [] { last }); 115 } finally { 116 ManagerUtil.monitorExit(hashtable); 117 } 118 } 119 120 public final boolean hasNext() { 121 return realIterator.hasNext(); 122 } 123 124 public final Object next() { 125 last = realIterator.next(); 126 return last; 127 } 128 } 129 130 } 131 | Popular Tags |