You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2009/01/29 19:48:47 UTC
svn commit: r738956 [4/34] - in
/commons/proper/collections/branches/collections_jdk5_branch/src:
java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/
java/org/apache/commons/collections/bidimap/
java/org/apache/commons/collect...
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractMapBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractMapBag.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractMapBag.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractMapBag.java Thu Jan 29 18:48:37 2009
@@ -33,12 +33,13 @@
* Abstract implementation of the {@link Bag} interface to simplify the creation
* of subclass implementations.
* <p>
- * Subclasses specify a Map implementation to use as the internal storage.
- * The map will be used to map bag elements to a number; the number represents
- * the number of occurrences of that element in the bag.
- *
+ * Subclasses specify a Map implementation to use as the internal storage. The
+ * map will be used to map bag elements to a number; the number represents the
+ * number of occurrences of that element in the bag.
+ *
* @since Commons Collections 3.0 (previously DefaultMapBag v2.0)
- * @version $Revision$ $Date$
+ * @version $Revision$ $Date: 2006-10-27 19:52:37 -0500 (Fri, 27 Oct
+ * 2006) $
*
* @author Chuck Burdick
* @author Michael A. Smith
@@ -46,16 +47,16 @@
* @author Janek Bogucki
* @author Steve Clark
*/
-public abstract class AbstractMapBag implements Bag {
-
+public abstract class AbstractMapBag<E> implements Bag<E> {
+
/** The map to use to store the data */
- private transient Map map;
+ private transient Map<E, MutableInteger> map;
/** The current total size of the bag */
private int size;
/** The modification count for fail fast iterators */
private transient int modCount;
/** The modification count for fail fast iterators */
- private transient Set uniqueSet;
+ private transient Set<E> uniqueSet;
/**
* Constructor needed for subclass serialisation.
@@ -66,30 +67,30 @@
}
/**
- * Constructor that assigns the specified Map as the backing store.
- * The map must be empty and non-null.
+ * Constructor that assigns the specified Map as the backing store. The map
+ * must be empty and non-null.
*
- * @param map the map to assign
+ * @param map the map to assign
*/
- protected AbstractMapBag(Map map) {
+ protected AbstractMapBag(Map<E, MutableInteger> map) {
super();
this.map = map;
}
/**
- * Utility method for implementations to access the map that backs
- * this bag. Not intended for interactive use outside of subclasses.
+ * Utility method for implementations to access the map that backs this bag.
+ * Not intended for interactive use outside of subclasses.
*
* @return the map being used by the Bag
*/
- protected Map getMap() {
+ protected Map<E, MutableInteger> getMap() {
return map;
}
//-----------------------------------------------------------------------
/**
* Returns the number of elements in this bag.
- *
+ *
* @return current size of the bag
*/
public int size() {
@@ -98,7 +99,7 @@
/**
* Returns true if the underlying map is empty.
- *
+ *
* @return true if bag is empty
*/
public boolean isEmpty() {
@@ -106,14 +107,14 @@
}
/**
- * Returns the number of occurrence of the given element in this bag
- * by looking up its count in the underlying map.
- *
- * @param object the object to search for
+ * Returns the number of occurrence of the given element in this bag by
+ * looking up its count in the underlying map.
+ *
+ * @param object the object to search for
* @return the number of occurrences of the object, zero if not found
*/
public int getCount(Object object) {
- MutableInteger count = (MutableInteger) map.get(object);
+ MutableInteger count = map.get(object);
if (count != null) {
return count.value;
}
@@ -124,8 +125,8 @@
/**
* Determines if the bag contains the given element by checking if the
* underlying map contains the element as a key.
- *
- * @param object the object to search for
+ *
+ * @param object the object to search for
* @return true if the bag contains the given element
*/
public boolean contains(Object object) {
@@ -135,26 +136,27 @@
/**
* Determines if the bag contains the given elements.
*
- * @param coll the collection to check against
+ * @param coll the collection to check against
* @return <code>true</code> if the Bag contains all the collection
*/
- public boolean containsAll(Collection coll) {
+ @SuppressWarnings("unchecked")
+ public boolean containsAll(Collection<?> coll) {
if (coll instanceof Bag) {
- return containsAll((Bag) coll);
+ return containsAll((Bag<?>) coll);
}
- return containsAll(new HashBag(coll));
+ return containsAll(new HashBag<Object>((Collection<Object>) coll));
}
/**
- * Returns <code>true</code> if the bag contains all elements in
- * the given collection, respecting cardinality.
+ * Returns <code>true</code> if the bag contains all elements in the given
+ * collection, respecting cardinality.
*
- * @param other the bag to check against
+ * @param other the bag to check against
* @return <code>true</code> if the Bag contains all the collection
*/
- boolean containsAll(Bag other) {
+ boolean containsAll(Bag<?> other) {
boolean result = true;
- Iterator it = other.uniqueSet().iterator();
+ Iterator<?> it = other.uniqueSet().iterator();
while (it.hasNext()) {
Object current = it.next();
boolean contains = getCount(current) >= other.getCount(current);
@@ -165,22 +167,22 @@
//-----------------------------------------------------------------------
/**
- * Gets an iterator over the bag elements.
- * Elements present in the Bag more than once will be returned repeatedly.
+ * Gets an iterator over the bag elements. Elements present in the Bag more
+ * than once will be returned repeatedly.
*
* @return the iterator
*/
- public Iterator iterator() {
- return new BagIterator(this);
+ public Iterator<E> iterator() {
+ return new BagIterator<E>(this);
}
/**
* Inner class iterator for the Bag.
*/
- static class BagIterator implements Iterator {
- private AbstractMapBag parent;
- private Iterator entryIterator;
- private Map.Entry current;
+ static class BagIterator<E> implements Iterator<E> {
+ private AbstractMapBag<E> parent;
+ private Iterator<Map.Entry<E, MutableInteger>> entryIterator;
+ private Map.Entry<E, MutableInteger> current;
private int itemCount;
private final int mods;
private boolean canRemove;
@@ -188,9 +190,9 @@
/**
* Constructor.
*
- * @param parent the parent bag
+ * @param parent the parent bag
*/
- public BagIterator(AbstractMapBag parent) {
+ public BagIterator(AbstractMapBag<E> parent) {
this.parent = parent;
this.entryIterator = parent.map.entrySet().iterator();
this.current = null;
@@ -202,13 +204,13 @@
return (itemCount > 0 || entryIterator.hasNext());
}
- public Object next() {
+ public E next() {
if (parent.modCount != mods) {
throw new ConcurrentModificationException();
}
if (itemCount == 0) {
- current = (Map.Entry) entryIterator.next();
- itemCount = ((MutableInteger) current.getValue()).value;
+ current = (Map.Entry<E, MutableInteger>) entryIterator.next();
+ itemCount = current.getValue().value;
}
canRemove = true;
itemCount--;
@@ -222,7 +224,7 @@
if (canRemove == false) {
throw new IllegalStateException();
}
- MutableInteger mut = (MutableInteger) current.getValue();
+ MutableInteger mut = current.getValue();
if (mut.value > 1) {
mut.value--;
} else {
@@ -235,48 +237,49 @@
//-----------------------------------------------------------------------
/**
- * Adds a new element to the bag, incrementing its count in the underlying map.
- *
- * @param object the object to add
- * @return <code>true</code> if the object was not already in the <code>uniqueSet</code>
+ * Adds a new element to the bag, incrementing its count in the underlying
+ * map.
+ *
+ * @param object the object to add
+ * @return <code>true</code> if the object was not already in the
+ * <code>uniqueSet</code>
*/
- public boolean add(Object object) {
+ public boolean add(E object) {
return add(object, 1);
}
/**
* Adds a new element to the bag, incrementing its count in the map.
- *
- * @param object the object to search for
- * @param nCopies the number of copies to add
- * @return <code>true</code> if the object was not already in the <code>uniqueSet</code>
+ *
+ * @param object the object to search for
+ * @param nCopies the number of copies to add
+ * @return <code>true</code> if the object was not already in the
+ * <code>uniqueSet</code>
*/
- public boolean add(Object object, int nCopies) {
+ public boolean add(E object, int nCopies) {
modCount++;
if (nCopies > 0) {
- MutableInteger mut = (MutableInteger) map.get(object);
+ MutableInteger mut = map.get(object);
size += nCopies;
if (mut == null) {
map.put(object, new MutableInteger(nCopies));
return true;
- } else {
- mut.value += nCopies;
- return false;
}
- } else {
+ mut.value += nCopies;
return false;
}
+ return false;
}
/**
* Invokes {@link #add(Object)} for each element in the given collection.
- *
- * @param coll the collection to add
+ *
+ * @param coll the collection to add
* @return <code>true</code> if this call changed the bag
*/
- public boolean addAll(Collection coll) {
+ public boolean addAll(Collection<? extends E> coll) {
boolean changed = false;
- Iterator i = coll.iterator();
+ Iterator<? extends E> i = coll.iterator();
while (i.hasNext()) {
boolean added = add(i.next());
changed = changed || added;
@@ -297,11 +300,11 @@
/**
* Removes all copies of the specified object from the bag.
*
- * @param object the object to remove
+ * @param object the object to remove
* @return true if the bag changed
*/
public boolean remove(Object object) {
- MutableInteger mut = (MutableInteger) map.get(object);
+ MutableInteger mut = map.get(object);
if (mut == null) {
return false;
}
@@ -314,12 +317,12 @@
/**
* Removes a specified number of copies of an object from the bag.
*
- * @param object the object to remove
- * @param nCopies the number of copies to remove
+ * @param object the object to remove
+ * @param nCopies the number of copies to remove
* @return true if the bag changed
*/
public boolean remove(Object object, int nCopies) {
- MutableInteger mut = (MutableInteger) map.get(object);
+ MutableInteger mut = map.get(object);
if (mut == null) {
return false;
}
@@ -338,15 +341,16 @@
}
/**
- * Removes objects from the bag according to their count in the specified collection.
+ * Removes objects from the bag according to their count in the specified
+ * collection.
*
- * @param coll the collection to use
+ * @param coll the collection to use
* @return true if the bag changed
*/
- public boolean removeAll(Collection coll) {
+ public boolean removeAll(Collection<?> coll) {
boolean result = false;
if (coll != null) {
- Iterator i = coll.iterator();
+ Iterator<?> i = coll.iterator();
while (i.hasNext()) {
boolean changed = remove(i.next(), 1);
result = result || changed;
@@ -356,33 +360,34 @@
}
/**
- * Remove any members of the bag that are not in the given
- * bag, respecting cardinality.
- *
- * @param coll the collection to retain
+ * Remove any members of the bag that are not in the given bag, respecting
+ * cardinality.
+ *
+ * @param coll the collection to retain
* @return true if this call changed the collection
*/
- public boolean retainAll(Collection coll) {
+ @SuppressWarnings("unchecked")
+ public boolean retainAll(Collection<?> coll) {
if (coll instanceof Bag) {
- return retainAll((Bag) coll);
+ return retainAll((Bag<?>) coll);
}
- return retainAll(new HashBag(coll));
+ return retainAll(new HashBag<Object>((Collection<Object>) coll));
}
/**
- * Remove any members of the bag that are not in the given
- * bag, respecting cardinality.
+ * Remove any members of the bag that are not in the given bag, respecting
+ * cardinality.
* @see #retainAll(Collection)
*
- * @param other the bag to retain
+ * @param other the bag to retain
* @return <code>true</code> if this call changed the collection
*/
- boolean retainAll(Bag other) {
+ boolean retainAll(Bag<?> other) {
boolean result = false;
- Bag excess = new HashBag();
- Iterator i = uniqueSet().iterator();
+ Bag<E> excess = new HashBag<E>();
+ Iterator<E> i = uniqueSet().iterator();
while (i.hasNext()) {
- Object current = i.next();
+ E current = i.next();
int myCount = getCount(current);
int otherCount = other.getCount(current);
if (1 <= otherCount && otherCount <= myCount) {
@@ -404,15 +409,15 @@
protected static class MutableInteger {
/** The value of this mutable. */
protected int value;
-
+
/**
* Constructor.
- * @param value the initial value
+ * @param value the initial value
*/
MutableInteger(int value) {
this.value = value;
}
-
+
public boolean equals(Object obj) {
if (obj instanceof MutableInteger == false) {
return false;
@@ -424,19 +429,19 @@
return value;
}
}
-
+
//-----------------------------------------------------------------------
/**
* Returns an array of all of this bag's elements.
- *
+ *
* @return an array of all of this bag's elements
*/
public Object[] toArray() {
Object[] result = new Object[size()];
int i = 0;
- Iterator it = map.keySet().iterator();
+ Iterator<E> it = map.keySet().iterator();
while (it.hasNext()) {
- Object current = it.next();
+ E current = it.next();
for (int index = getCount(current); index > 0; index--) {
result[i++] = current;
}
@@ -446,38 +451,39 @@
/**
* Returns an array of all of this bag's elements.
- *
- * @param array the array to populate
+ *
+ * @param array the array to populate
* @return an array of all of this bag's elements
*/
- public Object[] toArray(Object[] array) {
+ @SuppressWarnings("unchecked")
+ public <T> T[] toArray(T[] array) {
int size = size();
if (array.length < size) {
- array = (Object[]) Array.newInstance(array.getClass().getComponentType(), size);
+ array = (T[]) Array.newInstance(array.getClass().getComponentType(), size);
}
int i = 0;
- Iterator it = map.keySet().iterator();
+ Iterator<E> it = map.keySet().iterator();
while (it.hasNext()) {
- Object current = it.next();
+ E current = it.next();
for (int index = getCount(current); index > 0; index--) {
- array[i++] = current;
+ array[i++] = (T) current;
}
}
- if (array.length > size) {
- array[size] = null;
+ while (i < array.length) {
+ array[i++] = null;
}
return array;
}
/**
* Returns an unmodifiable view of the underlying map's key set.
- *
+ *
* @return the set of unique elements in this bag
*/
- public Set uniqueSet() {
+ public Set<E> uniqueSet() {
if (uniqueSet == null) {
- uniqueSet = UnmodifiableSet.decorate(map.keySet());
+ uniqueSet = UnmodifiableSet.<E> decorate(map.keySet());
}
return uniqueSet;
}
@@ -485,26 +491,28 @@
//-----------------------------------------------------------------------
/**
* Write the map out using a custom routine.
- * @param out the output stream
+ * @param out the output stream
* @throws IOException
*/
protected void doWriteObject(ObjectOutputStream out) throws IOException {
out.writeInt(map.size());
- for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ for (Iterator<Map.Entry<E, MutableInteger>> it = map.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<E, MutableInteger> entry = it.next();
out.writeObject(entry.getKey());
- out.writeInt(((MutableInteger) entry.getValue()).value);
+ out.writeInt(entry.getValue().value);
}
}
/**
* Read the map in using a custom routine.
- * @param map the map to use
- * @param in the input stream
+ * @param map the map to use
+ * @param in the input stream
* @throws IOException
* @throws ClassNotFoundException
*/
- protected void doReadObject(Map map, ObjectInputStream in) throws IOException, ClassNotFoundException {
+ @SuppressWarnings("unchecked")
+ protected void doReadObject(Map map, ObjectInputStream in) throws IOException,
+ ClassNotFoundException {
this.map = map;
int entrySize = in.readInt();
for (int i = 0; i < entrySize; i++) {
@@ -514,14 +522,13 @@
size += count;
}
}
-
+
//-----------------------------------------------------------------------
/**
- * Compares this Bag to another.
- * This Bag equals another Bag if it contains the same number of occurrences of
- * the same elements.
+ * Compares this Bag to another. This Bag equals another Bag if it contains
+ * the same number of occurrences of the same elements.
*
- * @param object the Bag to compare to
+ * @param object the Bag to compare to
* @return true if equal
*/
public boolean equals(Object object) {
@@ -531,12 +538,12 @@
if (object instanceof Bag == false) {
return false;
}
- Bag other = (Bag) object;
+ Bag<?> other = (Bag<?>) object;
if (other.size() != size()) {
return false;
}
- for (Iterator it = map.keySet().iterator(); it.hasNext();) {
- Object element = it.next();
+ for (Iterator<E> it = map.keySet().iterator(); it.hasNext();) {
+ E element = it.next();
if (other.getCount(element) != getCount(element)) {
return false;
}
@@ -546,19 +553,19 @@
/**
* Gets a hash code for the Bag compatible with the definition of equals.
- * The hash code is defined as the sum total of a hash code for each element.
- * The per element hash code is defined as
- * <code>(e==null ? 0 : e.hashCode()) ^ noOccurances)</code>.
- * This hash code is compatible with the Set interface.
+ * The hash code is defined as the sum total of a hash code for each
+ * element. The per element hash code is defined as
+ * <code>(e==null ? 0 : e.hashCode()) ^ noOccurances)</code>. This hash code
+ * is compatible with the Set interface.
*
* @return the hash code of the Bag
*/
public int hashCode() {
int total = 0;
- for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- Object element = entry.getKey();
- MutableInteger count = (MutableInteger) entry.getValue();
+ for (Iterator<Map.Entry<E, MutableInteger>> it = map.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<E, MutableInteger> entry = it.next();
+ E element = entry.getKey();
+ MutableInteger count = entry.getValue();
total += (element == null ? 0 : element.hashCode()) ^ count.value;
}
return total;
@@ -575,7 +582,7 @@
}
StringBuffer buf = new StringBuffer();
buf.append('[');
- Iterator it = uniqueSet().iterator();
+ Iterator<E> it = uniqueSet().iterator();
while (it.hasNext()) {
Object current = it.next();
int count = getCount(current);
@@ -589,5 +596,5 @@
buf.append(']');
return buf.toString();
}
-
+
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java Thu Jan 29 18:48:37 2009
@@ -33,6 +33,9 @@
public abstract class AbstractSortedBagDecorator<E>
extends AbstractBagDecorator<E> implements SortedBag<E> {
+ /** Serialization version */
+ private static final long serialVersionUID = -8223473624050467718L;
+
/**
* Constructor only used in deserialization, do not use otherwise.
* @since Commons Collections 3.1
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/HashBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/HashBag.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/HashBag.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/HashBag.java Thu Jan 29 18:48:37 2009
@@ -41,8 +41,8 @@
* @author Chuck Burdick
* @author Stephen Colebourne
*/
-public class HashBag
- extends AbstractMapBag implements Bag, Serializable {
+public class HashBag<E>
+ extends AbstractMapBag<E> implements Bag<E>, Serializable {
/** Serial version lock */
private static final long serialVersionUID = -6561115435802554013L;
@@ -51,7 +51,7 @@
* Constructs an empty <code>HashBag</code>.
*/
public HashBag() {
- super(new HashMap());
+ super(new HashMap<E, MutableInteger>());
}
/**
@@ -59,7 +59,7 @@
*
* @param coll a collection to copy into this bag
*/
- public HashBag(Collection coll) {
+ public HashBag(Collection<? extends E> coll) {
this();
addAll(coll);
}
@@ -78,7 +78,7 @@
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
- super.doReadObject(new HashMap(), in);
+ super.doReadObject(new HashMap<E, MutableInteger>(), in);
}
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedBag.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedBag.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedBag.java Thu Jan 29 18:48:37 2009
@@ -115,6 +115,9 @@
* Synchronized Set for the Bag class.
*/
class SynchronizedBagSet extends SynchronizedSet<E> {
+ /** Serialization version */
+ private static final long serialVersionUID = 2990565892366827855L;
+
/**
* Constructor.
* @param set the set to decorate
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java Thu Jan 29 18:48:37 2009
@@ -48,8 +48,8 @@
* @return a new synchronized SortedBag
* @throws IllegalArgumentException if bag is null
*/
- public static <T> SortedBag<T> decorate(SortedBag<T> bag) {
- return new SynchronizedSortedBag<T>(bag);
+ public static <E> SortedBag<E> decorate(SortedBag<E> bag) {
+ return new SynchronizedSortedBag<E>(bag);
}
//-----------------------------------------------------------------------
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TransformedBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TransformedBag.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TransformedBag.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TransformedBag.java Thu Jan 29 18:48:37 2009
@@ -38,8 +38,8 @@
*
* @author Stephen Colebourne
*/
-public class TransformedBag
- extends TransformedCollection implements Bag {
+public class TransformedBag<E>
+ extends TransformedCollection<E> implements Bag<E> {
/** Serialization version */
private static final long serialVersionUID = 5421170911299074185L;
@@ -55,8 +55,8 @@
* @return a new transformed Bag
* @throws IllegalArgumentException if bag or transformer is null
*/
- public static Bag decorate(Bag bag, Transformer transformer) {
- return new TransformedBag(bag, transformer);
+ public static <E> Bag<E> decorate(Bag<E> bag, Transformer<? super E, ? extends E> transformer) {
+ return new TransformedBag<E>(bag, transformer);
}
//-----------------------------------------------------------------------
@@ -70,7 +70,7 @@
* @param transformer the transformer to use for conversion, must not be null
* @throws IllegalArgumentException if bag or transformer is null
*/
- protected TransformedBag(Bag bag, Transformer transformer) {
+ protected TransformedBag(Bag<E> bag, Transformer<? super E, ? extends E> transformer) {
super(bag, transformer);
}
@@ -79,8 +79,8 @@
*
* @return the decorated bag
*/
- protected Bag getBag() {
- return (Bag) collection;
+ protected Bag<E> getBag() {
+ return (Bag<E>) collection;
}
//-----------------------------------------------------------------------
@@ -93,14 +93,13 @@
}
//-----------------------------------------------------------------------
- public boolean add(Object object, int nCopies) {
- object = transform(object);
- return getBag().add(object, nCopies);
+ public boolean add(E object, int nCopies) {
+ return getBag().add(transform(object), nCopies);
}
- public Set uniqueSet() {
- Set set = getBag().uniqueSet();
- return TransformedSet.decorate(set, transformer);
+ public Set<E> uniqueSet() {
+ Set<E> set = getBag().uniqueSet();
+ return TransformedSet.<E>decorate(set, transformer);
}
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TransformedSortedBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TransformedSortedBag.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TransformedSortedBag.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TransformedSortedBag.java Thu Jan 29 18:48:37 2009
@@ -36,8 +36,8 @@
*
* @author Stephen Colebourne
*/
-public class TransformedSortedBag
- extends TransformedBag implements SortedBag {
+public class TransformedSortedBag<E>
+ extends TransformedBag<E> implements SortedBag<E> {
/** Serialization version */
private static final long serialVersionUID = -251737742649401930L;
@@ -53,8 +53,8 @@
* @return a new transformed SortedBag
* @throws IllegalArgumentException if bag or transformer is null
*/
- public static SortedBag decorate(SortedBag bag, Transformer transformer) {
- return new TransformedSortedBag(bag, transformer);
+ public static <E> SortedBag<E> decorate(SortedBag<E> bag, Transformer<? super E, ? extends E> transformer) {
+ return new TransformedSortedBag<E>(bag, transformer);
}
//-----------------------------------------------------------------------
@@ -68,7 +68,7 @@
* @param transformer the transformer to use for conversion, must not be null
* @throws IllegalArgumentException if bag or transformer is null
*/
- protected TransformedSortedBag(SortedBag bag, Transformer transformer) {
+ protected TransformedSortedBag(SortedBag<E> bag, Transformer<? super E, ? extends E> transformer) {
super(bag, transformer);
}
@@ -77,20 +77,20 @@
*
* @return the decorated bag
*/
- protected SortedBag getSortedBag() {
- return (SortedBag) collection;
+ protected SortedBag<E> getSortedBag() {
+ return (SortedBag<E>) collection;
}
//-----------------------------------------------------------------------
- public Object first() {
+ public E first() {
return getSortedBag().first();
}
- public Object last() {
+ public E last() {
return getSortedBag().last();
}
- public Comparator comparator() {
+ public Comparator<? super E> comparator() {
return getSortedBag().comparator();
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TreeBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TreeBag.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TreeBag.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/TreeBag.java Thu Jan 29 18:48:37 2009
@@ -34,63 +34,72 @@
* Order will be maintained among the bag members and can be viewed through the
* iterator.
* <p>
- * A <code>Bag</code> stores each object in the collection together with a
- * count of occurrences. Extra methods on the interface allow multiple copies
- * of an object to be added or removed at once. It is important to read the
- * interface javadoc carefully as several methods violate the
- * <code>Collection</code> interface specification.
- *
+ * A <code>Bag</code> stores each object in the collection together with a count
+ * of occurrences. Extra methods on the interface allow multiple copies of an
+ * object to be added or removed at once. It is important to read the interface
+ * javadoc carefully as several methods violate the <code>Collection</code>
+ * interface specification.
+ *
* @since Commons Collections 3.0 (previously in main package v2.0)
- * @version $Revision$ $Date$
+ * @version $Revision$ $Date: 2006-10-27 19:52:37 -0500 (Fri, 27 Oct
+ * 2006) $
*
* @author Chuck Burdick
* @author Stephen Colebourne
*/
-public class TreeBag
- extends AbstractMapBag implements SortedBag, Serializable {
+public class TreeBag<E> extends AbstractMapBag<E> implements SortedBag<E>, Serializable {
/** Serial version lock */
private static final long serialVersionUID = -7740146511091606676L;
-
+
/**
* Constructs an empty <code>TreeBag</code>.
*/
public TreeBag() {
- super(new TreeMap());
+ super(new TreeMap<E, MutableInteger>());
}
/**
- * Constructs an empty bag that maintains order on its unique
- * representative members according to the given {@link Comparator}.
+ * Constructs an empty bag that maintains order on its unique representative
+ * members according to the given {@link Comparator}.
*
- * @param comparator the comparator to use
+ * @param comparator the comparator to use
*/
- public TreeBag(Comparator comparator) {
- super(new TreeMap(comparator));
+ public TreeBag(Comparator<? super E> comparator) {
+ super(new TreeMap<E, MutableInteger>(comparator));
}
/**
* Constructs a <code>TreeBag</code> containing all the members of the
* specified collection.
*
- * @param coll the collection to copy into the bag
+ * @param coll the collection to copy into the bag
*/
- public TreeBag(Collection coll) {
+ public TreeBag(Collection<? extends E> coll) {
this();
addAll(coll);
}
//-----------------------------------------------------------------------
- public Object first() {
- return ((SortedMap) getMap()).firstKey();
+ public E first() {
+ return getMap().firstKey();
}
- public Object last() {
- return ((SortedMap) getMap()).lastKey();
+ public E last() {
+ return getMap().lastKey();
}
- public Comparator comparator() {
- return ((SortedMap) getMap()).comparator();
+ public Comparator<? super E> comparator() {
+ return getMap().comparator();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected SortedMap<E, org.apache.commons.collections.bag.AbstractMapBag.MutableInteger> getMap() {
+ return (SortedMap<E, org.apache.commons.collections.bag.AbstractMapBag.MutableInteger>) super
+ .getMap();
}
//-----------------------------------------------------------------------
@@ -106,10 +115,11 @@
/**
* Read the bag in using a custom routine.
*/
+ @SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
Comparator comp = (Comparator) in.readObject();
super.doReadObject(new TreeMap(comp), in);
}
-
+
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableBag.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableBag.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableBag.java Thu Jan 29 18:48:37 2009
@@ -39,8 +39,8 @@
*
* @author Stephen Colebourne
*/
-public final class UnmodifiableBag
- extends AbstractBagDecorator implements Unmodifiable, Serializable {
+public final class UnmodifiableBag<E>
+ extends AbstractBagDecorator<E> implements Unmodifiable, Serializable {
/** Serialization version */
private static final long serialVersionUID = -1873799975157099624L;
@@ -54,11 +54,11 @@
* @return an unmodifiable Bag
* @throws IllegalArgumentException if bag is null
*/
- public static Bag decorate(Bag bag) {
+ public static <E> Bag<E> decorate(Bag<E> bag) {
if (bag instanceof Unmodifiable) {
return bag;
}
- return new UnmodifiableBag(bag);
+ return new UnmodifiableBag<E>(bag);
}
//-----------------------------------------------------------------------
@@ -68,7 +68,7 @@
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null
*/
- private UnmodifiableBag(Bag bag) {
+ private UnmodifiableBag(Bag<E> bag) {
super(bag);
}
@@ -91,21 +91,22 @@
* @throws IOException
* @throws ClassNotFoundException
*/
+ @SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
- collection = (Collection) in.readObject();
+ collection = (Collection<E>) in.readObject();
}
//-----------------------------------------------------------------------
- public Iterator iterator() {
- return UnmodifiableIterator.decorate(decorated().iterator());
+ public Iterator<E> iterator() {
+ return UnmodifiableIterator.<E>decorate(decorated().iterator());
}
- public boolean add(Object object) {
+ public boolean add(E object) {
throw new UnsupportedOperationException();
}
- public boolean addAll(Collection coll) {
+ public boolean addAll(Collection<? extends E> coll) {
throw new UnsupportedOperationException();
}
@@ -117,16 +118,16 @@
throw new UnsupportedOperationException();
}
- public boolean removeAll(Collection coll) {
+ public boolean removeAll(Collection<?> coll) {
throw new UnsupportedOperationException();
}
- public boolean retainAll(Collection coll) {
+ public boolean retainAll(Collection<?> coll) {
throw new UnsupportedOperationException();
}
//-----------------------------------------------------------------------
- public boolean add(Object object, int count) {
+ public boolean add(E object, int count) {
throw new UnsupportedOperationException();
}
@@ -134,9 +135,9 @@
throw new UnsupportedOperationException();
}
- public Set uniqueSet() {
- Set set = decorated().uniqueSet();
- return UnmodifiableSet.decorate(set);
+ public Set<E> uniqueSet() {
+ Set<E> set = decorated().uniqueSet();
+ return UnmodifiableSet.<E>decorate(set);
}
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java Thu Jan 29 18:48:37 2009
@@ -54,11 +54,11 @@
* @return an unmodifiable SortedBag
* @throws IllegalArgumentException if bag is null
*/
- public static <T> SortedBag<T> decorate(SortedBag<T> bag) {
+ public static <E> SortedBag<E> decorate(SortedBag<E> bag) {
if (bag instanceof Unmodifiable) {
return bag;
}
- return new UnmodifiableSortedBag<T>(bag);
+ return new UnmodifiableSortedBag<E>(bag);
}
//-----------------------------------------------------------------------
@@ -91,13 +91,14 @@
* @throws IOException
* @throws ClassNotFoundException
*/
+ @SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
collection = (Collection<E>) in.readObject();
}
//-----------------------------------------------------------------------
- public Iterator iterator() {
+ public Iterator<E> iterator() {
return UnmodifiableIterator.decorate(decorated().iterator());
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractBidiMapDecorator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractBidiMapDecorator.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractBidiMapDecorator.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractBidiMapDecorator.java Thu Jan 29 18:48:37 2009
@@ -37,9 +37,8 @@
*
* @author Stephen Colebourne
*/
-public abstract class AbstractBidiMapDecorator
- extends AbstractMapDecorator
- implements BidiMap {
+public abstract class AbstractBidiMapDecorator<K, V> extends AbstractMapDecorator<K, V> implements
+ BidiMap<K, V> {
/**
* Constructor that wraps (not copies).
@@ -47,7 +46,7 @@
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
- protected AbstractBidiMapDecorator(BidiMap map) {
+ protected AbstractBidiMapDecorator(BidiMap<K, V> map) {
super(map);
}
@@ -55,35 +54,25 @@
* Gets the map being decorated.
*
* @return the decorated map
- * @deprecated use decorated()
*/
- protected BidiMap getBidiMap() {
- return decorated();
- }
-
- /**
- * Gets the map being decorated.
- *
- * @return the decorated map
- */
- protected BidiMap decorated() {
- return (BidiMap) super.decorated();
+ protected BidiMap<K, V> decorated() {
+ return (BidiMap<K, V>) super.decorated();
}
//-----------------------------------------------------------------------
- public MapIterator mapIterator() {
+ public MapIterator<K, V> mapIterator() {
return decorated().mapIterator();
}
- public Object getKey(Object value) {
+ public K getKey(Object value) {
return decorated().getKey(value);
}
- public Object removeValue(Object value) {
+ public K removeValue(Object value) {
return decorated().removeValue(value);
}
- public BidiMap inverseBidiMap() {
+ public BidiMap<V, K> inverseBidiMap() {
return decorated().inverseBidiMap();
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java Thu Jan 29 18:48:37 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,38 +33,46 @@
* <p>
* An implementation can be written simply by implementing the
* <code>createMap</code> method.
- *
+ *
* @see DualHashBidiMap
* @see DualTreeBidiMap
* @since Commons Collections 3.0
* @version $Id$
- *
+ *
* @author Matthew Hawthorne
* @author Stephen Colebourne
*/
-public abstract class AbstractDualBidiMap implements BidiMap {
+public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
/**
- * Delegate map array. The first map contains standard entries, and the
- * second contains inverses.
+ * Normal delegate map.
*/
- protected transient final Map[] maps = new Map[2];
+ protected transient Map<K, V> normalMap;
+
+ /**
+ * Reverse delegate map.
+ */
+ protected transient Map<V, K> reverseMap;
+
/**
* Inverse view of this map.
*/
- protected transient BidiMap inverseBidiMap = null;
+ protected transient BidiMap<V, K> inverseBidiMap = null;
+
/**
* View of the keys.
*/
- protected transient Set keySet = null;
+ protected transient Set<K> keySet = null;
+
/**
* View of the values.
*/
- protected transient Collection values = null;
+ protected transient Collection<V> values = null;
+
/**
* View of the entries.
*/
- protected transient Set entrySet = null;
+ protected transient Set<Map.Entry<K, V>> entrySet = null;
/**
* Creates an empty map, initialised by <code>createMap</code>.
@@ -86,18 +94,18 @@
* Neither map is validated, so nulls may be passed in.
* If you choose to do this then the subclass constructor must populate
* the <code>maps[]</code> instance variable itself.
- *
+ *
* @param normalMap the normal direction map
* @param reverseMap the reverse direction map
* @since Commons Collections 3.1
*/
- protected AbstractDualBidiMap(Map normalMap, Map reverseMap) {
+ protected AbstractDualBidiMap(Map<K, V> normalMap, Map<V, K> reverseMap) {
super();
- maps[0] = normalMap;
- maps[1] = reverseMap;
+ this.normalMap = normalMap;
+ this.reverseMap = reverseMap;
}
- /**
+ /**
* Constructs a map that decorates the specified maps,
* used by the subclass <code>createBidiMap</code> implementation.
*
@@ -105,90 +113,89 @@
* @param reverseMap the reverse direction map
* @param inverseBidiMap the inverse BidiMap
*/
- protected AbstractDualBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
+ protected AbstractDualBidiMap(Map<K, V> normalMap, Map<V, K> reverseMap, BidiMap<V, K> inverseBidiMap) {
super();
- maps[0] = normalMap;
- maps[1] = reverseMap;
+ this.normalMap = normalMap;
+ this.reverseMap = reverseMap;
this.inverseBidiMap = inverseBidiMap;
}
/**
* Creates a new instance of the subclass.
- *
+ *
* @param normalMap the normal direction map
* @param reverseMap the reverse direction map
* @param inverseMap this map, which is the inverse in the new map
* @return the inverse map
*/
- protected abstract BidiMap createBidiMap(Map normalMap, Map reverseMap, BidiMap inverseMap);
+ protected abstract BidiMap<V, K> createBidiMap(Map<V, K> normalMap, Map<K, V> reverseMap, BidiMap<K, V> inverseMap);
// Map delegation
//-----------------------------------------------------------------------
- public Object get(Object key) {
- return maps[0].get(key);
+ public V get(Object key) {
+ return normalMap.get(key);
}
public int size() {
- return maps[0].size();
+ return normalMap.size();
}
public boolean isEmpty() {
- return maps[0].isEmpty();
+ return normalMap.isEmpty();
}
public boolean containsKey(Object key) {
- return maps[0].containsKey(key);
+ return normalMap.containsKey(key);
}
public boolean equals(Object obj) {
- return maps[0].equals(obj);
+ return normalMap.equals(obj);
}
public int hashCode() {
- return maps[0].hashCode();
+ return normalMap.hashCode();
}
public String toString() {
- return maps[0].toString();
+ return normalMap.toString();
}
// BidiMap changes
//-----------------------------------------------------------------------
- public Object put(Object key, Object value) {
- if (maps[0].containsKey(key)) {
- maps[1].remove(maps[0].get(key));
+ public V put(K key, V value) {
+ if (normalMap.containsKey(key)) {
+ reverseMap.remove(normalMap.get(key));
}
- if (maps[1].containsKey(value)) {
- maps[0].remove(maps[1].get(value));
+ if (reverseMap.containsKey(value)) {
+ normalMap.remove(reverseMap.get(value));
}
- final Object obj = maps[0].put(key, value);
- maps[1].put(value, key);
+ final V obj = normalMap.put(key, value);
+ reverseMap.put(value, key);
return obj;
}
-
- public void putAll(Map map) {
- for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+
+ public void putAll(Map<? extends K, ? extends V> map) {
+ for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
}
- public Object remove(Object key) {
- Object value = null;
- if (maps[0].containsKey(key)) {
- value = maps[0].remove(key);
- maps[1].remove(value);
+ public V remove(Object key) {
+ V value = null;
+ if (normalMap.containsKey(key)) {
+ value = normalMap.remove(key);
+ reverseMap.remove(value);
}
return value;
}
public void clear() {
- maps[0].clear();
- maps[1].clear();
+ normalMap.clear();
+ reverseMap.clear();
}
public boolean containsValue(Object value) {
- return maps[1].containsKey(value);
+ return reverseMap.containsKey(value);
}
// BidiMap
@@ -201,45 +208,45 @@
* The setValue() methods only allow a new value to be set.
* If the value being set is already in the map, an IllegalArgumentException
* is thrown (as setValue cannot change the size of the map).
- *
+ *
* @return a map iterator
*/
- public MapIterator mapIterator() {
- return new BidiMapIterator(this);
+ public MapIterator<K, V> mapIterator() {
+ return new BidiMapIterator<K, V>(this);
}
-
- public Object getKey(Object value) {
- return maps[1].get(value);
+
+ public K getKey(Object value) {
+ return reverseMap.get(value);
}
- public Object removeValue(Object value) {
- Object key = null;
- if (maps[1].containsKey(value)) {
- key = maps[1].remove(value);
- maps[0].remove(key);
+ public K removeValue(Object value) {
+ K key = null;
+ if (reverseMap.containsKey(value)) {
+ key = reverseMap.remove(value);
+ normalMap.remove(key);
}
return key;
}
- public BidiMap inverseBidiMap() {
+ public BidiMap<V, K> inverseBidiMap() {
if (inverseBidiMap == null) {
- inverseBidiMap = createBidiMap(maps[1], maps[0], this);
+ inverseBidiMap = createBidiMap(reverseMap, normalMap, this);
}
return inverseBidiMap;
}
-
+
// Map views
//-----------------------------------------------------------------------
/**
* Gets a keySet view of the map.
* Changes made on the view are reflected in the map.
* The set supports remove and clear but not add.
- *
+ *
* @return the keySet view
*/
- public Set keySet() {
+ public Set<K> keySet() {
if (keySet == null) {
- keySet = new KeySet(this);
+ keySet = new KeySet<K>(this);
}
return keySet;
}
@@ -247,24 +254,24 @@
/**
* Creates a key set iterator.
* Subclasses can override this to return iterators with different properties.
- *
+ *
* @param iterator the iterator to decorate
* @return the keySet iterator
*/
- protected Iterator createKeySetIterator(Iterator iterator) {
- return new KeySetIterator(iterator, this);
+ protected Iterator<K> createKeySetIterator(Iterator<K> iterator) {
+ return new KeySetIterator<K>(iterator, this);
}
/**
* Gets a values view of the map.
* Changes made on the view are reflected in the map.
* The set supports remove and clear but not add.
- *
+ *
* @return the values view
*/
- public Collection values() {
+ public Collection<V> values() {
if (values == null) {
- values = new Values(this);
+ values = new Values<V>(this);
}
return values;
}
@@ -272,12 +279,12 @@
/**
* Creates a values iterator.
* Subclasses can override this to return iterators with different properties.
- *
+ *
* @param iterator the iterator to decorate
* @return the values iterator
*/
- protected Iterator createValuesIterator(Iterator iterator) {
- return new ValuesIterator(iterator, this);
+ protected Iterator<V> createValuesIterator(Iterator<V> iterator) {
+ return new ValuesIterator<V>(iterator, this);
}
/**
@@ -288,53 +295,54 @@
* The Map Entry setValue() method only allow a new value to be set.
* If the value being set is already in the map, an IllegalArgumentException
* is thrown (as setValue cannot change the size of the map).
- *
+ *
* @return the entrySet view
*/
- public Set entrySet() {
+ public Set<Map.Entry<K, V>> entrySet() {
if (entrySet == null) {
- entrySet = new EntrySet(this);
+ entrySet = new EntrySet<K, V>(this);
}
return entrySet;
}
-
+
/**
* Creates an entry set iterator.
* Subclasses can override this to return iterators with different properties.
- *
+ *
* @param iterator the iterator to decorate
* @return the entrySet iterator
*/
- protected Iterator createEntrySetIterator(Iterator iterator) {
- return new EntrySetIterator(iterator, this);
+ protected Iterator<Map.Entry<K, V>> createEntrySetIterator(Iterator<Map.Entry<K, V>> iterator) {
+ return new EntrySetIterator<K, V>(iterator, this);
}
//-----------------------------------------------------------------------
/**
* Inner class View.
*/
- protected static abstract class View extends AbstractCollectionDecorator {
-
+ @SuppressWarnings("serial")
+ protected static abstract class View<K, V, E> extends AbstractCollectionDecorator<E> {
+
/** The parent map */
- protected final AbstractDualBidiMap parent;
-
+ protected final AbstractDualBidiMap<K, V> parent;
+
/**
* Constructs a new view of the BidiMap.
- *
+ *
* @param coll the collection view being decorated
* @param parent the parent BidiMap
*/
- protected View(Collection coll, AbstractDualBidiMap parent) {
+ protected View(Collection<E> coll, AbstractDualBidiMap<K, V> parent) {
super(coll);
this.parent = parent;
}
- public boolean removeAll(Collection coll) {
+ public boolean removeAll(Collection<?> coll) {
if (parent.isEmpty() || coll.isEmpty()) {
return false;
}
boolean modified = false;
- Iterator it = iterator();
+ Iterator<E> it = iterator();
while (it.hasNext()) {
if (coll.contains(it.next())) {
it.remove();
@@ -344,7 +352,7 @@
return modified;
}
- public boolean retainAll(Collection coll) {
+ public boolean retainAll(Collection<?> coll) {
if (parent.isEmpty()) {
return false;
}
@@ -353,7 +361,7 @@
return true;
}
boolean modified = false;
- Iterator it = iterator();
+ Iterator<E> it = iterator();
while (it.hasNext()) {
if (coll.contains(it.next()) == false) {
it.remove();
@@ -362,80 +370,86 @@
}
return modified;
}
-
+
public void clear() {
parent.clear();
}
}
-
+
//-----------------------------------------------------------------------
/**
* Inner class KeySet.
*/
- protected static class KeySet extends View implements Set {
-
+ protected static class KeySet<K> extends View<K, Object, K> implements Set<K> {
+
+ /** Serialization version */
+ private static final long serialVersionUID = -7107935777385040694L;
+
/**
* Constructs a new view of the BidiMap.
- *
+ *
* @param parent the parent BidiMap
*/
- protected KeySet(AbstractDualBidiMap parent) {
- super(parent.maps[0].keySet(), parent);
+ @SuppressWarnings("unchecked")
+ protected KeySet(AbstractDualBidiMap<K, ?> parent) {
+ super(parent.normalMap.keySet(), (AbstractDualBidiMap<K, Object>) parent);
}
- public Iterator iterator() {
+ public Iterator<K> iterator() {
return parent.createKeySetIterator(super.iterator());
}
-
+
public boolean contains(Object key) {
- return parent.maps[0].containsKey(key);
+ return parent.normalMap.containsKey(key);
}
public boolean remove(Object key) {
- if (parent.maps[0].containsKey(key)) {
- Object value = parent.maps[0].remove(key);
- parent.maps[1].remove(value);
+ if (parent.normalMap.containsKey(key)) {
+ Object value = parent.normalMap.remove(key);
+ parent.reverseMap.remove(value);
return true;
}
return false;
}
}
-
+
/**
* Inner class KeySetIterator.
*/
- protected static class KeySetIterator extends AbstractIteratorDecorator {
-
+ protected static class KeySetIterator<K> extends AbstractIteratorDecorator<K> {
+
/** The parent map */
- protected final AbstractDualBidiMap parent;
+ protected final AbstractDualBidiMap<K, ?> parent;
+
/** The last returned key */
- protected Object lastKey = null;
+ protected K lastKey = null;
+
/** Whether remove is allowed at present */
protected boolean canRemove = false;
-
+
/**
* Constructor.
* @param iterator the iterator to decorate
* @param parent the parent map
*/
- protected KeySetIterator(Iterator iterator, AbstractDualBidiMap parent) {
+ protected KeySetIterator(Iterator<K> iterator, AbstractDualBidiMap<K, ?> parent) {
super(iterator);
this.parent = parent;
}
-
- public Object next() {
+
+ public K next() {
lastKey = super.next();
canRemove = true;
return lastKey;
}
-
+
public void remove() {
if (canRemove == false) {
throw new IllegalStateException("Iterator remove() can only be called once after next()");
}
- Object value = parent.maps[0].get(lastKey);
+ Object value = parent.normalMap.get(lastKey);
super.remove();
- parent.maps[1].remove(value);
+ parent.reverseMap.remove(value);
lastKey = null;
canRemove = false;
}
@@ -445,69 +459,76 @@
/**
* Inner class Values.
*/
- protected static class Values extends View implements Set {
-
+ protected static class Values<V> extends View<Object, V, V> implements Set<V> {
+
+ /** Serialization version */
+ private static final long serialVersionUID = 4023777119829639864L;
+
/**
* Constructs a new view of the BidiMap.
- *
+ *
* @param parent the parent BidiMap
*/
- protected Values(AbstractDualBidiMap parent) {
- super(parent.maps[0].values(), parent);
+ @SuppressWarnings("unchecked")
+ protected Values(AbstractDualBidiMap<?, V> parent) {
+ super(parent.normalMap.values(), (AbstractDualBidiMap<Object, V>) parent);
}
- public Iterator iterator() {
+ public Iterator<V> iterator() {
return parent.createValuesIterator(super.iterator());
}
-
+
public boolean contains(Object value) {
- return parent.maps[1].containsKey(value);
+ return parent.reverseMap.containsKey(value);
}
public boolean remove(Object value) {
- if (parent.maps[1].containsKey(value)) {
- Object key = parent.maps[1].remove(value);
- parent.maps[0].remove(key);
+ if (parent.reverseMap.containsKey(value)) {
+ Object key = parent.reverseMap.remove(value);
+ parent.normalMap.remove(key);
return true;
}
return false;
}
}
-
+
/**
* Inner class ValuesIterator.
*/
- protected static class ValuesIterator extends AbstractIteratorDecorator {
-
+ protected static class ValuesIterator<V> extends AbstractIteratorDecorator<V> {
+
/** The parent map */
- protected final AbstractDualBidiMap parent;
+ protected final AbstractDualBidiMap<Object, V> parent;
+
/** The last returned value */
- protected Object lastValue = null;
+ protected V lastValue = null;
+
/** Whether remove is allowed at present */
protected boolean canRemove = false;
-
+
/**
* Constructor.
* @param iterator the iterator to decorate
* @param parent the parent map
*/
- protected ValuesIterator(Iterator iterator, AbstractDualBidiMap parent) {
+ @SuppressWarnings("unchecked")
+ protected ValuesIterator(Iterator<V> iterator, AbstractDualBidiMap<?, V> parent) {
super(iterator);
- this.parent = parent;
+ this.parent = (AbstractDualBidiMap<Object, V>) parent;
}
-
- public Object next() {
+
+ public V next() {
lastValue = super.next();
canRemove = true;
return lastValue;
}
-
+
public void remove() {
if (canRemove == false) {
throw new IllegalStateException("Iterator remove() can only be called once after next()");
}
super.remove(); // removes from maps[0]
- parent.maps[1].remove(lastValue);
+ parent.reverseMap.remove(lastValue);
lastValue = null;
canRemove = false;
}
@@ -517,67 +538,72 @@
/**
* Inner class EntrySet.
*/
- protected static class EntrySet extends View implements Set {
-
+ protected static class EntrySet<K, V> extends View<K, V, Map.Entry<K, V>> implements Set<Map.Entry<K, V>> {
+
+ /** Serialization version */
+ private static final long serialVersionUID = 4040410962603292348L;
+
/**
* Constructs a new view of the BidiMap.
- *
+ *
* @param parent the parent BidiMap
*/
- protected EntrySet(AbstractDualBidiMap parent) {
- super(parent.maps[0].entrySet(), parent);
+ protected EntrySet(AbstractDualBidiMap<K, V> parent) {
+ super(parent.normalMap.entrySet(), parent);
}
- public Iterator iterator() {
+ public Iterator<Map.Entry<K, V>> iterator() {
return parent.createEntrySetIterator(super.iterator());
}
-
+
public boolean remove(Object obj) {
if (obj instanceof Map.Entry == false) {
return false;
}
- Map.Entry entry = (Map.Entry) obj;
+ Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
Object key = entry.getKey();
if (parent.containsKey(key)) {
- Object value = parent.maps[0].get(key);
+ V value = parent.normalMap.get(key);
if (value == null ? entry.getValue() == null : value.equals(entry.getValue())) {
- parent.maps[0].remove(key);
- parent.maps[1].remove(value);
+ parent.normalMap.remove(key);
+ parent.reverseMap.remove(value);
return true;
}
}
return false;
}
}
-
+
/**
* Inner class EntrySetIterator.
*/
- protected static class EntrySetIterator extends AbstractIteratorDecorator {
-
+ protected static class EntrySetIterator<K, V> extends AbstractIteratorDecorator<Map.Entry<K, V>> {
+
/** The parent map */
- protected final AbstractDualBidiMap parent;
+ protected final AbstractDualBidiMap<K, V> parent;
+
/** The last returned entry */
- protected Map.Entry last = null;
+ protected Map.Entry<K, V> last = null;
+
/** Whether remove is allowed at present */
protected boolean canRemove = false;
-
+
/**
* Constructor.
* @param iterator the iterator to decorate
* @param parent the parent map
*/
- protected EntrySetIterator(Iterator iterator, AbstractDualBidiMap parent) {
+ protected EntrySetIterator(Iterator<Map.Entry<K, V>> iterator, AbstractDualBidiMap<K, V> parent) {
super(iterator);
this.parent = parent;
}
-
- public Object next() {
- last = new MapEntry((Map.Entry) super.next(), parent);
+
+ public Map.Entry<K, V> next() {
+ last = new MapEntry<K, V>(super.next(), parent);
canRemove = true;
return last;
}
-
+
public void remove() {
if (canRemove == false) {
throw new IllegalStateException("Iterator remove() can only be called once after next()");
@@ -585,7 +611,7 @@
// store value as remove may change the entry in the decorator (eg.TreeMap)
Object value = last.getValue();
super.remove();
- parent.maps[1].remove(value);
+ parent.reverseMap.remove(value);
last = null;
canRemove = false;
}
@@ -594,117 +620,119 @@
/**
* Inner class MapEntry.
*/
- protected static class MapEntry extends AbstractMapEntryDecorator {
+ protected static class MapEntry<K, V> extends AbstractMapEntryDecorator<K, V> {
+
+ /** The parent map */
+ protected final AbstractDualBidiMap<K, V> parent;
- /** The parent map */
- protected final AbstractDualBidiMap parent;
-
/**
* Constructor.
* @param entry the entry to decorate
* @param parent the parent map
*/
- protected MapEntry(Map.Entry entry, AbstractDualBidiMap parent) {
+ protected MapEntry(Map.Entry<K, V> entry, AbstractDualBidiMap<K, V> parent) {
super(entry);
this.parent = parent;
}
-
- public Object setValue(Object value) {
- Object key = MapEntry.this.getKey();
- if (parent.maps[1].containsKey(value) &&
- parent.maps[1].get(value) != key) {
+
+ public V setValue(V value) {
+ K key = MapEntry.this.getKey();
+ if (parent.reverseMap.containsKey(value) &&
+ parent.reverseMap.get(value) != key) {
throw new IllegalArgumentException("Cannot use setValue() when the object being set is already in the map");
}
parent.put(key, value);
- final Object oldValue = super.setValue(value);
+ final V oldValue = super.setValue(value);
return oldValue;
}
}
-
+
/**
* Inner class MapIterator.
*/
- protected static class BidiMapIterator implements MapIterator, ResettableIterator {
-
+ protected static class BidiMapIterator<K, V> implements MapIterator<K, V>, ResettableIterator<K> {
+
/** The parent map */
- protected final AbstractDualBidiMap parent;
+ protected final AbstractDualBidiMap<K, V> parent;
+
/** The iterator being wrapped */
- protected Iterator iterator;
+ protected Iterator<Map.Entry<K, V>> iterator;
+
/** The last returned entry */
- protected Map.Entry last = null;
+ protected Map.Entry<K, V> last = null;
+
/** Whether remove is allowed at present */
protected boolean canRemove = false;
-
+
/**
* Constructor.
* @param parent the parent map
*/
- protected BidiMapIterator(AbstractDualBidiMap parent) {
+ protected BidiMapIterator(AbstractDualBidiMap<K, V> parent) {
super();
this.parent = parent;
- this.iterator = parent.maps[0].entrySet().iterator();
+ this.iterator = parent.normalMap.entrySet().iterator();
}
-
+
public boolean hasNext() {
return iterator.hasNext();
}
-
- public Object next() {
- last = (Map.Entry) iterator.next();
+
+ public K next() {
+ last = iterator.next();
canRemove = true;
return last.getKey();
}
-
+
public void remove() {
if (canRemove == false) {
throw new IllegalStateException("Iterator remove() can only be called once after next()");
}
// store value as remove may change the entry in the decorator (eg.TreeMap)
- Object value = last.getValue();
+ V value = last.getValue();
iterator.remove();
- parent.maps[1].remove(value);
+ parent.reverseMap.remove(value);
last = null;
canRemove = false;
}
-
- public Object getKey() {
+
+ public K getKey() {
if (last == null) {
throw new IllegalStateException("Iterator getKey() can only be called after next() and before remove()");
}
return last.getKey();
}
- public Object getValue() {
+ public V getValue() {
if (last == null) {
throw new IllegalStateException("Iterator getValue() can only be called after next() and before remove()");
}
return last.getValue();
}
-
- public Object setValue(Object value) {
+
+ public V setValue(V value) {
if (last == null) {
throw new IllegalStateException("Iterator setValue() can only be called after next() and before remove()");
}
- if (parent.maps[1].containsKey(value) &&
- parent.maps[1].get(value) != last.getKey()) {
+ if (parent.reverseMap.containsKey(value) &&
+ parent.reverseMap.get(value) != last.getKey()) {
throw new IllegalArgumentException("Cannot use setValue() when the object being set is already in the map");
}
return parent.put(last.getKey(), value);
}
-
+
public void reset() {
- iterator = parent.maps[0].entrySet().iterator();
+ iterator = parent.normalMap.entrySet().iterator();
last = null;
canRemove = false;
}
-
+
public String toString() {
if (last != null) {
return "MapIterator[" + getKey() + "=" + getValue() + "]";
- } else {
- return "MapIterator[]";
}
+ return "MapIterator[]";
}
}
-
+
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractOrderedBidiMapDecorator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractOrderedBidiMapDecorator.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractOrderedBidiMapDecorator.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractOrderedBidiMapDecorator.java Thu Jan 29 18:48:37 2009
@@ -36,9 +36,9 @@
*
* @author Stephen Colebourne
*/
-public abstract class AbstractOrderedBidiMapDecorator
- extends AbstractBidiMapDecorator
- implements OrderedBidiMap {
+public abstract class AbstractOrderedBidiMapDecorator<K, V>
+ extends AbstractBidiMapDecorator<K, V>
+ implements OrderedBidiMap<K, V> {
/**
* Constructor that wraps (not copies).
@@ -46,7 +46,7 @@
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
- protected AbstractOrderedBidiMapDecorator(OrderedBidiMap map) {
+ protected AbstractOrderedBidiMapDecorator(OrderedBidiMap<K, V> map) {
super(map);
}
@@ -54,44 +54,35 @@
* Gets the map being decorated.
*
* @return the decorated map
- * @deprecated use decorated()
*/
- protected OrderedBidiMap getOrderedBidiMap() {
- return decorated();
- }
-
- /**
- * Gets the map being decorated.
- *
- * @return the decorated map
- */
- protected OrderedBidiMap decorated() {
- return (OrderedBidiMap) super.decorated();
+ protected OrderedBidiMap<K, V> decorated() {
+ return (OrderedBidiMap<K, V>) super.decorated();
}
//-----------------------------------------------------------------------
- public OrderedMapIterator orderedMapIterator() {
- return decorated().orderedMapIterator();
+ public OrderedMapIterator<K, V> mapIterator() {
+ return decorated().mapIterator();
}
- public Object firstKey() {
+ public K firstKey() {
return decorated().firstKey();
}
- public Object lastKey() {
+ public K lastKey() {
return decorated().lastKey();
}
- public Object nextKey(Object key) {
+ public K nextKey(K key) {
return decorated().nextKey(key);
}
- public Object previousKey(Object key) {
+ public K previousKey(K key) {
return decorated().previousKey(key);
}
- public OrderedBidiMap inverseOrderedBidiMap() {
- return decorated().inverseOrderedBidiMap();
+ @Override
+ public OrderedBidiMap<V, K> inverseBidiMap() {
+ return decorated().inverseBidiMap();
}
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractSortedBidiMapDecorator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractSortedBidiMapDecorator.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractSortedBidiMapDecorator.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractSortedBidiMapDecorator.java Thu Jan 29 18:48:37 2009
@@ -38,9 +38,8 @@
*
* @author Stephen Colebourne
*/
-public abstract class AbstractSortedBidiMapDecorator
- extends AbstractOrderedBidiMapDecorator
- implements SortedBidiMap {
+public abstract class AbstractSortedBidiMapDecorator<K, V> extends
+ AbstractOrderedBidiMapDecorator<K, V> implements SortedBidiMap<K, V> {
/**
* Constructor that wraps (not copies).
@@ -48,7 +47,7 @@
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
- public AbstractSortedBidiMapDecorator(SortedBidiMap map) {
+ public AbstractSortedBidiMapDecorator(SortedBidiMap<K, V> map) {
super(map);
}
@@ -56,39 +55,34 @@
* Gets the map being decorated.
*
* @return the decorated map
- * @deprecated use decorated()
*/
- protected SortedBidiMap getSortedBidiMap() {
- return decorated();
- }
-
- /**
- * Gets the map being decorated.
- *
- * @return the decorated map
- */
- protected SortedBidiMap decorated() {
- return (SortedBidiMap) super.decorated();
+ protected SortedBidiMap<K, V> decorated() {
+ return (SortedBidiMap<K, V>) super.decorated();
}
//-----------------------------------------------------------------------
- public SortedBidiMap inverseSortedBidiMap() {
- return getSortedBidiMap().inverseSortedBidiMap();
+ @Override
+ public SortedBidiMap<V, K> inverseBidiMap() {
+ return decorated().inverseBidiMap();
}
- public Comparator comparator() {
+ public Comparator<? super K> comparator() {
return decorated().comparator();
}
- public SortedMap subMap(Object fromKey, Object toKey) {
+ public Comparator<? super V> valueComparator() {
+ return decorated().valueComparator();
+ }
+
+ public SortedMap<K, V> subMap(K fromKey, K toKey) {
return decorated().subMap(fromKey, toKey);
}
- public SortedMap headMap(Object toKey) {
+ public SortedMap<K, V> headMap(K toKey) {
return decorated().headMap(toKey);
}
- public SortedMap tailMap(Object fromKey) {
+ public SortedMap<K, V> tailMap(K fromKey) {
return decorated().tailMap(fromKey);
}
Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/DualHashBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/DualHashBidiMap.java?rev=738956&r1=738955&r2=738956&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/DualHashBidiMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/DualHashBidiMap.java Thu Jan 29 18:48:37 2009
@@ -42,8 +42,7 @@
* @author Matthew Hawthorne
* @author Stephen Colebourne
*/
-public class DualHashBidiMap
- extends AbstractDualBidiMap implements Serializable {
+public class DualHashBidiMap<K, V> extends AbstractDualBidiMap<K, V> implements Serializable {
/** Ensure serialization compatibility */
private static final long serialVersionUID = 721969328361808L;
@@ -52,7 +51,7 @@
* Creates an empty <code>HashBidiMap</code>.
*/
public DualHashBidiMap() {
- super(new HashMap(), new HashMap());
+ super(new HashMap<K, V>(), new HashMap<V, K>());
}
/**
@@ -61,8 +60,8 @@
*
* @param map the map whose mappings are to be placed in this map
*/
- public DualHashBidiMap(Map map) {
- super(new HashMap(), new HashMap());
+ public DualHashBidiMap(Map<K, V> map) {
+ super(new HashMap<K, V>(), new HashMap<V, K>());
putAll(map);
}
@@ -73,7 +72,7 @@
* @param reverseMap the reverse direction map
* @param inverseBidiMap the inverse BidiMap
*/
- protected DualHashBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
+ protected DualHashBidiMap(Map<K, V> normalMap, Map<V, K> reverseMap, BidiMap<V, K> inverseBidiMap) {
super(normalMap, reverseMap, inverseBidiMap);
}
@@ -85,21 +84,22 @@
* @param inverseBidiMap the inverse BidiMap
* @return new bidi map
*/
- protected BidiMap createBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
- return new DualHashBidiMap(normalMap, reverseMap, inverseBidiMap);
+ protected BidiMap<V, K> createBidiMap(Map<V, K> normalMap, Map<K, V> reverseMap, BidiMap<K, V> inverseBidiMap) {
+ return new DualHashBidiMap<V, K>(normalMap, reverseMap, inverseBidiMap);
}
// Serialization
//-----------------------------------------------------------------------
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
- out.writeObject(maps[0]);
+ out.writeObject(normalMap);
}
+ @SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
- maps[0] = new HashMap();
- maps[1] = new HashMap();
+ normalMap = new HashMap();
+ reverseMap = new HashMap();
Map map = (Map) in.readObject();
putAll(map);
}