scolebourne 2003/12/11 14:55:25 Modified: collections/src/java/org/apache/commons/collections/map FixedSizeSortedMap.java FixedSizeMap.java LRUMap.java Log: Implement BoundedMap interface Revision Changes Path 1.2 +54 -10 jakarta-commons/collections/src/java/org/apache/commons/collections/map/FixedSizeSortedMap.java Index: FixedSizeSortedMap.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/FixedSizeSortedMap.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FixedSizeSortedMap.java 16 Nov 2003 00:05:45 -0000 1.1 +++ FixedSizeSortedMap.java 11 Dec 2003 22:55:25 -0000 1.2 @@ -57,9 +57,16 @@ */ package org.apache.commons.collections.map; -import java.util.Comparator; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; 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> @@ -79,7 +86,8 @@ * @author Stephen Colebourne * @author Paul Jack */ -public class FixedSizeSortedMap extends FixedSizeMap implements SortedMap { +public class FixedSizeSortedMap extends AbstractSortedMapDecorator + implements SortedMap, BoundedMap { /** * Factory method to create a fixed size sorted map. @@ -112,18 +120,46 @@ } //----------------------------------------------------------------------- - public Object firstKey() { - return getSortedMap().firstKey(); + 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 Object lastKey() { - return getSortedMap().lastKey(); + public Set entrySet() { + Set set = map.entrySet(); + return UnmodifiableSet.decorate(set); } - public Comparator comparator() { - return getSortedMap().comparator(); + public Set keySet() { + Set set = map.keySet(); + return UnmodifiableSet.decorate(set); } + public Collection values() { + Collection coll = map.values(); + return UnmodifiableCollection.decorate(coll); + } + + //----------------------------------------------------------------------- public SortedMap subMap(Object fromKey, Object toKey) { SortedMap map = getSortedMap().subMap(fromKey, toKey); return new FixedSizeSortedMap(map); @@ -139,4 +175,12 @@ return new FixedSizeSortedMap(map); } + public boolean isFull() { + return true; + } + + public int maxSize() { + return size(); + } + } 1.2 +13 -3 jakarta-commons/collections/src/java/org/apache/commons/collections/map/FixedSizeMap.java Index: FixedSizeMap.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/FixedSizeMap.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FixedSizeMap.java 16 Nov 2003 00:05:45 -0000 1.1 +++ FixedSizeMap.java 11 Dec 2003 22:55:25 -0000 1.2 @@ -62,6 +62,7 @@ import java.util.Map; import java.util.Set; +import org.apache.commons.collections.BoundedMap; import org.apache.commons.collections.collection.UnmodifiableCollection; import org.apache.commons.collections.set.UnmodifiableSet; @@ -84,7 +85,8 @@ * @author Stephen Colebourne * @author Paul Jack */ -public class FixedSizeMap extends AbstractMapDecorator implements Map { +public class FixedSizeMap extends AbstractMapDecorator + implements Map, BoundedMap { /** * Factory method to create a fixed size map. @@ -145,6 +147,14 @@ public Collection values() { Collection coll = map.values(); return UnmodifiableCollection.decorate(coll); + } + + public boolean isFull() { + return true; + } + + public int maxSize() { + return size(); } } 1.4 +6 -3 jakarta-commons/collections/src/java/org/apache/commons/collections/map/LRUMap.java Index: LRUMap.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/LRUMap.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LRUMap.java 11 Dec 2003 00:46:12 -0000 1.3 +++ LRUMap.java 11 Dec 2003 22:55:25 -0000 1.4 @@ -63,6 +63,8 @@ import java.io.Serializable; import java.util.Map; +import org.apache.commons.collections.BoundedMap; + /** * A <code>Map</code> implementation with a fixed maximum size which removes * the least recently used entry if an entry is added when full. @@ -87,7 +89,8 @@ * @author Morgan Delagrange * @author Stephen Colebourne */ -public class LRUMap extends AbstractLinkedMap implements Serializable, Cloneable { +public class LRUMap extends AbstractLinkedMap + implements BoundedMap, Serializable, Cloneable { /** Serialisation version */ static final long serialVersionUID = -612114643488955218L;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]