Add javadoc for DocWriteResponse.Builders (#23267)

This commit is contained in:
Tanguy Leroux 2017-02-21 10:19:01 +01:00 committed by GitHub
parent 24bf18b610
commit c88eb00b83
5 changed files with 33 additions and 17 deletions

View File

@ -304,7 +304,7 @@ public abstract class DocWriteResponse extends ReplicationResponse implements Wr
* {@link DocWriteResponse} objects. It always parses the current token, updates the given parsing context accordingly
* if needed and then immediately returns.
*/
protected static void parseInnerToXContent(XContentParser parser, DocWriteResponseBuilder context) throws IOException {
protected static void parseInnerToXContent(XContentParser parser, Builder context) throws IOException {
XContentParser.Token token = parser.currentToken();
ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
@ -348,9 +348,11 @@ public abstract class DocWriteResponse extends ReplicationResponse implements Wr
}
/**
* {@link DocWriteResponseBuilder} is used to build {@link DocWriteResponse} objects during XContent parsing.
* Base class of all {@link DocWriteResponse} builders. These {@link DocWriteResponse.Builder} are used during
* xcontent parsing to temporarily store the parsed values, then the {@link Builder#build()} method is called to
* instantiate the appropriate {@link DocWriteResponse} with the parsed values.
*/
public abstract static class DocWriteResponseBuilder {
public abstract static class Builder {
protected ShardId shardId = null;
protected String type = null;

View File

@ -40,7 +40,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
import java.util.function.Supplier;
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
import static org.elasticsearch.common.xcontent.XContentParserUtils.throwUnknownField;
@ -102,21 +101,21 @@ public class BulkItemResponse implements Streamable, StatusToXContentObject {
final OpType opType = OpType.fromString(currentFieldName);
ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);
DocWriteResponse.DocWriteResponseBuilder builder = null;
DocWriteResponse.Builder builder = null;
CheckedConsumer<XContentParser, IOException> itemParser = null;
if (opType == OpType.INDEX || opType == OpType.CREATE) {
final IndexResponse.IndexResponseBuilder indexResponseBuilder = new IndexResponse.IndexResponseBuilder();
final IndexResponse.Builder indexResponseBuilder = new IndexResponse.Builder();
builder = indexResponseBuilder;
itemParser = (indexParser) -> IndexResponse.parseXContentFields(indexParser, indexResponseBuilder);
} else if (opType == OpType.UPDATE) {
final UpdateResponse.UpdateResponseBuilder updateResponseBuilder = new UpdateResponse.UpdateResponseBuilder();
final UpdateResponse.Builder updateResponseBuilder = new UpdateResponse.Builder();
builder = updateResponseBuilder;
itemParser = (updateParser) -> UpdateResponse.parseXContentFields(updateParser, updateResponseBuilder);
} else if (opType == OpType.DELETE) {
final DeleteResponse.DeleteResponseBuilder deleteResponseBuilder = new DeleteResponse.DeleteResponseBuilder();
final DeleteResponse.Builder deleteResponseBuilder = new DeleteResponse.Builder();
builder = deleteResponseBuilder;
itemParser = (deleteParser) -> DeleteResponse.parseXContentFields(deleteParser, deleteResponseBuilder);
} else {

View File

@ -74,7 +74,7 @@ public class DeleteResponse extends DocWriteResponse {
public static DeleteResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
DeleteResponseBuilder context = new DeleteResponseBuilder();
Builder context = new Builder();
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
parseXContentFields(parser, context);
}
@ -84,7 +84,7 @@ public class DeleteResponse extends DocWriteResponse {
/**
* Parse the current token and update the parsing context appropriately.
*/
public static void parseXContentFields(XContentParser parser, DeleteResponseBuilder context) throws IOException {
public static void parseXContentFields(XContentParser parser, Builder context) throws IOException {
XContentParser.Token token = parser.currentToken();
String currentFieldName = parser.currentName();
@ -97,7 +97,12 @@ public class DeleteResponse extends DocWriteResponse {
}
}
public static class DeleteResponseBuilder extends DocWriteResponse.DocWriteResponseBuilder {
/**
* Builder class for {@link DeleteResponse}. This builder is usually used during xcontent parsing to
* temporarily store the parsed values, then the {@link DocWriteResponse.Builder#build()} method is called to
* instantiate the {@link DeleteResponse}.
*/
public static class Builder extends DocWriteResponse.Builder {
private boolean found = false;

View File

@ -76,7 +76,7 @@ public class IndexResponse extends DocWriteResponse {
public static IndexResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
IndexResponseBuilder context = new IndexResponseBuilder();
Builder context = new Builder();
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
parseXContentFields(parser, context);
}
@ -86,7 +86,7 @@ public class IndexResponse extends DocWriteResponse {
/**
* Parse the current token and update the parsing context appropriately.
*/
public static void parseXContentFields(XContentParser parser, IndexResponseBuilder context) throws IOException {
public static void parseXContentFields(XContentParser parser, Builder context) throws IOException {
XContentParser.Token token = parser.currentToken();
String currentFieldName = parser.currentName();
@ -99,7 +99,12 @@ public class IndexResponse extends DocWriteResponse {
}
}
public static class IndexResponseBuilder extends DocWriteResponse.DocWriteResponseBuilder {
/**
* Builder class for {@link IndexResponse}. This builder is usually used during xcontent parsing to
* temporarily store the parsed values, then the {@link Builder#build()} method is called to
* instantiate the {@link IndexResponse}.
*/
public static class Builder extends DocWriteResponse.Builder {
private boolean created = false;

View File

@ -114,7 +114,7 @@ public class UpdateResponse extends DocWriteResponse {
public static UpdateResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
UpdateResponseBuilder context = new UpdateResponseBuilder();
Builder context = new Builder();
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
parseXContentFields(parser, context);
}
@ -124,7 +124,7 @@ public class UpdateResponse extends DocWriteResponse {
/**
* Parse the current token and update the parsing context appropriately.
*/
public static void parseXContentFields(XContentParser parser, UpdateResponseBuilder context) throws IOException {
public static void parseXContentFields(XContentParser parser, Builder context) throws IOException {
XContentParser.Token token = parser.currentToken();
String currentFieldName = parser.currentName();
@ -137,7 +137,12 @@ public class UpdateResponse extends DocWriteResponse {
}
}
public static class UpdateResponseBuilder extends DocWriteResponse.DocWriteResponseBuilder {
/**
* Builder class for {@link UpdateResponse}. This builder is usually used during xcontent parsing to
* temporarily store the parsed values, then the {@link DocWriteResponse.Builder#build()} method is called to
* instantiate the {@link UpdateResponse}.
*/
public static class Builder extends DocWriteResponse.Builder {
private GetResult getResult = null;