Deprecated ToXContent.Params#paramAsBooleanOptional in favour of paramAsBoolean

Closes #4817
This commit is contained in:
Luca Cavanna 2014-01-20 17:14:46 +01:00
parent 66ed9a855a
commit 8f96930638
10 changed files with 44 additions and 15 deletions

View File

@ -156,13 +156,16 @@ public class TransportGetFieldMappingsAction extends TransportClusterInfoAction<
return defaultValue;
}
@Override
public Boolean paramAsBooleanOptional(String key, Boolean defaultValue) {
public Boolean paramAsBoolean(String key, Boolean defaultValue) {
if (INCLUDE_DEFAULTS.equals(key)) {
return true;
}
return defaultValue;
}
@Override @Deprecated
public Boolean paramAsBooleanOptional(String key, Boolean defaultValue) {
return paramAsBoolean(key, defaultValue);
}
};

View File

@ -36,6 +36,13 @@ public interface ToXContent {
boolean paramAsBoolean(String key, boolean defaultValue);
Boolean paramAsBoolean(String key, Boolean defaultValue);
/**
* @deprecated since 1.0.0
* use {@link ToXContent.Params#paramAsBoolean(String, Boolean)} instead
*/
@Deprecated
Boolean paramAsBooleanOptional(String key, Boolean defaultValue);
}
@ -56,9 +63,14 @@ public interface ToXContent {
}
@Override
public Boolean paramAsBooleanOptional(String key, Boolean defaultValue) {
public Boolean paramAsBoolean(String key, Boolean defaultValue) {
return defaultValue;
}
@Override @Deprecated
public Boolean paramAsBooleanOptional(String key, Boolean defaultValue) {
return paramAsBoolean(key, defaultValue);
}
};
public static class MapParams implements Params {
@ -89,9 +101,14 @@ public interface ToXContent {
}
@Override
public Boolean paramAsBooleanOptional(String key, Boolean defaultValue) {
public Boolean paramAsBoolean(String key, Boolean defaultValue) {
return Booleans.parseBoolean(param(key), defaultValue);
}
@Override @Deprecated
public Boolean paramAsBooleanOptional(String key, Boolean defaultValue) {
return paramAsBoolean(key, defaultValue);
}
}
public static class DelegatingMapParams extends MapParams {
@ -119,6 +136,11 @@ public interface ToXContent {
}
@Override
public Boolean paramAsBoolean(String key, Boolean defaultValue) {
return super.paramAsBoolean(key, delegate.paramAsBoolean(key, defaultValue));
}
@Override @Deprecated
public Boolean paramAsBooleanOptional(String key, Boolean defaultValue) {
return super.paramAsBooleanOptional(key, delegate.paramAsBooleanOptional(key, defaultValue));
}

View File

@ -135,10 +135,15 @@ public abstract class RestRequest implements ToXContent.Params {
}
@Override
public Boolean paramAsBooleanOptional(String key, Boolean defaultValue) {
public Boolean paramAsBoolean(String key, Boolean defaultValue) {
return Booleans.parseBoolean(param(key), defaultValue);
}
@Override @Deprecated
public Boolean paramAsBooleanOptional(String key, Boolean defaultValue) {
return paramAsBoolean(key, defaultValue);
}
public TimeValue paramAsTime(String key, TimeValue defaultValue) {
return parseTimeValue(param(key), defaultValue);
}

View File

@ -76,7 +76,7 @@ public class RestExplainAction extends BaseRestHandler {
queryStringBuilder.analyzer(request.param("analyzer"));
queryStringBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
queryStringBuilder.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true));
queryStringBuilder.lenient(request.paramAsBooleanOptional("lenient", null));
queryStringBuilder.lenient(request.paramAsBoolean("lenient", null));
String defaultOperator = request.param("default_operator");
if (defaultOperator != null) {
if ("OR".equals(defaultOperator)) {

View File

@ -23,7 +23,6 @@ import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -60,7 +59,7 @@ public class RestGetAction extends BaseRestHandler {
getRequest.routing(request.param("routing")); // order is important, set it after routing, so it will set the routing
getRequest.parent(request.param("parent"));
getRequest.preference(request.param("preference"));
getRequest.realtime(request.paramAsBooleanOptional("realtime", null));
getRequest.realtime(request.paramAsBoolean("realtime", null));
String sField = request.param("fields");
if (sField != null) {

View File

@ -58,7 +58,7 @@ public class RestGetSourceAction extends BaseRestHandler {
getRequest.routing(request.param("routing")); // order is important, set it after routing, so it will set the routing
getRequest.parent(request.param("parent"));
getRequest.preference(request.param("preference"));
getRequest.realtime(request.paramAsBooleanOptional("realtime", null));
getRequest.realtime(request.paramAsBoolean("realtime", null));
getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));

View File

@ -54,7 +54,7 @@ public class RestHeadAction extends BaseRestHandler {
getRequest.routing(request.param("routing")); // order is important, set it after routing, so it will set the routing
getRequest.parent(request.param("parent"));
getRequest.preference(request.param("preference"));
getRequest.realtime(request.paramAsBooleanOptional("realtime", null));
getRequest.realtime(request.paramAsBoolean("realtime", null));
// don't get any fields back...
getRequest.fields(Strings.EMPTY_ARRAY);
// TODO we can also just return the document size as Content-Length

View File

@ -61,7 +61,7 @@ public class RestMultiGetAction extends BaseRestHandler {
multiGetRequest.listenerThreaded(false);
multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
multiGetRequest.preference(request.param("preference"));
multiGetRequest.realtime(request.paramAsBooleanOptional("realtime", null));
multiGetRequest.realtime(request.paramAsBoolean("realtime", null));
String[] sFields = null;
String sField = request.param("fields");

View File

@ -86,7 +86,7 @@ public class RestPercolateAction extends BaseRestHandler {
getRequest.routing(restRequest.param("routing"));
getRequest.preference(restRequest.param("preference"));
getRequest.refresh(restRequest.paramAsBoolean("refresh", getRequest.refresh()));
getRequest.realtime(restRequest.paramAsBooleanOptional("realtime", null));
getRequest.realtime(restRequest.paramAsBoolean("realtime", null));
getRequest.version(RestActions.parseVersion(restRequest));
getRequest.versionType(VersionType.fromString(restRequest.param("version_type"), getRequest.versionType()));

View File

@ -156,7 +156,7 @@ public class RestSearchAction extends BaseRestHandler {
queryBuilder.analyzer(request.param("analyzer"));
queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
queryBuilder.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true));
queryBuilder.lenient(request.paramAsBooleanOptional("lenient", null));
queryBuilder.lenient(request.paramAsBoolean("lenient", null));
String defaultOperator = request.param("default_operator");
if (defaultOperator != null) {
if ("OR".equals(defaultOperator)) {
@ -192,13 +192,13 @@ public class RestSearchAction extends BaseRestHandler {
if (searchSourceBuilder == null) {
searchSourceBuilder = new SearchSourceBuilder();
}
searchSourceBuilder.explain(request.paramAsBooleanOptional("explain", null));
searchSourceBuilder.explain(request.paramAsBoolean("explain", null));
}
if (request.hasParam("version")) {
if (searchSourceBuilder == null) {
searchSourceBuilder = new SearchSourceBuilder();
}
searchSourceBuilder.version(request.paramAsBooleanOptional("version", null));
searchSourceBuilder.version(request.paramAsBoolean("version", null));
}
if (request.hasParam("timeout")) {
if (searchSourceBuilder == null) {