KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > SetIteratorWrapper


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.util;
5
6 import com.tc.object.bytecode.ManagerUtil;
7
8 import java.util.Iterator JavaDoc;
9 import java.util.Set JavaDoc;
10
11 /**
12  * Since a Set is just a wrapper around a HashMap we need to use this to find out about removes from iterators on sets.
13  * This is how we are doing it.
14  */

15 public class SetIteratorWrapper implements Iterator JavaDoc {
16   private final Set JavaDoc set;
17   private final Iterator JavaDoc iterator;
18   private Object JavaDoc current;
19
20   public SetIteratorWrapper(Iterator JavaDoc iterator, Set JavaDoc set) {
21     this.set = set;
22     this.iterator = iterator;
23   }
24
25   public boolean hasNext() {
26     return this.iterator.hasNext();
27   }
28
29   public Object JavaDoc next() {
30     current = iterator.next();
31     return current;
32   }
33
34   public void remove() {
35     ManagerUtil.checkWriteAccess(set);
36     iterator.remove();
37     ManagerUtil.logicalInvoke(set, "remove(Ljava/lang/Object;)Z", new Object JavaDoc[] { current });
38   }
39 }
40
Popular Tags