Skip to content

Commit

Permalink
OAK-11194 : replaced usage of MoreObjects.ToStringHelper with StringJ…
Browse files Browse the repository at this point in the history
…oiner
  • Loading branch information
Rishabh Kumar committed Dec 16, 2024
1 parent cb77390 commit d4dcc7e
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -61,7 +62,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.guava.common.base.MoreObjects.toStringHelper;
import static java.lang.String.format;
import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount;
import static org.apache.jackrabbit.oak.plugins.blob.DataStoreCacheUpgradeUtils
Expand Down Expand Up @@ -774,18 +774,18 @@ public long estimateCurrentMemoryWeight() {

@Override
public String cacheInfoAsString() {
return toStringHelper("StagingCacheStats")
.add("requestCount", getRequestCount())
.add("hitCount", getHitCount())
.add("hitRate", format("%1.2f", getHitRate()))
.add("missCount", getMissCount())
.add("missRate", format("%1.2f", getMissRate()))
.add("loadCount", getLoadCount())
.add("loadSuccessCount", getLoadSuccessCount())
.add("elementCount", getElementCount())
.add("currentMemSize", estimateCurrentMemoryWeight())
.add("totalWeight", humanReadableByteCount(estimateCurrentWeight()))
.add("maxWeight", humanReadableByteCount(getMaxTotalWeight()))
return new StringJoiner(", ", "StagingCacheStats + [", "]")
.add("requestCount=" + getRequestCount())
.add("hitCount=" + getHitCount())
.add("hitRate=" + format("%1.2f", getHitRate()))
.add("missCount=" + getMissCount())
.add("missRate=" + format("%1.2f", getMissRate()))
.add("loadCount=" + getLoadCount())
.add("loadSuccessCount=" + getLoadSuccessCount())
.add("elementCount=" + getElementCount())
.add("currentMemSize=" + estimateCurrentMemoryWeight())
.add("totalWeight=" + humanReadableByteCount(estimateCurrentWeight()))
.add("maxWeight=" + humanReadableByteCount(getMaxTotalWeight()))
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount;

import java.util.Objects;
import java.util.StringJoiner;
import java.util.concurrent.TimeUnit;

import org.apache.jackrabbit.guava.common.base.MoreObjects;
import org.apache.jackrabbit.guava.common.cache.CacheStats;
import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
import org.apache.jackrabbit.oak.commons.jmx.AnnotatedStandardMBean;
Expand Down Expand Up @@ -135,21 +135,21 @@ public long getEvictionCount() {

@Override
public String cacheInfoAsString() {
return MoreObjects.toStringHelper("CacheStats")
.add("hitCount", getHitCount())
.add("hitRate", format("%1.2f", getHitRate()))
.add("missCount", getMissCount())
.add("missRate", format("%1.2f", getMissRate()))
.add("requestCount", getRequestCount())
.add("loadCount", getLoadCount())
.add("loadSuccessCount", getLoadSuccessCount())
.add("loadExceptionCount", getLoadExceptionCount())
.add("totalLoadTime", timeInWords(getTotalLoadTime()))
.add("averageLoadPenalty", format("%1.2f ns", getAverageLoadPenalty()))
.add("evictionCount", getEvictionCount())
.add("elementCount", getElementCount())
.add("totalWeight", humanReadableByteCount(estimateCurrentWeight()))
.add("maxWeight", humanReadableByteCount(getMaxTotalWeight()))
return new StringJoiner(", ", "CacheStats [", "]")
.add("hitCount=" + getHitCount())
.add("hitRate=" + format("%1.2f", getHitRate()))
.add("missCount=" + getMissCount())
.add("missRate=" + format("%1.2f", getMissRate()))
.add("requestCount=" + getRequestCount())
.add("loadCount=" + getLoadCount())
.add("loadSuccessCount=" + getLoadSuccessCount())
.add("loadExceptionCount=" + getLoadExceptionCount())
.add("totalLoadTime=" + timeInWords(getTotalLoadTime()))
.add("averageLoadPenalty=" + format("%1.2f ns", getAverageLoadPenalty()))
.add("evictionCount=" + getEvictionCount())
.add("elementCount=" + getElementCount())
.add("totalWeight=" + humanReadableByteCount(estimateCurrentWeight()))
.add("maxWeight=" + humanReadableByteCount(getMaxTotalWeight()))
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.jackrabbit.oak.commons.jmx;

import static org.apache.jackrabbit.guava.common.base.MoreObjects.toStringHelper;
import static java.lang.Thread.currentThread;
import static javax.management.openmbean.SimpleType.INTEGER;
import static javax.management.openmbean.SimpleType.STRING;
Expand All @@ -36,6 +35,7 @@
import static org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status.succeeded;

import java.util.Objects;
import java.util.StringJoiner;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
Expand Down Expand Up @@ -218,9 +218,9 @@ public Status getStatus() {

@Override
public String toString() {
return toStringHelper(this)
.add("name", name)
.add("id", id)
return new StringJoiner(", ", ManagementOperation.class.getSimpleName() + "[", "]")
.add("name=" + name)
.add("id=" + id)
.toString();
}

Expand Down Expand Up @@ -407,10 +407,10 @@ public boolean isFailure() {

@Override
public String toString() {
return toStringHelper(this)
.addValue(code)
.add("id", id)
.add("message", message)
return new StringJoiner(", ", Status.class.getSimpleName() + "[", "]")
.add("code=" + code)
.add("id=" + id)
.add("message=" + message)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
package org.apache.jackrabbit.oak.plugins.observation.filter;

import static org.apache.jackrabbit.guava.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.oak.commons.PathUtils.elements;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import java.util.regex.Pattern;

import org.apache.jackrabbit.guava.common.collect.Iterators;
Expand Down Expand Up @@ -177,8 +177,8 @@ public EventFilter create(String name, NodeState before, NodeState after) {

@Override
public String toString() {
return toStringHelper(this)
.add("path", String.join("/", pattern))
return new StringJoiner(", ", GlobbingPathFilter.class.getSimpleName() + "[", "]")
.add("path=" + String.join("/", pattern))
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.jcr.delegate;

import static org.apache.jackrabbit.guava.common.base.MoreObjects.toStringHelper;
import static org.apache.jackrabbit.guava.common.collect.Iterables.addAll;
import static org.apache.jackrabbit.guava.common.collect.Iterables.contains;
import static org.apache.jackrabbit.guava.common.collect.Iterators.filter;
Expand Down Expand Up @@ -60,6 +59,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Function;

import javax.jcr.InvalidItemStateException;
Expand Down Expand Up @@ -862,7 +862,9 @@ public void unlock() throws RepositoryException {

@Override
public String toString() {
return toStringHelper(this).add("tree", tree).toString();
return new StringJoiner(", ", NodeDelegate.class.getSimpleName() + "[", "]")
.add("tree=" + tree)
.toString();
}

//------------------------------------------------------------< internal >---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.jcr.delegate;

import static org.apache.jackrabbit.guava.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;

import javax.jcr.InvalidItemStateException;
Expand All @@ -30,6 +29,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.StringJoiner;

/**
* {@code PropertyDelegate} serve as internal representations of {@code Property}s.
* Most methods of this class throw an {@code InvalidItemStateException}
Expand Down Expand Up @@ -158,9 +159,9 @@ public boolean remove() {

@Override
public String toString() {
return toStringHelper(this)
.add("parent", parent)
.add("property", parent.getProperty(name))
return new StringJoiner(", ", PropertyDelegate.class.getSimpleName() + "[", "]")
.add("parent=" + parent)
.add("property=" + parent.getProperty(name))
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.StringJoiner;

import javax.jcr.Value;
import javax.jcr.observation.Event;

import org.apache.jackrabbit.guava.common.base.MoreObjects;

import org.apache.jackrabbit.api.observation.JackrabbitEvent;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.blob.BlobAccessProvider;
Expand Down Expand Up @@ -328,15 +327,15 @@ public int hashCode() {

@Override
public String toString() {
return MoreObjects.toStringHelper("Event")
.add("type", getType())
.add("path", getPath())
.add("identifier", getIdentifier())
.add("info", getInfo())
.add("userID", getUserID())
.add("userData", getUserData())
.add("date", getDate())
.add("external", isExternal())
return new StringJoiner(", ", "Event [", "]")
.add("type=" + getType())
.add("path=" + getPath())
.add("identifier=" + getIdentifier())
.add("info=" + getInfo())
.add("userID=" + getUserID())
.add("userData=" + getUserData())
.add("date=" + getDate())
.add("external=" + isExternal())
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.apache.jackrabbit.guava.common.base.MoreObjects.toStringHelper;
import java.util.StringJoiner;

import static org.apache.jackrabbit.oak.commons.conditions.Validate.checkArgument;
import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
import static org.apache.jackrabbit.oak.commons.PathUtils.isAbsolute;
Expand Down Expand Up @@ -140,7 +141,9 @@ public PropertyState getProperty() {

@Override
public String toString() {
return toStringHelper(this).add("path", getPath()).toString();
return new StringJoiner(", ", TreeLocation.class.getSimpleName() + "[", "]")
.add("path=" + getPath())
.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;

import javax.jcr.SimpleCredentials;
import javax.security.auth.Subject;

import org.apache.jackrabbit.guava.common.base.MoreObjects;
import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.oak.api.AuthInfo;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -64,10 +64,11 @@ public static AuthInfo createFromSubject(@NotNull Subject subject) {

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("userID", userID)
.add("attributes", attributes)
.add("principals", principals).toString();
return new StringJoiner(", ", AuthInfoImpl.class.getSimpleName() + "[", "]")
.add("userID=" + userID)
.add("attributes=" + attributes)
.add("principals=" + principals)
.toString();
}

//-----------------------------------------------------------< AuthInfo >---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.plugins.document.persistentCache;

import org.apache.jackrabbit.guava.common.base.MoreObjects;
import org.apache.jackrabbit.api.stats.TimeSeries;
import org.apache.jackrabbit.oak.api.jmx.PersistentCacheStatsMBean;
import org.apache.jackrabbit.oak.commons.IOUtils;
Expand All @@ -31,6 +30,7 @@

import javax.management.openmbean.CompositeData;
import java.util.Map;
import java.util.StringJoiner;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

Expand Down Expand Up @@ -450,16 +450,16 @@ public CompositeData getUsedSpaceHistory() {

@Override
public String cacheInfoAsString() {
return MoreObjects.toStringHelper("PersistentCacheStats")
.add("requestCount", getRequestCount())
.add("hitCount", getHitCount())
.add("hitRate", String.format("%1.2f", getHitRate()))
.add("missCount", getMissCount())
.add("missRate", String.format("%1.2f", getMissRate()))
.add("loadCount", getLoadCount())
.add("loadSuccessCount", getLoadSuccessCount())
.add("loadExceptionCount", getLoadExceptionCount())
.add("totalWeight", IOUtils.humanReadableByteCount(estimateCurrentWeight()))
return new StringJoiner(", ", "PersistentCacheStats [", "]")
.add("requestCount=" + getRequestCount())
.add("hitCount=" + getHitCount())
.add("hitRate=" + String.format("%1.2f", getHitRate()))
.add("missCount=" + getMissCount())
.add("missRate=" + String.format("%1.2f", getMissRate()))
.add("loadCount=" + getLoadCount())
.add("loadSuccessCount=" + getLoadSuccessCount())
.add("loadExceptionCount=" + getLoadExceptionCount())
.add("totalWeight=" + IOUtils.humanReadableByteCount(estimateCurrentWeight()))
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import java.util.concurrent.TimeUnit;

import org.apache.jackrabbit.guava.common.base.MoreObjects;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientURI;
Expand Down Expand Up @@ -159,17 +159,16 @@ public static MongoClientOptions.Builder getDefaultBuilder() {
}

public static String toString(MongoClientOptions opts) {
return MoreObjects.toStringHelper(opts)
.add("connectionsPerHost", opts.getConnectionsPerHost())
.add("connectTimeout", opts.getConnectTimeout())
.add("socketTimeout", opts.getSocketTimeout())
.add("socketKeepAlive", opts.isSocketKeepAlive())
.add("maxWaitTime", opts.getMaxWaitTime())
.add("heartbeatFrequency", opts.getHeartbeatFrequency())
.add("threadsAllowedToBlockForConnectionMultiplier",
opts.getThreadsAllowedToBlockForConnectionMultiplier())
.add("readPreference", opts.getReadPreference().getName())
.add("writeConcern", opts.getWriteConcern())
return new StringJoiner(", ", opts.getClass().getSimpleName() + "[", "]")
.add("connectionsPerHost=" + opts.getConnectionsPerHost())
.add("connectTimeout=" + opts.getConnectTimeout())
.add("socketTimeout=" + opts.getSocketTimeout())
.add("socketKeepAlive=" + opts.isSocketKeepAlive())
.add("maxWaitTime=" + opts.getMaxWaitTime())
.add("heartbeatFrequency=" + opts.getHeartbeatFrequency())
.add("threadsAllowedToBlockForConnectionMultiplier=" + opts.getThreadsAllowedToBlockForConnectionMultiplier())
.add("readPreference=" + opts.getReadPreference().getName())
.add("writeConcern=" + opts.getWriteConcern())
.toString();
}

Expand Down
Loading

0 comments on commit d4dcc7e

Please sign in to comment.