[Schmitzm-commits] r945 - in trunk: src/schmitzm/lang src_junit/schmitzm/lang

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jul 23 19:11:46 CEST 2010


Author: mojays
Date: 2010-07-23 19:11:46 +0200 (Fri, 23 Jul 2010)
New Revision: 945

Modified:
   trunk/src/schmitzm/lang/LimitedHashMap.java
   trunk/src_junit/schmitzm/lang/LimitedHashMapTest.java
Log:
LimitedHashMap: behavior of oldest-list changed for OLDEST_GET (see MS-01)

Modified: trunk/src/schmitzm/lang/LimitedHashMap.java
===================================================================
--- trunk/src/schmitzm/lang/LimitedHashMap.java	2010-07-23 14:31:54 UTC (rev 944)
+++ trunk/src/schmitzm/lang/LimitedHashMap.java	2010-07-23 17:11:46 UTC (rev 945)
@@ -159,10 +159,20 @@
       //             new element at the end of the oldest list
       case OLDEST_PUT: oldestKeys.add(key);
                        break;
-      // OLDEST_GET: the new element is not yet accessed by get, so add the key 
-      //             at the front of the oldest list
-      case OLDEST_GET: oldestKeys.add(0,key);
+//MS-01.sc: Adding the new element to the top of the oldest-list causes that
+//          it might be removed immediately on the next put/truncate!
+//          Although this would be consequent, this is not practical.
+//          Instead we put the new element at the end of the oldest-list
+//          so that the element stays in the map at least "for a while".
+//      // OLDEST_GET: the new element is not yet accessed by get, so add the key 
+//      //             at the front of the oldest list
+//      case OLDEST_GET: oldestKeys.add(0,key);
+//                       break;
+      // OLDEST_GET: to keep the new element in the map at least "for a while",
+      //             it is added at the end of the oldest-list (like OLDEST_PUT)
+      case OLDEST_GET: oldestKeys.add(key);
                        break;
+//MS-01.ec
     }
     
     // fire an event if the map has changed

Modified: trunk/src_junit/schmitzm/lang/LimitedHashMapTest.java
===================================================================
--- trunk/src_junit/schmitzm/lang/LimitedHashMapTest.java	2010-07-23 14:31:54 UTC (rev 944)
+++ trunk/src_junit/schmitzm/lang/LimitedHashMapTest.java	2010-07-23 17:11:46 UTC (rev 945)
@@ -1,13 +1,47 @@
 package schmitzm.lang;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
+import java.awt.Color;
+import java.awt.Graphics2D;
 import java.awt.GraphicsEnvironment;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.io.File;
 import java.io.IOException;
+import java.net.URL;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.log4j.Logger;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.filter.text.cql2.CQLException;
+import org.jfree.chart.ChartFrame;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.AxisState;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.axis.NumberTick;
+import org.jfree.chart.axis.NumberTickUnit;
+import org.jfree.chart.axis.TickUnits;
+import org.jfree.chart.axis.ValueTick;
+import org.jfree.ui.RectangleEdge;
+import org.jfree.ui.TextAnchor;
 import org.junit.Test;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
 
+import schmitzm.geotools.io.GeoImportUtil;
+import schmitzm.io.IOUtil;
+import schmitzm.jfree.chart.style.ChartAxisStyle;
+import schmitzm.jfree.chart.style.ChartLabelStyle;
+import schmitzm.jfree.chart.style.ChartRendererStyle;
+import schmitzm.jfree.chart.style.ChartType;
+import schmitzm.jfree.table.AggregationFunction;
+
 public class LimitedHashMapTest {
   private static Logger log = Logger.getLogger(LimitedHashMapTest.class);
   /** If tests are run on a system with head, we may theoretically open dialgs, frames etc. **/
@@ -46,12 +80,12 @@
         assertEquals("Vorletztes Element in Oldest-List muss 5 sein.", 5, (int)lhm.oldestKeys.elementAt(lhm.size()-2));
         break;
       case OLDEST_GET:
-        // 5 muesste geloescht worden sein
-        assertEquals("Erstes Element in Oldest-List muss 6 sein.", 6, (int)lhm.oldestKeys.firstElement());
+        // 1 muesste geloescht worden sein
+        assertEquals("Erstes Element in Oldest-List muss 2 sein.", 2, (int)lhm.oldestKeys.firstElement());
         // 6 muesste letztes Element sein
-        assertEquals("Letztes Element in Oldest-List muss 1 sein.", 1, (int)lhm.oldestKeys.lastElement());
+        assertEquals("Letztes Element in Oldest-List muss 6 sein.", 6, (int)lhm.oldestKeys.lastElement());
         // 4 muesste vorletztes Element sein
-        assertEquals("Vorletztes Element in Oldest-List muss 2 sein.", 2, (int)lhm.oldestKeys.elementAt(lhm.size()-2));
+        assertEquals("Vorletztes Element in Oldest-List muss 5 sein.", 5, (int)lhm.oldestKeys.elementAt(lhm.size()-2));
         break;
     }
     
@@ -59,8 +93,9 @@
     debugLimitedHashMap(lhm);
     lhm.get(6); // 6 muss ans Ende der Oldest-List rutschen
     debugLimitedHashMap(lhm);
+    lhm.get(4); // 4 muss ans Ende der Oldest-List rutschen
+    debugLimitedHashMap(lhm);
     
-    
     lhm.put(7, "Element "+7);
     debugLimitedHashMap(lhm);
   }



More information about the Schmitzm-commits mailing list