HADOOP-14382 Remove usages of MoreObjects.toStringHelper.

Contributed by Andrew Wang
This commit is contained in:
Steve Loughran 2017-05-05 13:03:09 +01:00
parent 97c2e576c9
commit 4e6bbd049d
No known key found for this signature in database
GPG Key ID: 950CC3E032B79CA2
9 changed files with 66 additions and 54 deletions

View File

@ -18,13 +18,14 @@
package org.apache.hadoop.metrics2; package org.apache.hadoop.metrics2;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import static com.google.common.base.Preconditions.*;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import java.util.StringJoiner;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* The immutable metric * The immutable metric
*/ */
@ -84,10 +85,11 @@ protected MetricsInfo info() {
return Objects.hashCode(info, value()); return Objects.hashCode(info, value());
} }
@Override public String toString() { @Override
return MoreObjects.toStringHelper(this) public String toString() {
.add("info", info) return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}")
.add("value", value()) .add("info=" + info)
.add("value=" + value())
.toString(); .toString();
} }
} }

View File

@ -18,13 +18,14 @@
package org.apache.hadoop.metrics2; package org.apache.hadoop.metrics2;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import static com.google.common.base.Preconditions.*;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import java.util.StringJoiner;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Immutable tag for metrics (for grouping on host/queue/username etc.) * Immutable tag for metrics (for grouping on host/queue/username etc.)
*/ */
@ -81,9 +82,9 @@ public String value() {
} }
@Override public String toString() { @Override public String toString() {
return MoreObjects.toStringHelper(this) return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}")
.add("info", info) .add("info=" + info)
.add("value", value()) .add("value=" + value())
.toString(); .toString();
} }
} }

View File

@ -18,12 +18,12 @@
package org.apache.hadoop.metrics2.impl; package org.apache.hadoop.metrics2.impl;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import org.apache.hadoop.metrics2.MetricsRecord; import org.apache.hadoop.metrics2.MetricsRecord;
import java.util.StringJoiner;
abstract class AbstractMetricsRecord implements MetricsRecord { abstract class AbstractMetricsRecord implements MetricsRecord {
@Override public boolean equals(Object obj) { @Override public boolean equals(Object obj) {
@ -44,12 +44,12 @@ abstract class AbstractMetricsRecord implements MetricsRecord {
} }
@Override public String toString() { @Override public String toString() {
return MoreObjects.toStringHelper(this) return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}")
.add("timestamp", timestamp()) .add("timestamp=" + timestamp())
.add("name", name()) .add("name=" + name())
.add("description", description()) .add("description=" + description())
.add("tags", tags()) .add("tags=" + tags())
.add("metrics", Iterables.toString(metrics())) .add("metrics=" + Iterables.toString(metrics()))
.toString(); .toString();
} }
} }

View File

@ -18,11 +18,11 @@
package org.apache.hadoop.metrics2.impl; package org.apache.hadoop.metrics2.impl;
import com.google.common.base.MoreObjects;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.metrics2.MetricsInfo; import org.apache.hadoop.metrics2.MetricsInfo;
import java.util.StringJoiner;
/** /**
* Metrics system related metrics info instances * Metrics system related metrics info instances
*/ */
@ -48,8 +48,9 @@ public enum MsInfo implements MetricsInfo {
} }
@Override public String toString() { @Override public String toString() {
return MoreObjects.toStringHelper(this) return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}")
.add("name", name()).add("description", desc) .add("name=" + name())
.add("description=" + desc)
.toString(); .toString();
} }
} }

View File

@ -18,11 +18,13 @@
package org.apache.hadoop.metrics2.lib; package org.apache.hadoop.metrics2.lib;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import static com.google.common.base.Preconditions.*;
import org.apache.hadoop.metrics2.MetricsInfo; import org.apache.hadoop.metrics2.MetricsInfo;
import java.util.StringJoiner;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Making implementing metric info a little easier * Making implementing metric info a little easier
*/ */
@ -56,8 +58,9 @@ class MetricsInfoImpl implements MetricsInfo {
} }
@Override public String toString() { @Override public String toString() {
return MoreObjects.toStringHelper(this) return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}")
.add("name", name).add("description", description) .add("name=" + name)
.add("description=" + description)
.toString(); .toString();
} }
} }

View File

@ -18,20 +18,19 @@
package org.apache.hadoop.metrics2.lib; package org.apache.hadoop.metrics2.lib;
import java.util.Collection;
import java.util.Map;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.base.MoreObjects;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.metrics2.MetricsInfo;
import org.apache.hadoop.metrics2.MetricsException; import org.apache.hadoop.metrics2.MetricsException;
import org.apache.hadoop.metrics2.MetricsInfo;
import org.apache.hadoop.metrics2.MetricsRecordBuilder; import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import org.apache.hadoop.metrics2.MetricsTag; import org.apache.hadoop.metrics2.MetricsTag;
import org.apache.hadoop.metrics2.impl.MsInfo; import org.apache.hadoop.metrics2.impl.MsInfo;
import java.util.Collection;
import java.util.Map;
import java.util.StringJoiner;
/** /**
* An optional metrics registry class for creating and maintaining a * An optional metrics registry class for creating and maintaining a
* collection of MetricsMutables, making writing metrics source easier. * collection of MetricsMutables, making writing metrics source easier.
@ -440,9 +439,12 @@ public synchronized void snapshot(MetricsRecordBuilder builder, boolean all) {
} }
} }
@Override public String toString() { @Override
return MoreObjects.toStringHelper(this) public String toString() {
.add("info", metricsInfo).add("tags", tags()).add("metrics", metrics()) return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}")
.add("info=" + metricsInfo.toString())
.add("tags=" + tags())
.add("metrics=" + metrics())
.toString(); .toString();
} }

View File

@ -21,7 +21,7 @@
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.metrics2.MetricsInfo; import org.apache.hadoop.metrics2.MetricsInfo;
import com.google.common.base.MoreObjects; import java.util.StringJoiner;
/** /**
* JVM and logging related metrics info instances * JVM and logging related metrics info instances
@ -60,8 +60,9 @@ public enum JvmMetricsInfo implements MetricsInfo {
@Override public String description() { return desc; } @Override public String description() { return desc; }
@Override public String toString() { @Override public String toString() {
return MoreObjects.toStringHelper(this) return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}")
.add("name", name()).add("description", desc) .add("name=" + name())
.toString(); .add("description=" + desc)
.toString();
} }
} }

View File

@ -18,11 +18,7 @@
package org.apache.hadoop.metrics2.util; package org.apache.hadoop.metrics2.util;
import java.util.Collection; import com.google.common.collect.Maps;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
@ -31,8 +27,11 @@
import org.apache.hadoop.metrics2.MetricsRecord; import org.apache.hadoop.metrics2.MetricsRecord;
import org.apache.hadoop.metrics2.MetricsTag; import org.apache.hadoop.metrics2.MetricsTag;
import com.google.common.base.MoreObjects; import java.util.Collection;
import com.google.common.collect.Maps; import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;
/** /**
* A metrics cache for sinks that don't support sparse updates. * A metrics cache for sinks that don't support sparse updates.
@ -127,8 +126,9 @@ public Set<Map.Entry<String, AbstractMetric>> metricsEntrySet() {
} }
@Override public String toString() { @Override public String toString() {
return MoreObjects.toStringHelper(this) return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}")
.add("tags", tags).add("metrics", metrics) .add("tags=" + tags)
.add("metrics=" + metrics)
.toString(); .toString();
} }
} }

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.metrics2.impl; package org.apache.hadoop.metrics2.impl;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.configuration2.SubsetConfiguration; import org.apache.commons.configuration2.SubsetConfiguration;
import org.apache.hadoop.metrics2.AbstractMetric; import org.apache.hadoop.metrics2.AbstractMetric;
@ -40,6 +39,7 @@
import java.net.InetAddress; import java.net.InetAddress;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.StringJoiner;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -74,8 +74,10 @@ public String description() {
@Override @Override
public String toString() { public String toString() {
return MoreObjects.toStringHelper(this).add("name", name()) return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}")
.add("description", desc).toString(); .add("name=" + name())
.add("description=" + desc)
.toString();
} }
} }