() {
public boolean hasNext () {
@@ -164,13 +153,12 @@ public class Collections
}
/**
- * Returns a synchronized (thread-safe) int map backed by the
- * specified int map. In order to guarantee serial access, it is
- * critical that all access to the backing int map is
- * accomplished through the returned int map.
+ * Returns a synchronized (thread-safe) int map backed by the specified int map. In order to
+ * guarantee serial access, it is critical that all access to the backing int
+ * map is accomplished through the returned int map.
*
- * It is imperative that the user manually synchronize on the
- * returned int map when iterating over any of its collection views:
+ *
It is imperative that the user manually synchronize on the returned int map when
+ * iterating over any of its collection views:
*
*
* IntMap m = Collections.synchronizedIntMap(new HashIntMap());
@@ -184,28 +172,25 @@ public class Collections
* }
*
*
- * Failure to follow this advice may result in non-deterministic
- * behavior.
+ * Failure to follow this advice may result in non-deterministic behavior.
*
- * The returned map will be serializable if the specified map is
- * serializable.
+ *
The returned map will be serializable if the specified map is serializable.
*
* @param m the int map to be "wrapped" in a synchronized int map.
*
* @return a synchronized view of the specified int map.
*/
public static IntMap synchronizedIntMap (IntMap m) {
- return new SynchronizedIntMap(m);
+ return new SynchronizedIntMap(m);
}
/**
- * Returns a synchronized (thread-safe) int set backed by the
- * specified int set. In order to guarantee serial access, it is
- * critical that all access to the backing int map is
- * accomplished through the returned int map.
+ * Returns a synchronized (thread-safe) int set backed by the specified int set. In order to
+ * guarantee serial access, it is critical that all access to the backing int
+ * map is accomplished through the returned int map.
*
- * It is imperative that the user manually synchronize on the
- * returned int map when iterating over any of its collection views:
+ *
It is imperative that the user manually synchronize on the returned int map when
+ * iterating over any of its collection views:
*
*
* IntSet s = Collections.synchronizedIntSet(new ArrayIntSet());
@@ -217,11 +202,9 @@ public class Collections
* }
*
*
- * Failure to follow this advice may result in non-deterministic
- * behavior.
+ * Failure to follow this advice may result in non-deterministic behavior.
*
- * The returned set will be serializable if the specified set is
- * serializable.
+ *
The returned set will be serializable if the specified set is serializable.
*
* @param s the int set to be "wrapped" in a synchronized int set.
*
@@ -236,10 +219,14 @@ public class Collections
*/
protected static class SynchronizedIntMap implements IntMap
{
- private IntMap m; // Backing Map
+ private IntMap m; // Backing Map
private Object mutex; // Object on which to synchronize
- SynchronizedIntMap(IntMap m) {
+ private transient IntSet keySet = null;
+ private transient Set> entrySet = null;
+ private transient Collection values = null;
+
+ SynchronizedIntMap (IntMap m) {
if (m == null) {
throw new NullPointerException();
}
@@ -247,7 +234,7 @@ public class Collections
mutex = this;
}
- SynchronizedIntMap(IntMap m, Object mutex) {
+ SynchronizedIntMap(IntMap m, Object mutex) {
if (m == null) {
throw new NullPointerException();
}
@@ -255,135 +242,132 @@ public class Collections
this.mutex = mutex;
}
- public int size() {
- synchronized(mutex) {return m.size();}
+ public int size () {
+ synchronized(mutex) {return m.size();}
}
- public boolean isEmpty(){
- synchronized(mutex) {return m.isEmpty();}
+ public boolean isEmpty (){
+ synchronized(mutex) {return m.isEmpty();}
}
- public boolean containsKey(int key) {
- synchronized(mutex) {return m.containsKey(key);}
+ public boolean containsKey (int key) {
+ synchronized(mutex) {return m.containsKey(key);}
}
- public boolean containsKey(Object key) {
- synchronized(mutex) {return m.containsKey(key);}
+ public boolean containsKey (Object key) {
+ synchronized(mutex) {return m.containsKey(key);}
}
- public boolean containsValue(Object value){
- synchronized(mutex) {return m.containsValue(value);}
+ public boolean containsValue (Object value){
+ synchronized(mutex) {return m.containsValue(value);}
}
- public V get(int key) {
- synchronized(mutex) {return m.get(key);}
+ public V get (int key) {
+ synchronized(mutex) {return m.get(key);}
}
- public V get(Object key) {
- synchronized(mutex) {return m.get(key);}
+ public V get (Object key) {
+ synchronized(mutex) {return m.get(key);}
}
- public V put(int key, V value) {
- synchronized(mutex) {return m.put(key, value);}
+ public V put (int key, V value) {
+ synchronized(mutex) {return m.put(key, value);}
}
- public V put(Integer key, V value) {
- synchronized(mutex) {return m.put(key, value);}
+ public V put (Integer key, V value) {
+ synchronized(mutex) {return m.put(key, value);}
}
- public V remove(int key) {
- synchronized(mutex) {return m.remove(key);}
+ public V remove (int key) {
+ synchronized(mutex) {return m.remove(key);}
}
- public V remove(Object key) {
- synchronized(mutex) {return m.remove(key);}
+ public V remove (Object key) {
+ synchronized(mutex) {return m.remove(key);}
}
- public void putAll(Map extends Integer,? extends V> map) {
- synchronized(mutex) {m.putAll(map);}
+ public void putAll (Map extends Integer,? extends V> map) {
+ synchronized(mutex) {m.putAll(map);}
}
- public void clear() {
- synchronized(mutex) {m.clear();}
+ public void clear () {
+ synchronized(mutex) {m.clear();}
}
- private transient IntSet keySet = null;
- private transient Set> entrySet = null;
- private transient Collection values = null;
-
- public Set keySet() {
+ public Set keySet () {
return intKeySet();
- }
+ }
public IntSet intKeySet () {
synchronized(mutex) {
- if (keySet==null)
+ if (keySet == null) {
keySet = new SynchronizedIntSet(m.intKeySet(), mutex);
+ }
return keySet;
}
}
- public Set> entrySet() {
+ public Set> entrySet () {
synchronized(mutex) {
- if (entrySet==null)
- entrySet = new SynchronizedSet>(
- m.entrySet(), mutex);
+ if (entrySet == null) {
+ entrySet = new SynchronizedSet>(m.entrySet(), mutex);
+ }
return entrySet;
}
- }
+ }
- public Set> intEntrySet() {
+ public Set> intEntrySet () {
synchronized(mutex) {
return new SynchronizedSet>(m.intEntrySet(), mutex);
}
- }
+ }
- public Collection values() {
+ public Collection values () {
synchronized(mutex) {
- if (values==null)
+ if (values == null) {
values = new SynchronizedCollection(m.values(), mutex);
+ }
return values;
}
}
- @Override
- public boolean equals(Object o) {
+ @Override
+ public boolean equals (Object o) {
synchronized(mutex) {return m.equals(o);}
}
- @Override
- public int hashCode() {
+ @Override
+ public int hashCode () {
synchronized(mutex) {return m.hashCode();}
}
- @Override
- public String toString() {
- synchronized(mutex) {return m.toString();}
+ @Override
+ public String toString () {
+ synchronized(mutex) {return m.toString();}
}
}
/**
- * I wish I could use this from the java.util.Collections
- * class, but those crazy kids at Sun are always using private and
- * default access and pointlessly preventing people from properly
- * reusing their code. Yay!
+ * I wish I could use this from the java.util.Collections class, but those crazy
+ * kids at Sun are always using private and default access and pointlessly preventing people
+ * from properly reusing their code. Yay!
*/
- protected static class SynchronizedSet
- extends SynchronizedCollection implements Set {
- SynchronizedSet(Set s) {
+ protected static class SynchronizedSet extends SynchronizedCollection implements Set
+ {
+ SynchronizedSet (Set s) {
super(s);
}
- SynchronizedSet(Set s, Object mutex) {
+ SynchronizedSet(Set s, Object mutex) {
super(s, mutex);
}
- @Override
- public boolean equals(Object o) {
- synchronized(mutex) {return c.equals(o);}
+ @Override
+ public boolean equals (Object o) {
+ synchronized(mutex) {return c.equals(o);}
}
- @Override
- public int hashCode() {
- synchronized(mutex) {return c.hashCode();}
+ @Override
+ public int hashCode () {
+ synchronized(mutex) {return c.hashCode();}
}
}
@@ -413,97 +397,106 @@ public class Collections
}
public Interator interator () {
- // must be manually sync'd by user
- return _i.interator();
+ return _i.interator(); // must be manually sync'd by user
}
public int[] toIntArray () {
synchronized(mutex) {return _i.toIntArray();}
}
+ @Override
+ public boolean equals (Object o) {
+ synchronized(mutex) {return _i.equals(o);}
+ }
+
+ @Override
+ public int hashCode () {
+ synchronized(mutex) {return _i.hashCode();}
+ }
+
/** Properly casted reference to 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
- * default access and pointlessly preventing people from properly
- * reusing their code. Yay!
+ * I wish I could use this from the java.util.Collections class, but those crazy
+ * kids at Sun are always using private and default access and pointlessly preventing people
+ * from properly reusing their code. Yay!
*/
- protected static class SynchronizedCollection
- implements Collection {
- Collection c; // Backing Collection
- Object mutex; // Object on which to synchronize
+ protected static class SynchronizedCollection implements Collection
+ {
+ protected Collection c; // Backing Collection
+ protected Object mutex; // Object on which to synchronize
- SynchronizedCollection(Collection c) {
- if (c==null)
+ SynchronizedCollection (Collection c) {
+ if (c==null) {
throw new NullPointerException();
- this.c = c;
+ }
+ this.c = c;
mutex = this;
}
- SynchronizedCollection(Collection c, Object mutex) {
- this.c = c;
+ SynchronizedCollection(Collection c, Object mutex) {
+ this.c = c;
this.mutex = mutex;
}
- public int size() {
- synchronized(mutex) {return c.size();}
+ public int size () {
+ synchronized(mutex) {return c.size();}
}
- public boolean isEmpty() {
- synchronized(mutex) {return c.isEmpty();}
+ public boolean isEmpty () {
+ synchronized(mutex) {return c.isEmpty();}
}
- public boolean contains(Object o) {
- synchronized(mutex) {return c.contains(o);}
+ public boolean contains (Object o) {
+ synchronized(mutex) {return c.contains(o);}
}
- public Object[] toArray() {
- synchronized(mutex) {return c.toArray();}
+ public Object[] toArray () {
+ synchronized(mutex) {return c.toArray();}
}
- public T[] toArray(T[] a) {
- synchronized(mutex) {return c.toArray(a);}
+ public T[] toArray (T[] a) {
+ synchronized(mutex) {return c.toArray(a);}
}
- public Iterator iterator() {
+ public Iterator iterator () {
return c.iterator(); // Must be manually synched by user!
}
- public boolean add(E o) {
- synchronized(mutex) {return c.add(o);}
+ public boolean add (E o) {
+ synchronized(mutex) {return c.add(o);}
}
- public boolean remove(Object o) {
- synchronized(mutex) {return c.remove(o);}
+ public boolean remove (Object o) {
+ synchronized(mutex) {return c.remove(o);}
}
- public boolean containsAll(Collection> coll) {
- synchronized(mutex) {return c.containsAll(coll);}
+ public boolean containsAll (Collection> coll) {
+ synchronized(mutex) {return c.containsAll(coll);}
}
- public boolean addAll(Collection extends E> coll) {
- synchronized(mutex) {return c.addAll(coll);}
+ public boolean addAll (Collection extends E> coll) {
+ synchronized(mutex) {return c.addAll(coll);}
}
- public boolean removeAll(Collection> coll) {
- synchronized(mutex) {return c.removeAll(coll);}
+ public boolean removeAll (Collection> coll) {
+ synchronized(mutex) {return c.removeAll(coll);}
}
- public boolean retainAll(Collection> coll) {
- synchronized(mutex) {return c.retainAll(coll);}
+ public boolean retainAll (Collection> coll) {
+ synchronized(mutex) {return c.retainAll(coll);}
}
- public void clear() {
- synchronized(mutex) {c.clear();}
+ public void clear () {
+ synchronized(mutex) {c.clear();}
}
- @Override
- public String toString() {
- synchronized(mutex) {return c.toString();}
+ @Override
+ public String toString () {
+ synchronized(mutex) {return c.toString();}
}
}
/**
- * An iterator that iterates over the union of the iterators provided by a
- * collection of iterators.
+ * An iterator that iterates over the union of the iterators provided by a collection of
+ * iterators.
*/
protected static class MetaIterator implements Iterator
{
/**
- * @param iterable a Iterable containing more Iterables
- * whose elements we are to iterate over.
+ * @param iterable a Iterable containing more Iterables whose elements we are to iterate
+ * over.
*/
public MetaIterator (Iterable> iterable)
{