Address stylistic comments.

This commit is contained in:
Isabel Drost-Fromm 2016-04-21 22:02:17 +02:00
parent ee6e53b581
commit 36a8f7b7bb
5 changed files with 48 additions and 57 deletions

View File

@ -63,7 +63,7 @@ public class RenderSearchTemplateRequest extends ActionRequest<RenderSearchTempl
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.readBoolean()) {
template = Template.readTemplate(in);
template = new Template(in);
}
}
}

View File

@ -102,7 +102,7 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder<TemplateQueryBuil
*/
public TemplateQueryBuilder(StreamInput in) throws IOException {
super(in);
template = Template.readTemplate(in);
template = new Template(in);
}
@Override

View File

@ -38,7 +38,7 @@ import java.util.Map;
/**
* Script holds all the parameters necessary to compile or find in cache and then execute a script.
*/
public class Script implements ToXContent, Writeable<Script> {
public class Script implements ToXContent, Writeable {
public static final ScriptType DEFAULT_TYPE = ScriptType.INLINE;
private static final ScriptParser PARSER = new ScriptParser();
@ -94,6 +94,36 @@ public class Script implements ToXContent, Writeable<Script> {
this.params = (Map<String, Object>)params;
}
public Script(StreamInput in) throws IOException {
script = in.readString();
if (in.readBoolean()) {
type = ScriptType.readFrom(in);
}
lang = in.readOptionalString();
if (in.readBoolean()) {
params = in.readMap();
}
}
@Override
public final void writeTo(StreamOutput out) throws IOException {
out.writeString(script);
boolean hasType = type != null;
out.writeBoolean(hasType);
if (hasType) {
ScriptType.writeTo(type, out);
}
out.writeOptionalString(lang);
boolean hasParams = params != null;
out.writeBoolean(hasParams);
if (hasParams) {
out.writeMap(params);
}
doWriteTo(out);
}
protected void doWriteTo(StreamOutput out) throws IOException {};
/**
* Method for getting the script.
* @return The cache key of the script to be compiled/executed. For dynamic scripts this is the actual
@ -131,41 +161,6 @@ public class Script implements ToXContent, Writeable<Script> {
return params;
}
@Override
public final Script readFrom(StreamInput in) throws IOException {
return new Script(in);
}
public Script(StreamInput in) throws IOException {
script = in.readString();
if (in.readBoolean()) {
type = ScriptType.readFrom(in);
}
lang = in.readOptionalString();
if (in.readBoolean()) {
params = in.readMap();
}
}
@Override
public final void writeTo(StreamOutput out) throws IOException {
out.writeString(script);
boolean hasType = type != null;
out.writeBoolean(hasType);
if (hasType) {
ScriptType.writeTo(type, out);
}
out.writeOptionalString(lang);
boolean hasParams = params != null;
out.writeBoolean(hasParams);
if (hasParams) {
out.writeMap(params);
}
doWriteTo(out);
}
protected void doWriteTo(StreamOutput out) throws IOException {};
@Override
public final XContentBuilder toXContent(XContentBuilder builder, Params builderParams) throws IOException {
if (type == null) {

View File

@ -41,13 +41,6 @@ public class Template extends Script {
private XContentType contentType;
public Template(StreamInput in) throws IOException {
super(in);
if (in.readBoolean()) {
this.contentType = XContentType.readFrom(in);
}
}
/**
* Constructor for simple inline template. The template will have no lang,
* content type or params set.
@ -82,13 +75,11 @@ public class Template extends Script {
this.contentType = xContentType;
}
/**
* Method for getting the {@link XContentType} of the template.
*
* @return The {@link XContentType} of the template.
*/
public XContentType getContentType() {
return contentType;
public Template(StreamInput in) throws IOException {
super(in);
if (in.readBoolean()) {
this.contentType = XContentType.readFrom(in);
}
}
@Override
@ -100,6 +91,15 @@ public class Template extends Script {
}
}
/**
* Method for getting the {@link XContentType} of the template.
*
* @return The {@link XContentType} of the template.
*/
public XContentType getContentType() {
return contentType;
}
@Override
protected XContentBuilder scriptFieldToXContent(String template, ScriptType type, XContentBuilder builder, Params builderParams)
throws IOException {
@ -111,10 +111,6 @@ public class Template extends Script {
return builder;
}
public static Template readTemplate(StreamInput in) throws IOException {
return new Template(in);
}
public static Script parse(Map<String, Object> config, boolean removeMatchedEntries, ParseFieldMatcher parseFieldMatcher) {
return new TemplateParser(Collections.emptyMap(), DEFAULT_LANG).parse(config, removeMatchedEntries, parseFieldMatcher);
}

View File

@ -135,7 +135,7 @@ public class PhraseSuggestionBuilder extends SuggestionBuilder<PhraseSuggestionB
postTag = in.readOptionalString();
separator = in.readString();
if (in.readBoolean()) {
collateQuery = Template.readTemplate(in);
collateQuery = new Template(in);
}
collateParams = in.readMap();
collatePrune = in.readOptionalBoolean();