Added a SynchronizedIntSet which must back the intKeySet() method of

a SynchronizedHashIntMap.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1702 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray
2005-08-25 19:55:10 +00:00
parent 51429770cb
commit 6bdd153cba
@@ -237,17 +237,21 @@ public class Collections
synchronized(mutex) {m.clear();} synchronized(mutex) {m.clear();}
} }
private transient Set keySet = null; private transient IntSet keySet = null;
private transient Set entrySet = null; private transient Set entrySet = null;
private transient Collection values = null; private transient Collection values = null;
public Set keySet() { public Set keySet() {
return intKeySet();
}
public IntSet intKeySet () {
synchronized(mutex) { synchronized(mutex) {
if (keySet==null) if (keySet==null)
keySet = new SynchronizedSet(m.keySet(), mutex); keySet = new SynchronizedIntSet(m.intKeySet(), mutex);
return keySet; return keySet;
} }
} }
public Set entrySet() { public Set entrySet() {
synchronized(mutex) { synchronized(mutex) {
@@ -301,6 +305,44 @@ public class Collections
} }
} }
protected static class SynchronizedIntSet extends SynchronizedSet
implements IntSet
{
SynchronizedIntSet (IntSet s) {
super(s);
_i = s;
}
SynchronizedIntSet (IntSet s, Object mutex) {
super(s, mutex);
_i = s;
}
public boolean contains (int value) {
synchronized(mutex) {return _i.contains(value);}
}
public boolean add (int value) {
synchronized(mutex) {return _i.add(value);}
}
public boolean remove (int value) {
synchronized(mutex) {return _i.remove(value);}
}
public Interator interator () {
// must be manually sync'd by user
return _i.interator();
}
public int[] toIntArray () {
synchronized(mutex) {return _i.toIntArray();}
}
/** Pre-casted version of our backing set. */
protected IntSet _i;
}
/** /**
* I wish I could use this from the <code>java.util.Collections</code> * I wish I could use this from the <code>java.util.Collections</code>
* class, but those crazy kids at Sun are always using private and * class, but those crazy kids at Sun are always using private and