Simplify the decorator serialization, add javadoc [18815]

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131636 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2004-04-09 10:36:02 +00:00
parent a05ca20552
commit ac6c18f090
22 changed files with 74 additions and 164 deletions

View File

@ -40,9 +40,11 @@ import org.apache.commons.collections.set.UnmodifiableSet;
* IllegalArgumentException is thrown. This is because the put method can * IllegalArgumentException is thrown. This is because the put method can
* succeed if the mapping's key already exists in the map, so the put method * succeed if the mapping's key already exists in the map, so the put method
* is not always unsupported. * is not always unsupported.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2004/04/02 21:15:05 $ * @version $Revision: 1.7 $ $Date: 2004/04/09 10:36:01 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Paul Jack * @author Paul Jack
@ -78,6 +80,10 @@ public class FixedSizeMap
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Write the map out using a custom routine. * Write the map out using a custom routine.
*
* @param out the output stream
* @throws IOException
* @since Commons Collections 3.1
*/ */
private void writeObject(ObjectOutputStream out) throws IOException { private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject(); out.defaultWriteObject();
@ -86,6 +92,11 @@ public class FixedSizeMap
/** /**
* Read the map in using a custom routine. * Read the map in using a custom routine.
*
* @param in the input stream
* @throws IOException
* @throws ClassNotFoundException
* @since Commons Collections 3.1
*/ */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject(); in.defaultReadObject();

View File

@ -15,20 +15,9 @@
*/ */
package org.apache.commons.collections.map; package org.apache.commons.collections.map;
import java.io.IOException; import java.util.Comparator;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap; import java.util.SortedMap;
import org.apache.commons.collections.BoundedMap;
import org.apache.commons.collections.collection.UnmodifiableCollection;
import org.apache.commons.collections.set.UnmodifiableSet;
/** /**
* Decorates another <code>SortedMap</code> to fix the size blocking add/remove. * Decorates another <code>SortedMap</code> to fix the size blocking add/remove.
* <p> * <p>
@ -41,16 +30,18 @@ import org.apache.commons.collections.set.UnmodifiableSet;
* IllegalArgumentException is thrown. This is because the put method can * IllegalArgumentException is thrown. This is because the put method can
* succeed if the mapping's key already exists in the map, so the put method * succeed if the mapping's key already exists in the map, so the put method
* is not always unsupported. * is not always unsupported.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2004/04/02 23:12:34 $ * @version $Revision: 1.7 $ $Date: 2004/04/09 10:36:01 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Paul Jack * @author Paul Jack
*/ */
public class FixedSizeSortedMap public class FixedSizeSortedMap
extends AbstractSortedMapDecorator extends FixedSizeMap
implements SortedMap, BoundedMap, Serializable { implements SortedMap {
/** /**
* Factory method to create a fixed size sorted map. * Factory method to create a fixed size sorted map.
@ -75,59 +66,12 @@ public class FixedSizeSortedMap
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Write the map out using a custom routine. * Gets the map being decorated.
*
* @return the decorated map
*/ */
private void writeObject(ObjectOutputStream out) throws IOException { protected SortedMap getSortedMap() {
out.defaultWriteObject(); return (SortedMap) map;
out.writeObject(map);
}
/**
* Read the map in using a custom routine.
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
map = (Map) in.readObject();
}
//-----------------------------------------------------------------------
public Object put(Object key, Object value) {
if (map.containsKey(key) == false) {
throw new IllegalArgumentException("Cannot put new key/value pair - Map is fixed size");
}
return map.put(key, value);
}
public void putAll(Map mapToCopy) {
for (Iterator it = mapToCopy.keySet().iterator(); it.hasNext(); ) {
if (mapToCopy.containsKey(it.next()) == false) {
throw new IllegalArgumentException("Cannot put new key/value pair - Map is fixed size");
}
}
map.putAll(mapToCopy);
}
public void clear() {
throw new UnsupportedOperationException("Map is fixed size");
}
public Object remove(Object key) {
throw new UnsupportedOperationException("Map is fixed size");
}
public Set entrySet() {
Set set = map.entrySet();
return UnmodifiableSet.decorate(set);
}
public Set keySet() {
Set set = map.keySet();
return UnmodifiableSet.decorate(set);
}
public Collection values() {
Collection coll = map.values();
return UnmodifiableCollection.decorate(coll);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -146,12 +90,16 @@ public class FixedSizeSortedMap
return new FixedSizeSortedMap(map); return new FixedSizeSortedMap(map);
} }
public boolean isFull() { public Comparator comparator() {
return true; return getSortedMap().comparator();
} }
public int maxSize() { public Object firstKey() {
return size(); return getSortedMap().firstKey();
}
public Object lastKey() {
return getSortedMap().lastKey();
} }
} }

View File

@ -46,9 +46,11 @@ import org.apache.commons.collections.TransformerUtils;
* After the above code is executed, <code>obj</code> will contain * After the above code is executed, <code>obj</code> will contain
* a new <code>Date</code> instance. Furthermore, that <code>Date</code> * a new <code>Date</code> instance. Furthermore, that <code>Date</code>
* instance is mapped to the "NOW" key in the map. * instance is mapped to the "NOW" key in the map.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/04/07 23:05:37 $ * @version $Revision: 1.6 $ $Date: 2004/04/09 10:36:01 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Paul Jack * @author Paul Jack
@ -119,6 +121,10 @@ public class LazyMap
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Write the map out using a custom routine. * Write the map out using a custom routine.
*
* @param out the output stream
* @throws IOException
* @since Commons Collections 3.1
*/ */
private void writeObject(ObjectOutputStream out) throws IOException { private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject(); out.defaultWriteObject();
@ -127,6 +133,11 @@ public class LazyMap
/** /**
* Read the map in using a custom routine. * Read the map in using a custom routine.
*
* @param in the input stream
* @throws IOException
* @throws ClassNotFoundException
* @since Commons Collections 3.1
*/ */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject(); in.defaultReadObject();

View File

@ -15,12 +15,7 @@
*/ */
package org.apache.commons.collections.map; package org.apache.commons.collections.map;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map;
import java.util.SortedMap; import java.util.SortedMap;
import org.apache.commons.collections.Factory; import org.apache.commons.collections.Factory;
@ -47,16 +42,18 @@ import org.apache.commons.collections.Transformer;
* After the above code is executed, <code>obj</code> will contain * After the above code is executed, <code>obj</code> will contain
* a new <code>Date</code> instance. Furthermore, that <code>Date</code> * a new <code>Date</code> instance. Furthermore, that <code>Date</code>
* instance is mapped to the "NOW" key in the map. * instance is mapped to the "NOW" key in the map.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/04/07 23:05:37 $ * @version $Revision: 1.6 $ $Date: 2004/04/09 10:36:01 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Paul Jack * @author Paul Jack
*/ */
public class LazySortedMap public class LazySortedMap
extends LazyMap extends LazyMap
implements SortedMap, Serializable { implements SortedMap {
/** Serialization version */ /** Serialization version */
private static final long serialVersionUID = 2715322183617658933L; private static final long serialVersionUID = 2715322183617658933L;
@ -107,22 +104,6 @@ public class LazySortedMap
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/**
* Write the map out using a custom routine.
*/
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(map);
}
/**
* Read the map in using a custom routine.
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
map = (Map) in.readObject();
}
/** /**
* Gets the map being decorated. * Gets the map being decorated.
* *

View File

@ -50,9 +50,11 @@ import org.apache.commons.collections.list.UnmodifiableList;
* <p> * <p>
* If an object is added to the Map for a second time, it will remain in the * If an object is added to the Map for a second time, it will remain in the
* original position in the iteration. * original position in the iteration.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.14 $ $Date: 2004/04/07 23:17:25 $ * @version $Revision: 1.15 $ $Date: 2004/04/09 10:36:01 $
* *
* @author Henri Yandell * @author Henri Yandell
* @author Stephen Colebourne * @author Stephen Colebourne
@ -94,6 +96,10 @@ public class ListOrderedMap
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Write the map out using a custom routine. * Write the map out using a custom routine.
*
* @param out the output stream
* @throws IOException
* @since Commons Collections 3.1
*/ */
private void writeObject(ObjectOutputStream out) throws IOException { private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject(); out.defaultWriteObject();
@ -102,6 +108,11 @@ public class ListOrderedMap
/** /**
* Read the map in using a custom routine. * Read the map in using a custom routine.
*
* @param in the input stream
* @throws IOException
* @throws ClassNotFoundException
* @since Commons Collections 3.1
*/ */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject(); in.defaultReadObject();

View File

@ -35,9 +35,11 @@ import org.apache.commons.collections.keyvalue.AbstractMapEntryDecorator;
* <p> * <p>
* If an object cannot be added to the map, an IllegalArgumentException * If an object cannot be added to the map, an IllegalArgumentException
* is thrown. * is thrown.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.8 $ $Date: 2004/04/09 09:43:09 $ * @version $Revision: 1.9 $ $Date: 2004/04/09 10:36:01 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Paul Jack * @author Paul Jack

View File

@ -15,12 +15,7 @@
*/ */
package org.apache.commons.collections.map; package org.apache.commons.collections.map;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map;
import java.util.SortedMap; import java.util.SortedMap;
import org.apache.commons.collections.Predicate; import org.apache.commons.collections.Predicate;
@ -31,16 +26,18 @@ import org.apache.commons.collections.Predicate;
* <p> * <p>
* If an object cannot be added to the map, an IllegalArgumentException * If an object cannot be added to the map, an IllegalArgumentException
* is thrown. * is thrown.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/04/09 09:43:09 $ * @version $Revision: 1.6 $ $Date: 2004/04/09 10:36:01 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Paul Jack * @author Paul Jack
*/ */
public class PredicatedSortedMap public class PredicatedSortedMap
extends PredicatedMap extends PredicatedMap
implements SortedMap, Serializable { implements SortedMap {
/** Serialization version */ /** Serialization version */
private static final long serialVersionUID = 3359846175935304332L; private static final long serialVersionUID = 3359846175935304332L;
@ -74,31 +71,6 @@ public class PredicatedSortedMap
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/**
* Write the map out using a custom routine.
*
* @param out the output stream
* @throws IOException
* @since Commons Collections 3.1
*/
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(map);
}
/**
* Read the map in using a custom routine.
*
* @param in the input stream
* @throws IOException
* @throws ClassNotFoundException
* @since Commons Collections 3.1
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
map = (Map) in.readObject();
}
/** /**
* Gets the map being decorated. * Gets the map being decorated.
* *

View File

@ -37,9 +37,11 @@ import org.apache.commons.collections.keyvalue.AbstractMapEntryDecorator;
* Thus objects must be removed or searched for using their transformed form. * Thus objects must be removed or searched for using their transformed form.
* For example, if the transformation converts Strings to Integers, you must * For example, if the transformation converts Strings to Integers, you must
* use the Integer form to remove objects. * use the Integer form to remove objects.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.7 $ $Date: 2004/04/09 09:43:09 $ * @version $Revision: 1.8 $ $Date: 2004/04/09 10:36:01 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */

View File

@ -15,12 +15,7 @@
*/ */
package org.apache.commons.collections.map; package org.apache.commons.collections.map;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map;
import java.util.SortedMap; import java.util.SortedMap;
import org.apache.commons.collections.Transformer; import org.apache.commons.collections.Transformer;
@ -32,15 +27,17 @@ import org.apache.commons.collections.Transformer;
* Thus objects must be removed or searched for using their transformed form. * Thus objects must be removed or searched for using their transformed form.
* For example, if the transformation converts Strings to Integers, you must * For example, if the transformation converts Strings to Integers, you must
* use the Integer form to remove objects. * use the Integer form to remove objects.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/04/09 09:43:09 $ * @version $Revision: 1.6 $ $Date: 2004/04/09 10:36:01 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public class TransformedSortedMap public class TransformedSortedMap
extends TransformedMap extends TransformedMap
implements SortedMap, Serializable { implements SortedMap {
/** Serialization version */ /** Serialization version */
private static final long serialVersionUID = -8751771676410385778L; private static final long serialVersionUID = -8751771676410385778L;
@ -77,31 +74,6 @@ public class TransformedSortedMap
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/**
* Write the map out using a custom routine.
*
* @param out the output stream
* @throws IOException
* @since Commons Collections 3.1
*/
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(map);
}
/**
* Read the map in using a custom routine.
*
* @param in the input stream
* @throws IOException
* @throws ClassNotFoundException
* @since Commons Collections 3.1
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
map = (Map) in.readObject();
}
/** /**
* Gets the map being decorated. * Gets the map being decorated.
* *