diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/DataContainerCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/DataContainerCache.java index fba38e52e..407ab9f65 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/DataContainerCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/DataContainerCache.java @@ -54,6 +54,9 @@ public class DataContainerCache extends DataContainer { return new Key<>(PlayerContainer.class, "PLAYER_CONTAINER:" + uuid); } + private Keys() { + // Static utility class + } } public static class Suppliers { @@ -66,6 +69,10 @@ public class DataContainerCache extends DataContainer { static Supplier playerContainer(UUID uuid) { return () -> Database.getActive().fetch().getPlayerContainer(uuid); } + + private Suppliers() { + // Static utility class + } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/GeolocationCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/GeolocationCache.java index 270d4510b..3e7a752dc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/GeolocationCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/GeolocationCache.java @@ -37,12 +37,12 @@ import java.util.zip.GZIPInputStream; public class GeolocationCache implements SubSystem { private final Supplier locale; - private final Map geolocationCache; + private final Map cached; private File geolocationDB; public GeolocationCache(Supplier locale) { this.locale = locale; - geolocationCache = new HashMap<>(); + cached = new HashMap<>(); } @Override @@ -61,20 +61,10 @@ public class GeolocationCache implements SubSystem { } } - @Override - public void disable() { - } - - private static GeolocationCache getInstance() { - GeolocationCache geolocationCache = CacheSystem.getInstance().getGeolocationCache(); - Verify.nullCheck(geolocationCache, () -> new IllegalStateException("GeolocationCache was not initialized.")); - return geolocationCache; - } - /** * Retrieves the country in full length (e.g. United States) from the IP Address. *

- * This method uses the {@code geolocationCache}, every first access is getting cached and then retrieved later. + * This method uses {@code cached}, every first access is getting cached and then retrieved later. * * @param ipAddress The IP Address from which the country is retrieved * @return The name of the country in full length. @@ -90,12 +80,28 @@ public class GeolocationCache implements SubSystem { return country; } else { country = getUnCachedCountry(ipAddress); - getInstance().geolocationCache.put(ipAddress, country); + getInstance().cached.put(ipAddress, country); return country; } } + private static GeolocationCache getInstance() { + GeolocationCache geolocationCache = CacheSystem.getInstance().getGeolocationCache(); + Verify.nullCheck(geolocationCache, () -> new IllegalStateException("GeolocationCache was not initialized.")); + return geolocationCache; + } + + /** + * Returns the cached country + * + * @param ipAddress The IP Address which is retrieved out of the cache + * @return The cached country, {@code null} if the country is not cached + */ + private static String getCachedCountry(String ipAddress) { + return getInstance().cached.get(ipAddress); + } + /** * Retrieves the country in full length (e.g. United States) from the IP Address. *

@@ -147,16 +153,6 @@ public class GeolocationCache implements SubSystem { } } - /** - * Returns the cached country - * - * @param ipAddress The IP Address which is retrieved out of the cache - * @return The cached country, {@code null} if the country is not cached - */ - private static String getCachedCountry(String ipAddress) { - return getInstance().geolocationCache.get(ipAddress); - } - /** * Checks if the IP Address is cached * @@ -164,13 +160,18 @@ public class GeolocationCache implements SubSystem { * @return true if the IP Address is cached */ public static boolean isCached(String ipAddress) { - return getInstance().geolocationCache.containsKey(ipAddress); + return getInstance().cached.containsKey(ipAddress); + } + + @Override + public void disable() { + cached.clear(); } /** * Clears the cache */ public void clearCache() { - geolocationCache.clear(); + cached.clear(); } }