Search in sources :

Example 6 with ToStringHelper

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();
}
Also used : ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper)

Example 7 with ToStringHelper

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();
}
Also used : Optional(java.util.Optional) Method(java.lang.reflect.Method) ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with ToStringHelper

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();
}
Also used : ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper)

Example 9 with ToStringHelper

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();
}
Also used : ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper)

Example 10 with ToStringHelper

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();
}
Also used : ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper)

Aggregations

ToStringHelper (com.google.common.base.MoreObjects.ToStringHelper)23 Logger (com.facebook.airlift.log.Logger)1 FINAL (com.facebook.presto.bytecode.Access.FINAL)1 PRIVATE (com.facebook.presto.bytecode.Access.PRIVATE)1 PUBLIC (com.facebook.presto.bytecode.Access.PUBLIC)1 Access.a (com.facebook.presto.bytecode.Access.a)1 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)1 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)1 CallSiteBinder (com.facebook.presto.bytecode.CallSiteBinder)1 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)1 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)1 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)1 Parameter (com.facebook.presto.bytecode.Parameter)1 Parameter.arg (com.facebook.presto.bytecode.Parameter.arg)1 ParameterizedType (com.facebook.presto.bytecode.ParameterizedType)1 ParameterizedType.type (com.facebook.presto.bytecode.ParameterizedType.type)1 Scope (com.facebook.presto.bytecode.Scope)1 Variable (com.facebook.presto.bytecode.Variable)1 ForLoop (com.facebook.presto.bytecode.control.ForLoop)1 IfStatement (com.facebook.presto.bytecode.control.IfStatement)1