1 4 package com.tcclient.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.Iterator ; 11 import java.util.Map ; 12 import java.util.Set ; 13 import java.util.Map.Entry; 14 15 18 public class HashtableEntrySetWrapper extends MapEntrySetWrapper { 19 public final static String CLASS = "com/tcclient/util/HashtableEntrySetWrapper"; 20 21 public HashtableEntrySetWrapper(Map map, Set realEntrySet) { 22 super(map, realEntrySet); 23 } 24 25 public final Iterator iterator() { 26 return new HashtableIteratorWrapper(map, realEntrySet.iterator()); 27 } 28 29 public final boolean remove(Object o) { 30 boolean removed = false; 31 ManagerUtil.monitorEnter(map, LockLevel.WRITE); 32 try { 33 ManagerUtil.checkWriteAccess(map); 34 removed = realEntrySet.remove(o); 35 if (removed) { 36 ManagerUtil.logicalInvoke(map, SerializationUtil.REMOVE_KEY_SIGNATURE, 37 new Object [] { ((Map.Entry ) o).getKey() }); 38 } 39 } finally { 40 ManagerUtil.monitorExit(map); 41 } 42 return removed; 43 } 44 45 private static class HashtableIteratorWrapper implements Iterator { 46 47 protected final Iterator realIterator; 48 protected final Map map; 49 protected Entry current; 50 51 HashtableIteratorWrapper(Map map, Iterator realIterator) { 52 this.map = map; 53 this.realIterator = realIterator; 54 } 55 56 public final void remove() { 57 ManagerUtil.monitorEnter(map, LockLevel.WRITE); 58 try { 59 realIterator.remove(); 60 61 ManagerUtil.logicalInvoke(map, SerializationUtil.REMOVE_KEY_SIGNATURE, new Object [] { current.getKey() }); 64 } finally { 65 ManagerUtil.monitorExit(map); 66 } 67 } 68 69 public final boolean hasNext() { 70 boolean rv = realIterator.hasNext(); 71 return rv; 72 } 73 74 public final Object next() { 75 current = new EntryWrapper(map, (Entry) realIterator.next()); 76 return current; 77 } 78 79 } 80 81 } 82 | Popular Tags |