From 6bdd153cba9ebbb2fcee64e393be3b10bd1f3f4d Mon Sep 17 00:00:00 2001 From: ray Date: Thu, 25 Aug 2005 19:55:10 +0000 Subject: [PATCH] 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 --- .../java/com/samskivert/util/Collections.java | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/Collections.java b/projects/samskivert/src/java/com/samskivert/util/Collections.java index a9535538..23d4cbd5 100644 --- a/projects/samskivert/src/java/com/samskivert/util/Collections.java +++ b/projects/samskivert/src/java/com/samskivert/util/Collections.java @@ -237,17 +237,21 @@ public class Collections synchronized(mutex) {m.clear();} } - private transient Set keySet = null; + private transient IntSet keySet = null; private transient Set entrySet = null; private transient Collection values = null; public Set keySet() { + return intKeySet(); + } + + public IntSet intKeySet () { synchronized(mutex) { if (keySet==null) - keySet = new SynchronizedSet(m.keySet(), mutex); + keySet = new SynchronizedIntSet(m.intKeySet(), mutex); return keySet; } - } + } public Set entrySet() { 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 java.util.Collections * class, but those crazy kids at Sun are always using private and