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:
Edwin Kempin
2018-02-02 11:42:15 +01:00
parent 79c916c462
commit 8128e3f149
5 changed files with 28 additions and 24 deletions

View File

@@ -125,11 +125,10 @@ public abstract class CurrentUser {
* Lookup a previously stored property.
*
* @param key unique property key.
* @return previously stored value, or {@code null}.
* @return previously stored value, or {@code Optional#empty()}.
*/
@Nullable
public <T> T get(PropertyKey<T> key) {
return null;
public <T> Optional<T> get(PropertyKey<T> key) {
return Optional.empty();
}
/**
@@ -144,7 +143,7 @@ public abstract class CurrentUser {
put(lastLoginExternalIdPropertyKey, externalIdKey);
}
public ExternalId.Key getLastLoginExternalIdKey() {
public Optional<ExternalId.Key> getLastLoginExternalIdKey() {
return get(lastLoginExternalIdPropertyKey);
}
}