Applied suggestions from @kske

This commit is contained in:
Leon Hofmeister 2020-09-26 21:38:31 +02:00
parent 618a4aa3cf
commit 61fbeda05e
Signed by: delvh
GPG Key ID: 3DECE05F6D9A647C
5 changed files with 22 additions and 19 deletions

View File

@ -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
@ -51,10 +50,8 @@ public final class CacheMap implements Serializable {
*/
public <T> Cache<? super T> getApplicable(Class<T> 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<Class<?>, 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); }
}

View File

@ -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() {
if (autoSaveRestart) {
// A logout happened so the timer should be restarted
if (autoSaveRestart) {
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();
}
/**

View File

@ -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 {

View File

@ -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() {}

View File

@ -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() {}