Search in sources :

Example 1 with ToStringHelper

use of com.google.common.base.Objects.ToStringHelper in project jackrabbit-oak by apache.

the class PropertiesUtil method populate.

/**
     * Populates the bean properties from config instance. It supports coercing
     *  values for simple types like Number, Integer, Long, Boolean etc. Complex
     *  objects are not supported
     *
     * @param instance bean to populate
     * @param config properties to set in the passed bean
     * @param validate Flag to validate the configured bean property names against
     *                 the configured bean class
     */
@SuppressWarnings("unchecked")
public static void populate(Object instance, Map<String, ?> config, boolean validate) {
    Class<?> objectClass = instance.getClass();
    // Set all configured bean properties
    Map<String, Method> setters = getSetters(objectClass);
    ToStringHelper toStringHelper = Objects.toStringHelper(instance);
    for (Map.Entry<String, ?> e : config.entrySet()) {
        String name = e.getKey();
        Method setter = setters.get(name);
        if (setter != null) {
            if (setter.getAnnotation(Deprecated.class) != null) {
                log.warn("Parameter {} of {} has been deprecated", name, objectClass.getName());
            }
            Object value = e.getValue();
            setProperty(instance, name, setter, value);
            toStringHelper.add(name, value);
        } else if (validate) {
            throw new IllegalArgumentException("Configured class " + objectClass.getName() + " does not contain a property named " + name);
        }
    }
    log.debug("Configured object with properties {}", toStringHelper);
}
Also used : Method(java.lang.reflect.Method) ToStringHelper(com.google.common.base.Objects.ToStringHelper) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ToStringHelper

use of com.google.common.base.Objects.ToStringHelper in project double-espresso by JakeWharton.

the class Root method toString.

@Override
public String toString() {
    ToStringHelper helper = toStringHelper(this).add("application-window-token", decorView.getApplicationWindowToken()).add("window-token", decorView.getWindowToken()).add("has-window-focus", decorView.hasWindowFocus());
    if (windowLayoutParams.isPresent()) {
        helper.add("layout-params-type", windowLayoutParams.get().type).add("layout-params-string", windowLayoutParams.get());
    }
    helper.add("decor-view-string", HumanReadables.describe(decorView));
    return helper.toString();
}
Also used : ToStringHelper(com.google.common.base.Objects.ToStringHelper)

Example 3 with ToStringHelper

use of com.google.common.base.Objects.ToStringHelper in project double-espresso by JakeWharton.

the class HumanReadables method describe.

/**
   * Transforms an arbitrary view into a string with (hopefully) enough debug info.
   *
   * @param v nullable view
   * @return a string for human consumption.
   */
public static String describe(View v) {
    if (null == v) {
        return "null";
    }
    ToStringHelper helper = Objects.toStringHelper(v).add("id", v.getId());
    if (v.getId() != -1 && v.getResources() != null) {
        try {
            helper.add("res-name", v.getResources().getResourceEntryName(v.getId()));
        } catch (Resources.NotFoundException ignore) {
        // Do nothing.
        }
    }
    if (null != v.getContentDescription()) {
        helper.add("desc", v.getContentDescription());
    }
    switch(v.getVisibility()) {
        case View.GONE:
            helper.add("visibility", "GONE");
            break;
        case View.INVISIBLE:
            helper.add("visibility", "INVISIBLE");
            break;
        case View.VISIBLE:
            helper.add("visibility", "VISIBLE");
            break;
        default:
            helper.add("visibility", v.getVisibility());
    }
    helper.add("width", v.getWidth()).add("height", v.getHeight()).add("has-focus", v.hasFocus()).add("has-focusable", v.hasFocusable()).add("has-window-focus", v.hasWindowFocus()).add("is-clickable", v.isClickable()).add("is-enabled", v.isEnabled()).add("is-focused", v.isFocused()).add("is-focusable", v.isFocusable()).add("is-layout-requested", v.isLayoutRequested()).add("is-selected", v.isSelected());
    if (null != v.getRootView()) {
        // pretty much only true in unit-tests.
        helper.add("root-is-layout-requested", v.getRootView().isLayoutRequested());
    }
    EditorInfo ei = new EditorInfo();
    InputConnection ic = v.onCreateInputConnection(ei);
    boolean hasInputConnection = ic != null;
    helper.add("has-input-connection", hasInputConnection);
    if (hasInputConnection) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        Printer p = new StringBuilderPrinter(sb);
        ei.dump(p, "");
        sb.append("]");
        helper.add("editor-info", sb.toString().replace("\n", " "));
    }
    if (Build.VERSION.SDK_INT > 10) {
        helper.add("x", v.getX()).add("y", v.getY());
    }
    if (v instanceof TextView) {
        innerDescribe((TextView) v, helper);
    }
    if (v instanceof Checkable) {
        innerDescribe((Checkable) v, helper);
    }
    if (v instanceof ViewGroup) {
        innerDescribe((ViewGroup) v, helper);
    }
    return helper.toString();
}
Also used : InputConnection(android.view.inputmethod.InputConnection) EditorInfo(android.view.inputmethod.EditorInfo) ViewGroup(android.view.ViewGroup) StringBuilderPrinter(android.util.StringBuilderPrinter) TextView(android.widget.TextView) Resources(android.content.res.Resources) Checkable(android.widget.Checkable) Printer(android.util.Printer) StringBuilderPrinter(android.util.StringBuilderPrinter) ToStringHelper(com.google.common.base.Objects.ToStringHelper)

Example 4 with ToStringHelper

use of com.google.common.base.Objects.ToStringHelper in project honeycomb by altamiracorp.

the class Row method toString.

@Override
public String toString() {
    final ToStringHelper toString = Objects.toStringHelper(this.getClass());
    toString.add("Version", row.getVersion()).add("UUID", getUUID());
    for (final Map.Entry<String, ByteBuffer> entry : getRecords().entrySet()) {
        toString.add("Record", format("%s: %s", entry.getKey(), entry.getValue()));
    }
    return toString.toString();
}
Also used : ToStringHelper(com.google.common.base.Objects.ToStringHelper) Map(java.util.Map) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ToStringHelper (com.google.common.base.Objects.ToStringHelper)4 Map (java.util.Map)2 Resources (android.content.res.Resources)1 Printer (android.util.Printer)1 StringBuilderPrinter (android.util.StringBuilderPrinter)1 ViewGroup (android.view.ViewGroup)1 EditorInfo (android.view.inputmethod.EditorInfo)1 InputConnection (android.view.inputmethod.InputConnection)1 Checkable (android.widget.Checkable)1 TextView (android.widget.TextView)1 Method (java.lang.reflect.Method)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1