[Schmitzm-commits] r1552 - in trunk/schmitzm-core/src: main/java/de/schmitzm/lang test/java/de/schmitzm/lang

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Apr 8 01:25:39 CEST 2011


Author: alfonx
Date: 2011-04-08 01:25:36 +0200 (Fri, 08 Apr 2011)
New Revision: 1552

Added:
   trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedHashMapTest.java
Removed:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/TimedHashmap.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedHashmapTest.java
Log:
Renamed TimedHashmap to TimedHashMap like HashMap

Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/TimedHashmap.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/TimedHashmap.java	2011-04-07 21:10:10 UTC (rev 1551)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/TimedHashmap.java	2011-04-07 23:25:36 UTC (rev 1552)
@@ -1,88 +0,0 @@
-package de.schmitzm.lang;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.HashMap;
-
-import javax.swing.Timer;
-
-/**
- * Erweiterung der {@link LimitedHashMap}. Erlaubt es in Millisekunden
- * anzugeben, wie lange ein Eintrag gültig ist.
- */
-public class TimedHashmap<K, V> extends HashMap<K, V> {
-
-	private final int timeout;
-
-	HashMap<K, Long> inputTimes = new HashMap<K, Long>();
-
-	Timer cleanTask;
-
-	/**
-	 * Erweiterung der {@link LimitedHashMap}. Erlaubt es in Millisekunden
-	 * anzugeben, wie lange ein Eintrag gültig ist.
-	 * 
-	 * @param timeout
-	 *            Anz. ms die Einträge gültig sind.
-	 */
-	public TimedHashmap(int timeout) {
-		this.timeout = timeout;
-	}
-
-	@Override
-	public V put(K key, V value) {
-
-		// Timeour ms Nach dem letzten put die komplette hashmap leeren. 
-		if (cleanTask != null) {
-			cleanTask.stop();
-		}
-
-		cleanTask = new Timer(timeout + 1, new ActionListener() {
-
-			@Override
-			public void actionPerformed(ActionEvent arg0) {
-				clear();
-				inputTimes.clear();
-				cleanTask.stop();
-				cleanTask = null;
-			}
-
-		});
-		cleanTask.setInitialDelay(timeout);
-		cleanTask.setRepeats(false);
-		cleanTask.start();
-
-		inputTimes.put(key, Long.valueOf(System.currentTimeMillis()));
-		return super.put(key, value);
-	}
-
-	@Override
-	public V get(Object key) {
-		V v = super.get(key);
-		if (v != null) {
-			Long inputTime = inputTimes.get(key);
-			if ((System.currentTimeMillis() - inputTime) >= timeout) {
-				remove(key);
-				inputTimes.remove(key);
-				return null;
-			}
-		}
-		return v;
-	}
-
-	/**
-	 * Liefert das eingestelte Timeout
-	 * 
-	 * @return
-	 */
-	public int getTimeout() {
-		return timeout;
-	}
-
-	
-	@Override
-	public void clear() {
-		super.clear();
-		if (cleanTask != null) cleanTask.stop();
-	}
-}

Copied: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedHashMapTest.java (from rev 1550, trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedHashmapTest.java)
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedHashmapTest.java	2011-04-06 08:51:43 UTC (rev 1550)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedHashMapTest.java	2011-04-07 23:25:36 UTC (rev 1552)
@@ -0,0 +1,43 @@
+package de.schmitzm.lang;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import de.schmitzm.testing.TestingClass;
+
+public class TimedHashMapTest extends TestingClass {
+
+	@Test
+	public void testTimedHashMap() throws InterruptedException {
+		TimedHashMap<String, String> tlhm = new TimedHashMap<String, String>(
+				300);
+
+		tlhm.put("A", "A");
+		Thread.sleep(110);
+		assertNotNull(tlhm.get("A"));
+		Thread.sleep(110);
+		assertNotNull(tlhm.get("A"));
+		Thread.sleep(110);
+		assertNull(tlhm.get("A"));
+	}
+	
+	@Test
+	public void testTimedHashMap_Autoclean() throws InterruptedException {
+		TimedHashMap<String, String> tlhm = new TimedHashMap<String, String>(
+				300);
+		
+		tlhm.put("A", "A");
+		Thread.sleep(110);
+		tlhm.put("B", "A");
+		Thread.sleep(110);
+		
+		assertTrue(tlhm.size() == 2);
+		Thread.sleep(410);
+		assertTrue(tlhm.size() == 0);
+	}
+
+
+}


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedHashMapTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Deleted: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedHashmapTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedHashmapTest.java	2011-04-07 21:10:10 UTC (rev 1551)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedHashmapTest.java	2011-04-07 23:25:36 UTC (rev 1552)
@@ -1,43 +0,0 @@
-package de.schmitzm.lang;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-import de.schmitzm.testing.TestingClass;
-
-public class TimedHashmapTest extends TestingClass {
-
-	@Test
-	public void testTimedHashMap() throws InterruptedException {
-		TimedHashmap<String, String> tlhm = new TimedHashmap<String, String>(
-				300);
-
-		tlhm.put("A", "A");
-		Thread.sleep(110);
-		assertNotNull(tlhm.get("A"));
-		Thread.sleep(110);
-		assertNotNull(tlhm.get("A"));
-		Thread.sleep(110);
-		assertNull(tlhm.get("A"));
-	}
-	
-	@Test
-	public void testTimedHashMap_Autoclean() throws InterruptedException {
-		TimedHashmap<String, String> tlhm = new TimedHashmap<String, String>(
-				300);
-		
-		tlhm.put("A", "A");
-		Thread.sleep(110);
-		tlhm.put("B", "A");
-		Thread.sleep(110);
-		
-		assertTrue(tlhm.size() == 2);
-		Thread.sleep(410);
-		assertTrue(tlhm.size() == 0);
-	}
-
-
-}



More information about the Schmitzm-commits mailing list