diff --git a/client/src/main/java/envoy/client/data/CacheMap.java b/client/src/main/java/envoy/client/data/CacheMap.java
index 8c1fcb2..1c1c6c3 100644
--- a/client/src/main/java/envoy/client/data/CacheMap.java
+++ b/client/src/main/java/envoy/client/data/CacheMap.java
@@ -1,8 +1,7 @@
package envoy.client.data;
import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
/**
* Stores a heterogeneous map of {@link Cache} objects with different type
@@ -11,7 +10,7 @@ import java.util.Map;
* Project: envoy-client
* File: CacheMap.java
* Created: 09.07.2020
- *
+ *
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
@@ -23,7 +22,7 @@ public final class CacheMap implements Serializable {
/**
* Adds a cache to the map.
- *
+ *
* @param the type accepted by the cache
* @param key the class that maps to the cache
* @param cache the cache to store
@@ -33,7 +32,7 @@ public final class CacheMap implements Serializable {
/**
* Returns a cache mapped by a class.
- *
+ *
* @param the type accepted by the cache
* @param key the class that maps to the cache
* @return the cache
@@ -43,7 +42,7 @@ public final class CacheMap implements Serializable {
/**
* Returns a cache mapped by a class or any of its subclasses.
- *
+ *
* @param the type accepted by the cache
* @param key the class that maps to the cache
* @return the cache
@@ -51,10 +50,8 @@ public final class CacheMap implements Serializable {
*/
public Cache super T> getApplicable(Class key) {
Cache super T> cache = get(key);
- if (cache == null)
- for (var e : map.entrySet())
- if (e.getKey().isAssignableFrom(key))
- cache = (Cache super T>) e.getValue();
+ if (cache == null) for (final var e : map.entrySet())
+ if (e.getKey().isAssignableFrom(key)) cache = (Cache super T>) e.getValue();
return cache;
}
@@ -63,4 +60,11 @@ public final class CacheMap implements Serializable {
* @since Envoy Client v0.1-beta
*/
public Map, Cache>> getMap() { return map; }
+
+ /**
+ * Clears the caches of this map of any values.
+ *
+ * @since Envoy Client v0.2-beta
+ */
+ public void clear() { map.values().forEach(Cache::clear); }
}
diff --git a/client/src/main/java/envoy/client/data/LocalDB.java b/client/src/main/java/envoy/client/data/LocalDB.java
index 5cf6bba..82c007c 100644
--- a/client/src/main/java/envoy/client/data/LocalDB.java
+++ b/client/src/main/java/envoy/client/data/LocalDB.java
@@ -40,7 +40,7 @@ public final class LocalDB implements EventListener {
private CacheMap cacheMap = new CacheMap();
private String authToken;
- // auto save Timer
+ // Auto save timer
private Timer autoSaver;
private boolean autoSaveRestart = true;
@@ -172,8 +172,8 @@ public final class LocalDB implements EventListener {
*/
public void initAutoSave() {
+ // A logout happened so the timer should be restarted
if (autoSaveRestart) {
- // A logout happened so the timer should be restarted
autoSaver = new Timer("LocalDB Autosave", true);
autoSaveRestart = false;
}
@@ -229,7 +229,7 @@ public final class LocalDB implements EventListener {
* @since Envoy Client v0.2-beta
*/
@Event(eventType = Logout.class, priority = 100)
- public void onLogout() {
+ private void onLogout() {
autoSaver.cancel();
autoSaveRestart = true;
lastLoginFile.delete();
@@ -238,8 +238,7 @@ public final class LocalDB implements EventListener {
authToken = null;
chats.clear();
lastSync = Instant.EPOCH;
- cacheMap.getMap().forEach((key, cache) -> cache.clear());
- // cacheMap = new CacheMap();
+ cacheMap.clear();
}
/**
diff --git a/client/src/main/java/envoy/client/event/Logout.java b/client/src/main/java/envoy/client/event/Logout.java
index 45e2a20..098075b 100644
--- a/client/src/main/java/envoy/client/event/Logout.java
+++ b/client/src/main/java/envoy/client/event/Logout.java
@@ -5,7 +5,7 @@ import envoy.event.Event.Valueless;
/**
* Indicates that a logout has been requested.
*
- * @author leon
+ * @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public final class Logout extends Valueless {
diff --git a/client/src/main/java/envoy/client/helper/AlertHelper.java b/client/src/main/java/envoy/client/helper/AlertHelper.java
index cf6c82f..4c6e880 100644
--- a/client/src/main/java/envoy/client/helper/AlertHelper.java
+++ b/client/src/main/java/envoy/client/helper/AlertHelper.java
@@ -10,7 +10,7 @@ import envoy.client.data.Settings;
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
-public class AlertHelper {
+public final class AlertHelper {
private AlertHelper() {}
diff --git a/client/src/main/java/envoy/client/helper/ShutdownHelper.java b/client/src/main/java/envoy/client/helper/ShutdownHelper.java
index fa39b69..7f6dd7e 100644
--- a/client/src/main/java/envoy/client/helper/ShutdownHelper.java
+++ b/client/src/main/java/envoy/client/helper/ShutdownHelper.java
@@ -13,12 +13,12 @@ import envoy.util.EnvoyLog;
import dev.kske.eventbus.EventBus;
/**
- * Contains methods that have a direct impact on the user.
+ * Simplifies shutdown actions.
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
-public class ShutdownHelper {
+public final class ShutdownHelper {
private ShutdownHelper() {}