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:
parent
a05ca20552
commit
ac6c18f090
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -40,9 +40,11 @@ import org.apache.commons.collections.set.UnmodifiableSet;
|
|||
* 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
|
||||
* is not always unsupported.
|
||||
* <p>
|
||||
* This class is Serializable from Commons Collections 3.1.
|
||||
*
|
||||
* @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 Paul Jack
|
||||
|
@ -78,6 +80,10 @@ public class FixedSizeMap
|
|||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* 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();
|
||||
|
@ -86,6 +92,11 @@ public class FixedSizeMap
|
|||
|
||||
/**
|
||||
* 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();
|
||||
|
|
|
@ -15,20 +15,9 @@
|
|||
*/
|
||||
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.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Comparator;
|
||||
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.
|
||||
* <p>
|
||||
|
@ -41,16 +30,18 @@ import org.apache.commons.collections.set.UnmodifiableSet;
|
|||
* 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
|
||||
* is not always unsupported.
|
||||
* <p>
|
||||
* This class is Serializable from Commons Collections 3.1.
|
||||
*
|
||||
* @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 Paul Jack
|
||||
*/
|
||||
public class FixedSizeSortedMap
|
||||
extends AbstractSortedMapDecorator
|
||||
implements SortedMap, BoundedMap, Serializable {
|
||||
extends FixedSizeMap
|
||||
implements SortedMap {
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
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();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
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);
|
||||
protected SortedMap getSortedMap() {
|
||||
return (SortedMap) map;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -146,12 +90,16 @@ public class FixedSizeSortedMap
|
|||
return new FixedSizeSortedMap(map);
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return true;
|
||||
public Comparator comparator() {
|
||||
return getSortedMap().comparator();
|
||||
}
|
||||
|
||||
public int maxSize() {
|
||||
return size();
|
||||
public Object firstKey() {
|
||||
return getSortedMap().firstKey();
|
||||
}
|
||||
|
||||
|
||||
public Object lastKey() {
|
||||
return getSortedMap().lastKey();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,9 +46,11 @@ import org.apache.commons.collections.TransformerUtils;
|
|||
* After the above code is executed, <code>obj</code> will contain
|
||||
* a new <code>Date</code> instance. Furthermore, that <code>Date</code>
|
||||
* 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
|
||||
* @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 Paul Jack
|
||||
|
@ -119,6 +121,10 @@ public class LazyMap
|
|||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* 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();
|
||||
|
@ -127,6 +133,11 @@ public class LazyMap
|
|||
|
||||
/**
|
||||
* 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();
|
||||
|
|
|
@ -15,12 +15,7 @@
|
|||
*/
|
||||
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.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
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
|
||||
* a new <code>Date</code> instance. Furthermore, that <code>Date</code>
|
||||
* 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
|
||||
* @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 Paul Jack
|
||||
*/
|
||||
public class LazySortedMap
|
||||
extends LazyMap
|
||||
implements SortedMap, Serializable {
|
||||
implements SortedMap {
|
||||
|
||||
/** Serialization version */
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -50,9 +50,11 @@ import org.apache.commons.collections.list.UnmodifiableList;
|
|||
* <p>
|
||||
* If an object is added to the Map for a second time, it will remain in the
|
||||
* original position in the iteration.
|
||||
* <p>
|
||||
* This class is Serializable from Commons Collections 3.1.
|
||||
*
|
||||
* @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 Stephen Colebourne
|
||||
|
@ -94,6 +96,10 @@ public class ListOrderedMap
|
|||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* 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();
|
||||
|
@ -102,6 +108,11 @@ public class ListOrderedMap
|
|||
|
||||
/**
|
||||
* 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();
|
||||
|
|
|
@ -35,9 +35,11 @@ import org.apache.commons.collections.keyvalue.AbstractMapEntryDecorator;
|
|||
* <p>
|
||||
* If an object cannot be added to the map, an IllegalArgumentException
|
||||
* is thrown.
|
||||
* <p>
|
||||
* This class is Serializable from Commons Collections 3.1.
|
||||
*
|
||||
* @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 Paul Jack
|
||||
|
|
|
@ -15,12 +15,7 @@
|
|||
*/
|
||||
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.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import org.apache.commons.collections.Predicate;
|
||||
|
@ -31,16 +26,18 @@ import org.apache.commons.collections.Predicate;
|
|||
* <p>
|
||||
* If an object cannot be added to the map, an IllegalArgumentException
|
||||
* is thrown.
|
||||
* <p>
|
||||
* This class is Serializable from Commons Collections 3.1.
|
||||
*
|
||||
* @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 Paul Jack
|
||||
*/
|
||||
public class PredicatedSortedMap
|
||||
extends PredicatedMap
|
||||
implements SortedMap, Serializable {
|
||||
implements SortedMap {
|
||||
|
||||
/** Serialization version */
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -37,9 +37,11 @@ import org.apache.commons.collections.keyvalue.AbstractMapEntryDecorator;
|
|||
* Thus objects must be removed or searched for using their transformed form.
|
||||
* For example, if the transformation converts Strings to Integers, you must
|
||||
* use the Integer form to remove objects.
|
||||
* <p>
|
||||
* This class is Serializable from Commons Collections 3.1.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
|
|
@ -15,12 +15,7 @@
|
|||
*/
|
||||
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.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
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.
|
||||
* For example, if the transformation converts Strings to Integers, you must
|
||||
* use the Integer form to remove objects.
|
||||
* <p>
|
||||
* This class is Serializable from Commons Collections 3.1.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public class TransformedSortedMap
|
||||
extends TransformedMap
|
||||
implements SortedMap, Serializable {
|
||||
implements SortedMap {
|
||||
|
||||
/** Serialization version */
|
||||
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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue