use of com.google.common.base.MoreObjects.ToStringHelper in project arctic-sea by 52North.
the class MultilingualString method toString.
@Override
public String toString() {
ToStringHelper h = MoreObjects.toStringHelper(this).omitNullValues();
getLocalizations().forEach((key, value) -> h.add(key.toString(), value.getText()));
return h.toString();
}
use of com.google.common.base.MoreObjects.ToStringHelper in project gerrit by GerritCodeReview.
the class Metadata method toStringForLoggingImpl.
private String toStringForLoggingImpl() {
// Append class name.
String className = getClass().getSimpleName();
if (className.startsWith("AutoValue_")) {
className = className.substring(10);
}
ToStringHelper stringHelper = MoreObjects.toStringHelper(className);
// Append key-value pairs for field which are set.
Method[] methods = Metadata.class.getDeclaredMethods();
Arrays.sort(methods, Comparator.comparing(Method::getName));
for (Method method : methods) {
if (Modifier.isStatic(method.getModifiers())) {
// skip static method
continue;
}
if (method.getName().equals("toStringForLoggingLazy") || method.getName().equals("toStringForLoggingImpl")) {
// Don't call myself in infinite recursion.
continue;
}
if (method.getReturnType().equals(Void.TYPE) || method.getParameterCount() > 0) {
// skip method since it's not a getter
continue;
}
method.setAccessible(true);
Object returnValue;
try {
returnValue = method.invoke(this);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
// should never happen
throw new IllegalStateException(e);
}
if (returnValue instanceof Optional) {
Optional<?> fieldValueOptional = (Optional<?>) returnValue;
if (!fieldValueOptional.isPresent()) {
// drop this key-value pair
continue;
}
// format as 'key=value' instead of 'key=Optional[value]'
stringHelper.add(method.getName(), fieldValueOptional.get());
} else {
// not an Optional value, keep as is
stringHelper.add(method.getName(), returnValue);
}
}
return stringHelper.toString();
}
use of com.google.common.base.MoreObjects.ToStringHelper in project snow-owl by b2ihealthcare.
the class ResourceRequest method toString.
@Override
public final String toString() {
ToStringHelper toStringHelper = MoreObjects.toStringHelper(getClass()).add("change", change).add("commitComment", commitComment);
doToString(toStringHelper);
return toStringHelper.toString();
}
use of com.google.common.base.MoreObjects.ToStringHelper in project gerrit by GerritCodeReview.
the class Event method toString.
@Override
public String toString() {
ToStringHelper helper = MoreObjects.toStringHelper(this).add("psId", psId).add("effectiveUser", user).add("realUser", realUser).add("when", when).add("tag", tag);
addToString(helper);
return helper.toString();
}
use of com.google.common.base.MoreObjects.ToStringHelper in project google-cloud-java by GoogleCloudPlatform.
the class Cursor method toString.
@Override
public String toString() {
ToStringHelper toStringHelper = MoreObjects.toStringHelper(this);
StringBuilder stBuilder = new StringBuilder();
for (int i = 0; i < byteString.size(); i++) {
stBuilder.append(String.format("%02x", byteString.byteAt(i)));
}
return toStringHelper.add("bytes", stBuilder.toString()).toString();
}
Aggregations