You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2004/04/17 01:53:59 UTC
cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/map LRUMap.java
scolebourne 2004/04/16 16:53:59
Modified: collections RELEASE-NOTES.html
collections/src/test/org/apache/commons/collections/map
TestLRUMap.java
collections/src/java/org/apache/commons/collections/map
LRUMap.java
Log:
LRUMap - The removeLRU() method was passed the wrong LinkEntry [28433]
Revision Changes Path
1.37 +1 -0 jakarta-commons/collections/RELEASE-NOTES.html
Index: RELEASE-NOTES.html
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/RELEASE-NOTES.html,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- RELEASE-NOTES.html 14 Apr 2004 21:48:28 -0000 1.36
+++ RELEASE-NOTES.html 16 Apr 2004 23:53:59 -0000 1.37
@@ -65,6 +65,7 @@
<li>AbstractHashedMap subclasses failed to clone() correctly [27159]</li>
<li>ExtendedProperties - Close input stream in constructor [27737]</li>
<li>Flat3Map - Handle infinite loops in toString</li>
+<li>LRUMap - The removeLRU() method was passed the wrong LinkEntry [28433]</li>
</ul>
<center><h3>JAVADOC</h3></center>
1.7 +58 -1 jakarta-commons/collections/src/test/org/apache/commons/collections/map/TestLRUMap.java
Index: TestLRUMap.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/map/TestLRUMap.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TestLRUMap.java 27 Feb 2004 00:25:14 -0000 1.6
+++ TestLRUMap.java 16 Apr 2004 23:53:59 -0000 1.7
@@ -218,6 +218,63 @@
assertSame(map.get("1"), cloned.get("1"));
}
+ public void testRemoveLRU() {
+ MockLRUMapSubclass map = new MockLRUMapSubclass(2);
+ assertNull(map.entry);
+ map.put("A", "a");
+ assertNull(map.entry);
+ map.put("B", "b");
+ assertNull(map.entry);
+ map.put("C", "c"); // removes oldest, which is A=a
+ assertNotNull(map.entry);
+ assertEquals("A", map.key);
+ assertEquals("a", map.value);
+ assertEquals("C", map.entry.getKey()); // entry is reused
+ assertEquals("c", map.entry.getValue()); // entry is reused
+ assertEquals(false, map.containsKey("A"));
+ assertEquals(true, map.containsKey("B"));
+ assertEquals(true, map.containsKey("C"));
+ }
+
+ static class MockLRUMapSubclass extends LRUMap {
+ LinkEntry entry;
+ Object key;
+ Object value;
+ MockLRUMapSubclass(int size) {
+ super(size);
+ }
+ protected boolean removeLRU(LinkEntry entry) {
+ this.entry = entry;
+ this.key = entry.getKey();
+ this.value = entry.getValue();
+ return true;
+ }
+ }
+
+ public void testRemoveLRUBlocksRemove() {
+ MockLRUMapSubclassBlocksRemove map = new MockLRUMapSubclassBlocksRemove(2);
+ assertEquals(0, map.size());
+ map.put("A", "a");
+ assertEquals(1, map.size());
+ map.put("B", "b");
+ assertEquals(2, map.size());
+ map.put("C", "c"); // should remove oldest, which is A=a, but this is blocked
+ assertEquals(3, map.size());
+ assertEquals(2, map.maxSize());
+ assertEquals(true, map.containsKey("A"));
+ assertEquals(true, map.containsKey("B"));
+ assertEquals(true, map.containsKey("C"));
+ }
+
+ static class MockLRUMapSubclassBlocksRemove extends LRUMap {
+ MockLRUMapSubclassBlocksRemove(int size) {
+ super(size);
+ }
+ protected boolean removeLRU(LinkEntry entry) {
+ return false;
+ }
+ }
+
// public void testCreate() throws Exception {
// resetEmpty();
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/LRUMap.emptyCollection.version3.obj");
1.10 +2 -2 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- LRUMap.java 18 Feb 2004 01:13:19 -0000 1.9
+++ LRUMap.java 16 Apr 2004 23:53:59 -0000 1.10
@@ -169,7 +169,7 @@
* @param value the value to add
*/
protected void addMapping(int hashIndex, int hashCode, Object key, Object value) {
- if (size >= maxSize && removeLRU(header.before)) {
+ if (size >= maxSize && removeLRU(header.after)) {
reuseMapping(header.after, hashIndex, hashCode, key, value);
} else {
super.addMapping(hashIndex, hashCode, key, value);
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org