AccountCacheImpl: Use java.util.Optional
Change-Id: I7e25ee99a59231a34f5ff4174f844b0c1d0e1a8d
This commit is contained in:
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
@@ -52,6 +51,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
@@ -252,17 +252,13 @@ public class AccountCacheImpl implements AccountCache {
|
|||||||
if (accountIndexes.getSearchIndex() != null) {
|
if (accountIndexes.getSearchIndex() != null) {
|
||||||
AccountState accountState =
|
AccountState accountState =
|
||||||
accountQueryProvider.get().oneByExternalId(key.get());
|
accountQueryProvider.get().oneByExternalId(key.get());
|
||||||
return accountState != null
|
return Optional.ofNullable(accountState)
|
||||||
? Optional.of(accountState.getAccount().getId())
|
.map(s -> s.getAccount().getId());
|
||||||
: Optional.<Account.Id>absent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try (ReviewDb db = schema.open()) {
|
try (ReviewDb db = schema.open()) {
|
||||||
AccountExternalId id = db.accountExternalIds().get(key);
|
return Optional.ofNullable(db.accountExternalIds().get(key))
|
||||||
if (id != null) {
|
.map(AccountExternalId::getAccountId);
|
||||||
return Optional.of(id.getAccountId());
|
|
||||||
}
|
|
||||||
return Optional.absent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user