From 22282e9d56bcbf61c826f0888e189fa25a56ae60 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 31 Jan 2017 20:15:08 +0100 Subject: [PATCH] cleanup toString() methods Original commit: elastic/x-pack-elasticsearch@17a10ea68f5626a058c64b488183516202e6ff90 --- .../xpack/ml/action/GetBucketsAction.java | 13 ++--------- .../xpack/ml/action/GetDatafeedsAction.java | 17 +++----------- .../ml/action/GetDatafeedsStatsAction.java | 17 +++----------- .../xpack/ml/action/GetFiltersAction.java | 13 ++--------- .../xpack/ml/action/GetInfluencersAction.java | 13 ++--------- .../xpack/ml/action/GetJobsAction.java | 19 ++++----------- .../xpack/ml/action/GetJobsStatsAction.java | 15 ++---------- .../ml/action/GetModelSnapshotsAction.java | 23 +++++-------------- .../xpack/ml/action/GetRecordsAction.java | 15 ++---------- .../xpack/ml/action/PutJobAction.java | 15 +++--------- .../ml/action/RevertModelSnapshotAction.java | 15 ++---------- .../ml/action/UpdateModelSnapshotAction.java | 19 ++++----------- .../xpack/ml/datafeed/Datafeed.java | 13 ++--------- .../xpack/ml/job/config/Job.java | 12 +--------- .../xpack/ml/job/metadata/Allocation.java | 13 ++--------- 15 files changed, 40 insertions(+), 192 deletions(-) diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java index 76517fc94f3..e91b3df882c 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java @@ -16,6 +16,7 @@ import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -24,7 +25,6 @@ import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -375,18 +375,9 @@ public class GetBucketsAction extends Action { return Objects.equals(model, other.model); } - @SuppressWarnings("deprecation") @Override public final String toString() { - try { - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.prettyPrint(); - builder.startObject(); - toXContent(builder, EMPTY_PARAMS); - builder.endObject(); - return builder.string(); - } catch (Exception e) { - // So we have a stack trace logged somewhere - return "{ \"error\" : \"" + org.elasticsearch.ExceptionsHelper.detailedMessage(e) + "\"}"; - } + return Strings.toString(this); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/datafeed/Datafeed.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/datafeed/Datafeed.java index 914384a3afc..0771f887c0a 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/datafeed/Datafeed.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/datafeed/Datafeed.java @@ -7,13 +7,13 @@ package org.elasticsearch.xpack.ml.datafeed; import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; import java.io.IOException; import java.util.Objects; @@ -94,17 +94,8 @@ public class Datafeed extends AbstractDiffable implements ToXContent { } // Class already extends from AbstractDiffable, so copied from ToXContentToBytes#toString() - @SuppressWarnings("deprecation") @Override public final String toString() { - try { - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.prettyPrint(); - toXContent(builder, EMPTY_PARAMS); - return builder.string(); - } catch (Exception e) { - // So we have a stack trace logged somewhere - return "{ \"error\" : \"" + org.elasticsearch.ExceptionsHelper.detailedMessage(e) + "\"}"; - } + return Strings.toString(this); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Job.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Job.java index 61a7a305869..0acbc26cb80 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Job.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Job.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser.ValueType; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.xpack.ml.job.messages.Messages; import org.elasticsearch.xpack.ml.utils.MlStrings; @@ -509,18 +508,9 @@ public class Job extends AbstractDiffable implements Writeable, ToXContent } // Class alreadt extends from AbstractDiffable, so copied from ToXContentToBytes#toString() - @SuppressWarnings("deprecation") @Override public final String toString() { - try { - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.prettyPrint(); - toXContent(builder, EMPTY_PARAMS); - return builder.string(); - } catch (Exception e) { - // So we have a stack trace logged somewhere - return "{ \"error\" : \"" + org.elasticsearch.ExceptionsHelper.detailedMessage(e) + "\"}"; - } + return Strings.toString(this); } private static void checkValueNotLessThan(long minVal, String name, Long value) { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/metadata/Allocation.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/metadata/Allocation.java index 14d7b2fb5ee..816484284fa 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/metadata/Allocation.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/metadata/Allocation.java @@ -7,12 +7,12 @@ package org.elasticsearch.xpack.ml.job.metadata; import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.xpack.ml.job.config.Job; import org.elasticsearch.xpack.ml.job.config.JobStatus; @@ -127,18 +127,9 @@ public class Allocation extends AbstractDiffable implements ToXConte } // Class already extends from AbstractDiffable, so copied from ToXContentToBytes#toString() - @SuppressWarnings("deprecation") @Override public final String toString() { - try { - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.prettyPrint(); - toXContent(builder, EMPTY_PARAMS); - return builder.string(); - } catch (Exception e) { - // So we have a stack trace logged somewhere - return "{ \"error\" : \"" + org.elasticsearch.ExceptionsHelper.detailedMessage(e) + "\"}"; - } + return Strings.toString(this); } public static class Builder {