[Schmitzm-commits] r1557 - trunk/schmitzm-core/src/main/java/de/schmitzm/lang
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Apr 18 13:27:37 CEST 2011
Author: alfonx
Date: 2011-04-18 13:27:36 +0200 (Mon, 18 Apr 2011)
New Revision: 1557
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/TimedHashMap.java
Log:
Tweaking TimedHashMap
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/TimedHashMap.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/TimedHashMap.java 2011-04-15 07:22:08 UTC (rev 1556)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/TimedHashMap.java 2011-04-18 11:27:36 UTC (rev 1557)
@@ -32,32 +32,41 @@
@Override
public V put(K key, V value) {
- // Timeour ms Nach dem letzten put die komplette hashmap leeren.
- if (cleanTask != null) {
- cleanTask.stop();
- }
+ if (timeout > 0) {
- cleanTask = new Timer(timeout + 1, new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent arg0) {
- clear();
- inputTimes.clear();
+ // Timeour ms Nach dem letzten put die komplette hashmap leeren.
+ if (cleanTask != null) {
cleanTask.stop();
- cleanTask = null;
}
- });
- cleanTask.setInitialDelay(timeout);
- cleanTask.setRepeats(false);
- cleanTask.start();
+ cleanTask = new Timer(timeout + 1, new ActionListener() {
- inputTimes.put(key, Long.valueOf(System.currentTimeMillis()));
- return super.put(key, value);
+ @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);
+ } else
+ return null;
}
@Override
public V get(Object key) {
+
+ // Bei einem Timeout von 0 wird der Wert nie gespeichert
+ if (timeout == 0)
+ return null;
+
V v = super.get(key);
if (v != null) {
Long inputTime = inputTimes.get(key);
@@ -79,10 +88,10 @@
return timeout;
}
-
@Override
public void clear() {
super.clear();
- if (cleanTask != null) cleanTask.stop();
+ if (cleanTask != null)
+ cleanTask.stop();
}
}
More information about the Schmitzm-commits
mailing list