Example usage for com.google.gwt.core.client.impl WeakMapping get

List of usage examples for com.google.gwt.core.client.impl WeakMapping get

Introduction

In this page you can find the example usage for com.google.gwt.core.client.impl WeakMapping get.

Prototype

public static native Object get(Object instance, String key) ;

Source Link

Document

Returns the Object associated with the given key in the (key, value) mapping associated with the given Object instance.

Usage

From source file:com.google.web.bindery.autobean.shared.AutoBeanUtils.java

License:Apache License

/**
 * Return the single AutoBean wrapper that is observing the delegate object or
 * {@code null} if the parameter is {@code null}or not wrapped by an AutoBean.
 * /*from w  w  w.ja  v  a  2s . c  o m*/
 * @param delegate a delegate object, or {@code null}
 * @return the {@link AutoBean} wrapper for the delegate, or {@code null}
 */
@SuppressWarnings("unchecked")
public static <T, U extends T> AutoBean<T> getAutoBean(U delegate) {
    return delegate == null ? null : (AutoBean<T>) WeakMapping.get(delegate, AutoBean.class.getName());
}

From source file:com.google.web.bindery.autobean.vm.impl.JsonSplittable.java

License:Apache License

private synchronized JsonSplittable makeSplittable(Object object) {
    if (JSONObject.NULL.equals(object)) {
        return null;
    }/*  www  .j a  va 2 s . c  o m*/
    /*
     * Maintain a 1:1 mapping between object instances and JsonSplittables.
     * Doing this with a WeakHashMap doesn't work on Android, since its org.json
     * arrays appear to have value-based equality.
     */
    JsonSplittable seen = (JsonSplittable) WeakMapping.get(object, JsonSplittable.class.getName());
    if (seen == null) {
        if (object instanceof JSONObject) {
            seen = new JsonSplittable((JSONObject) object);
            WeakMapping.setWeak(object, JsonSplittable.class.getName(), seen);
        } else if (object instanceof JSONArray) {
            seen = new JsonSplittable((JSONArray) object);
            WeakMapping.setWeak(object, JsonSplittable.class.getName(), seen);
        } else if (object instanceof String) {
            seen = new JsonSplittable(object.toString());
        } else if (object instanceof Number) {
            seen = new JsonSplittable(((Number) object).doubleValue());
        } else if (object instanceof Boolean) {
            seen = new JsonSplittable((Boolean) object);
        } else {
            throw new RuntimeException("Unhandled type " + object.getClass());
        }
    }
    return seen;
}

From source file:de.csenk.gwt.commons.bean.shared.observe.ObservableBeans.java

License:Apache License

/**
 * Returns an {@link ObservableBean} for a {@code delegate} if any was previously created.
 *
 * @param delegate the delegate object.//from w w w  . j  ava 2  s .co  m
 * @return an {@link ObservableBean} instance or {@code null} if no {@link ObservableBean} could be associated with the {@code delegate}.
 */
@SuppressWarnings("unchecked")
public static <T> ObservableBean<T> get(T delegate) {
    if (delegate == null)
        return null;

    return (ObservableBean<T>) WeakMapping.get(delegate, ObservableBean.class.getName());
}