From 2586963780d235a96c03145067e389117bd7a694 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Tue, 6 Dec 2016 01:24:36 +0700 Subject: [PATCH] Remove redundant Optional usages --- .../authme/datasource/CacheDataSource.java | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index ebd9299ef..fc4e88a47 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -1,6 +1,5 @@ package fr.xephi.authme.datasource; -import com.google.common.base.Optional; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -11,22 +10,19 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerCache; -import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.security.crypts.HashedPassword; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; -import java.util.concurrent.Callable; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class CacheDataSource implements DataSource { private final DataSource source; - private final LoadingCache> cachedAuths; + private final LoadingCache cachedAuths; private final ListeningExecutorService executorService; /** @@ -45,25 +41,20 @@ public class CacheDataSource implements DataSource { cachedAuths = CacheBuilder.newBuilder() .refreshAfterWrite(5, TimeUnit.MINUTES) .expireAfterAccess(15, TimeUnit.MINUTES) - .build(new CacheLoader>() { + .build(new CacheLoader() { @Override - public Optional load(String key) { - return Optional.fromNullable(source.getAuth(key)); + public PlayerAuth load(String key) { + return source.getAuth(key); } @Override - public ListenableFuture> reload(final String key, Optional oldValue) { - return executorService.submit(new Callable>() { - @Override - public Optional call() { - return load(key); - } - }); + public ListenableFuture reload(final String key, PlayerAuth oldValue) { + return executorService.submit(() -> load(key)); } }); } - public LoadingCache> getCachedAuths() { + public LoadingCache getCachedAuths() { return cachedAuths; } @@ -80,9 +71,9 @@ public class CacheDataSource implements DataSource { @Override public HashedPassword getPassword(String user) { user = user.toLowerCase(); - Optional pAuthOpt = cachedAuths.getIfPresent(user); - if (pAuthOpt != null && pAuthOpt.isPresent()) { - return pAuthOpt.get().getPassword(); + PlayerAuth auth = cachedAuths.getIfPresent(user); + if (auth != null) { + return auth.getPassword(); } return source.getPassword(user); } @@ -90,7 +81,7 @@ public class CacheDataSource implements DataSource { @Override public PlayerAuth getAuth(String user) { user = user.toLowerCase(); - return cachedAuths.getUnchecked(user).orNull(); + return cachedAuths.getUnchecked(user); } @Override