Skip to content

Commit

Permalink
fix: circular calling on GetResponse::found
Browse files Browse the repository at this point in the history
Adds a new interface `GetResponseFound` to solve the previous
implementation's circular calling on `GetResponse::found`.

Previously
this method returned a `GetResponse.Found`, so on a response of this
type, a caller could write
`response.found().get().found().get().found()...` ad infinitum. This
was not desirable.

To solve this we introduce a new interface `GetResponseFound` which
`GetResponse.Found` implements. This way `GetResponse::found` returns
an `Optional.of` an object implementing that, which cuts the cycle.
  • Loading branch information
malandis committed Jun 28, 2024
1 parent 1c9f001 commit 8c73749
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface GetResponse {
*
* @return The success response, or an empty optional if the operation failed.
*/
Optional<Found> found();
Optional<GetResponseFound> found();

/**
* A successful get operation.
Expand All @@ -38,7 +38,7 @@ public interface GetResponse {
* <p>Use the appropriate type-based accessor on the value to retrieve the value in its
* corresponding type.
*/
class Found implements GetResponse {
class Found implements GetResponse, GetResponseFound {
private final StorageValue value;

private Found(StorageValue value) {
Expand Down Expand Up @@ -71,7 +71,7 @@ public StorageValue value() {
}

@Override
public Optional<Found> found() {
public Optional<GetResponseFound> found() {
return Optional.of(this);
}

Expand All @@ -85,7 +85,7 @@ class NotFound implements GetResponse {
public NotFound() {}

@Override
public Optional<Found> found() {
public Optional<GetResponseFound> found() {
return Optional.empty();
}

Expand All @@ -112,7 +112,7 @@ public Error(SdkException cause) {
}

@Override
public Optional<Found> found() {
public Optional<GetResponseFound> found() {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package momento.sdk.responses.storage;

public interface GetResponseFound {
StorageValue value();
}

0 comments on commit 8c73749

Please sign in to comment.