Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused methods in Result #336

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/main/java/io/weaviate/client/base/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@ToString
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class Result<T> {
int statusCode;
T result;
WeaviateError error;

Expand All @@ -23,7 +22,6 @@ public Result(Response<T> response) {
}

public Result(int statusCode, T body, WeaviateErrorResponse errors) {
this.statusCode = statusCode;
if (errors != null && errors.getError() != null) {
List<WeaviateErrorMessage> items = errors.getError().stream().filter(Objects::nonNull).collect(Collectors.toList());
this.error = new WeaviateError(statusCode, items);
Expand All @@ -37,17 +35,17 @@ public Result(int statusCode, T body, WeaviateErrorResponse errors) {
}
}

public boolean hasErrors() {
return this.error != null;
}

/**
* Copy the Result object with a null body, preserving only the status code and the error message.
*
* @param <NULL> Would-be response type. It's required for type safety, but can be anything since the body is always set to null.
*
* @param <C> Would-be response type. It's required for type safety, but can be anything since the body is always set to null.
* @return A copy of this Result.
*/
public <NULL> Result<NULL> toErrorResult() {
public <C> Result<C> toErrorResult() {
return new Result<>(this.error.getStatusCode(), null, WeaviateErrorResponse.builder().error(this.error.getMessages()).build());
}

public boolean hasErrors() {
return this.error != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Future<Result<ShardStatus[]>> run(FutureCallback<Result<ShardStatus[]>> c
try {
Result<Shard[]> shards = this.shardsGetter.withClassName(this.className).run().get();
if (shards.hasErrors()) {
return shards.<ShardStatus[]>toErrorResult();
return shards.toErrorResult();
}

List<ShardStatus> shardStatuses = new ArrayList<>();
Expand All @@ -75,12 +75,12 @@ public Future<Result<ShardStatus[]>> run(FutureCallback<Result<ShardStatus[]>> c
.withShardName(shard.getName())
.withStatus(this.status).run().get();
if (update.hasErrors()) {
return update.<ShardStatus[]>toErrorResult();
return update.toErrorResult();
}
shardStatuses.add(update.getResult());
}

return new Result<ShardStatus[]>(HttpStatus.SC_OK, shardStatuses.toArray(new ShardStatus[shardStatuses.size()]), null);
return new Result<>(HttpStatus.SC_OK, shardStatuses.toArray(new ShardStatus[shardStatuses.size()]), null);
} catch (ExecutionException | InterruptedException e) {
throw new CompletionException(e);
}
Expand Down