CurrentUser: Return Optional from methods that retrieve a property
Returning Optional makes it more explicit that callers must expect that the return value is absent. Change-Id: If739844482ac8966dbcdc2285869cfac7ab7e059 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -41,6 +41,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
@Singleton
|
||||
@@ -81,7 +82,7 @@ public class DeleteExternalIds implements RestModifyView<AccountResource, List<S
|
||||
.collect(toMap(i -> i.key(), i -> i));
|
||||
|
||||
List<ExternalId> toDelete = new ArrayList<>();
|
||||
ExternalId.Key last = resource.getUser().getLastLoginExternalIdKey();
|
||||
Optional<ExternalId.Key> last = resource.getUser().getLastLoginExternalIdKey();
|
||||
for (String externalIdStr : extIds) {
|
||||
ExternalId id = externalIdMap.get(ExternalId.Key.parse(externalIdStr));
|
||||
|
||||
@@ -91,7 +92,7 @@ public class DeleteExternalIds implements RestModifyView<AccountResource, List<S
|
||||
}
|
||||
|
||||
if ((!id.isScheme(SCHEME_USERNAME))
|
||||
&& ((last == null) || (!last.get().equals(id.key().get())))) {
|
||||
&& (!last.isPresent() || (!last.get().equals(id.key())))) {
|
||||
toDelete.add(id);
|
||||
} else {
|
||||
throw new ResourceConflictException(
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Singleton
|
||||
public class GetExternalIds implements RestReadView<AccountResource> {
|
||||
@@ -78,8 +79,8 @@ public class GetExternalIds implements RestReadView<AccountResource> {
|
||||
// establish this web session, and if only if an identity was
|
||||
// actually used to establish this web session.
|
||||
if (!id.isScheme(SCHEME_USERNAME)) {
|
||||
ExternalId.Key last = resource.getUser().getLastLoginExternalIdKey();
|
||||
info.canDelete = toBoolean(last == null || !last.get().equals(info.identity));
|
||||
Optional<ExternalId.Key> last = resource.getUser().getLastLoginExternalIdKey();
|
||||
info.canDelete = toBoolean(!last.isPresent() || !last.get().get().equals(info.identity));
|
||||
}
|
||||
result.add(info);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user