Example usage for java.lang.ref WeakReference WeakReference

List of usage examples for java.lang.ref WeakReference WeakReference

Introduction

In this page you can find the example usage for java.lang.ref WeakReference WeakReference.

Prototype

public WeakReference(T referent) 

Source Link

Document

Creates a new weak reference that refers to the given object.

Usage

From source file:antre.TypeResolver.java

private static Map<TypeVariable<?>, Type> getTypeVariableMap(final Class<?> targetType) {
    Reference<Map<TypeVariable<?>, Type>> ref = typeVariableCache.get(targetType);
    Map<TypeVariable<?>, Type> map = ref != null ? ref.get() : null;

    if (map == null) {
        map = new HashMap<TypeVariable<?>, Type>();

        // Populate interfaces
        buildTypeVariableMap(targetType.getGenericInterfaces(), map);

        // Populate super classes and interfaces
        Type genericType = targetType.getGenericSuperclass();
        Class<?> type = targetType.getSuperclass();
        while (type != null && !Object.class.equals(type)) {
            if (genericType instanceof ParameterizedType)
                buildTypeVariableMap((ParameterizedType) genericType, map);
            buildTypeVariableMap(type.getGenericInterfaces(), map);

            genericType = type.getGenericSuperclass();
            type = type.getSuperclass();
        }/*from   ww w .java2  s.co  m*/

        // Populate enclosing classes
        type = targetType;
        while (type.isMemberClass()) {
            genericType = type.getGenericSuperclass();
            if (genericType instanceof ParameterizedType)
                buildTypeVariableMap((ParameterizedType) genericType, map);

            type = type.getEnclosingClass();
        }

        if (cacheEnabled)
            typeVariableCache.put(targetType, new WeakReference<Map<TypeVariable<?>, Type>>(map));
    }

    return map;
}

From source file:ch.entwine.weblounge.common.impl.request.WebloungeResponseImpl.java

/**
 * Sets the service that is used to cache responses to clients.
 * // w  w  w .j a v  a  2s .  c  om
 * @param cache
 *          the cache
 */
public void setResponseCache(ResponseCache cache) {
    this.cache = new WeakReference<ResponseCache>(cache);
}

From source file:ca.etsmtl.applets.etsmobile.ScheduleActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.calendar_view);
    TestFlight.passCheckpoint(this.getClass().getName());
    creds = new UserCredentials(PreferenceManager.getDefaultSharedPreferences(this));
    // get data async
    handler = new CalendarTaskHandler(this);
    new CalendarTaskMonth(handler).execute(creds);

    // set the navigation bar
    navBar = (NavBar) findViewById(R.id.navBar1);
    navBar.setTitle(R.drawable.navbar_horaire_title);

    // set the gridview containing the day names
    final String[] day_names = getResources().getStringArray(R.array.day_names);

    final GridView grid = (GridView) findViewById(R.id.gridDayNames);
    grid.setAdapter(new ArrayAdapter<String>(this, R.layout.day_name, day_names));

    // set next and previous buttons
    final ImageButton btn_previous = (ImageButton) findViewById(R.id.btn_previous);
    final ImageButton btn_next = (ImageButton) findViewById(R.id.btn_next);

    btn_previous.setOnClickListener(new View.OnClickListener() {
        @Override/*  www.  jav a2  s.  co m*/
        public void onClick(final View v) {
            currentCalendar.previousMonth();
        }
    });
    btn_next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            currentCalendar.nextMonth();
        }
    });

    // set the calendar view
    currentGridView = (NumGridView) findViewById(R.id.calendar_view);
    currentGridView.setOnCellTouchListener(mNumGridView_OnCellTouchListener);

    // assignation des session dja en mmoire
    currentGridView.setSessions(ETSMobileApp.getInstance().getSessionsFromPrefs());

    // Affiche le mois courant
    final CalendarTextView txtcalendar_title = (CalendarTextView) findViewById(R.id.calendar_title);

    // initialisation des observers
    currentCalendar = new CurrentCalendar();

    currentCalendar.addObserver(currentGridView);
    currentCalendar.addObserver(txtcalendar_title);

    txtcalendar_title.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            new DatePickerFragment(new WeakReference<ScheduleActivity>(ScheduleActivity.this))
                    .show(getSupportFragmentManager(), "date-frag-tag");
        }
    });
    currentCalendar.setChanged();
    currentCalendar.notifyObservers(currentCalendar.getCalendar());

    Log.v("ScheduleActivity", "ScheduleActivity: lst_cours=" + lst_cours);
    lst_cours = (CalendarEventsListView) findViewById(R.id.lst_cours);
    currentGridView.getCurrentCell().addObserver(lst_cours);
    currentGridView.getCurrentCell().setChanged();
    currentGridView.getCurrentCell().notifyObservers();

    navBar.setRightButtonText(R.string.Ajourdhui);
    navBar.showRightButton();
    navBar.setRightButtonAction(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            currentGridView.getCurrentCell().deleteObservers();
            currentGridView.setCurrentCell(null);

            currentCalendar.setToday();

            currentGridView.getCurrentCell().addObserver(lst_cours);
            currentGridView.getCurrentCell().setChanged();
            currentGridView.getCurrentCell().notifyObservers();
        }
    });
}

From source file:com.devexweb.googlemapsapi.lib.BottomSheetBehaviorGoogleMapsLike.java

@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    // First let the parent lay it out
    if (mState != STATE_DRAGGING && mState != STATE_SETTLING) {
        if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) {
            ViewCompat.setFitsSystemWindows(child, true);
        }/*from  w w  w.  java 2  s . c om*/
        parent.onLayoutChild(child, layoutDirection);
    }
    // Offset the bottom sheet
    mParentHeight = parent.getHeight();
    mMinOffset = Math.max(0, mParentHeight - child.getHeight());
    mMaxOffset = Math.max(mParentHeight - mPeekHeight, mMinOffset);

    /**
     * Old behavior
     */
    //        if (mState == STATE_EXPANDED) {
    //            ViewCompat.offsetTopAndBottom(child, mMinOffset);
    //        } else if (mHideable && mState == STATE_HIDDEN...
    /**
     * New behavior
     */
    if (mState == STATE_ANCHOR_POINT) {
        ViewCompat.offsetTopAndBottom(child, mAnchorPoint);
    } else if (mState == STATE_EXPANDED) {
        ViewCompat.offsetTopAndBottom(child, mMinOffset);
    } else if (mHideable && mState == STATE_HIDDEN) {
        ViewCompat.offsetTopAndBottom(child, mParentHeight);
    } else if (mState == STATE_COLLAPSED) {
        ViewCompat.offsetTopAndBottom(child, mMaxOffset);
    }
    if (mViewDragHelper == null) {
        mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
    }
    mViewRef = new WeakReference<>(child);
    mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
    return true;
}

From source file:com.bekwam.examples.javafx.oldscores.ScoresDialogController.java

public void setMainViewRef(MainViewController mainView) {
    mainViewRef = new WeakReference<MainViewController>(mainView);
}

From source file:com.geely.testbottomsheets.CustomBottomSheetBehavior.java

@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    // First let the parent lay it out
    if (mState != STATE_DRAGGING && mState != STATE_SETTLING) {
        if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) {
            ViewCompat.setFitsSystemWindows(child, true);
        }/*from  w  w w. j  a v  a 2  s.com*/
        parent.onLayoutChild(child, layoutDirection);
    }
    // Offset the bottom sheet
    mParentHeight = parent.getHeight();
    mMinOffset = Math.max(0, mParentHeight - child.getHeight());
    mMaxOffset = Math.max(mParentHeight - mPeekHeight, mMinOffset);

    /**
     * Old behavior
     */
    //        if (mState == STATE_EXPANDED) {
    //            ViewCompat.offsetTopAndBottom(child, mMinOffset);
    //        } else if (mHideable && mState == STATE_HIDDEN...

    childView = child;
    /**
     * New behavior
     */
    if (mState == STATE_ANCHOR_POINT) {
        ViewCompat.offsetTopAndBottom(child, mAnchorPoint);
    } else if (mState == STATE_EXPANDED) {
        ViewCompat.offsetTopAndBottom(child, mMinOffset);
    } else if (mHideable && mState == STATE_HIDDEN) {
        ViewCompat.offsetTopAndBottom(child, mParentHeight);
    } else if (mState == STATE_COLLAPSED) {
        ViewCompat.offsetTopAndBottom(child, mMaxOffset);
    }
    if (mViewDragHelper == null) {
        mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
    }
    mViewRef = new WeakReference<>(child);
    mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
    return true;
}

From source file:com.bekwam.examples.javafx.oldscores1.ScoresDialogController.java

public void setMainViewRef(MainViewController mainView) {
    mainViewRef = new WeakReference<>(mainView);
}

From source file:net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer.java

protected final void setLastObject(JRVirtualizable o) {
    JRVirtualizable currentLast = lastObject();
    if (o != null && currentLast != o) {
        // lastObject is mostly an optimization, we don't care if we don't have atomic operations here
        this.lastObjectRef = new WeakReference<JRVirtualizable>(o);

        synchronized (this) {
            JRVirtualizationContext context = o.getContext();
            Object ownerLast = lastObjectMap.get(context);
            if (ownerLast != o) {
                if (ownerLast != null) {
                    lastObjectSet.remove(ownerLast);
                }/*from  www . j  a  va2  s  . co m*/
                lastObjectMap.put(context, o);
                lastObjectSet.put(o, Boolean.TRUE);
            }
        }
    }
}

From source file:com.appbase.androidquery.callback.AbstractAjaxCallback.java

/**
 * Set a callback handler with a weak reference. Use weak handler if you do not want the ajax callback to hold the handler object from garbage collection.
 * For example, if the handler is an activity, weakHandler should be used since the method shouldn't be invoked if an activity is already dead and garbage collected.
 *
 * @param handler the handler/*  w  ww. ja  v a  2s.c o m*/
 * @param callback the callback
 * @return self
 */
public K weakHandler(Object handler, String callback) {
    this.whandler = new WeakReference<Object>(handler);
    this.callback = callback;
    this.handler = null;
    return self();
}

From source file:ca.etsmtl.applets.etsmobile.ScheduleWeekActivity.java

@SuppressWarnings("deprecation")
@Override//w  w  w . j  a v a 2  s.c  o m
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.calendar_view_week);
    creds = new UserCredentials(PreferenceManager.getDefaultSharedPreferences(this));
    TestFlight.passCheckpoint(this.getClass().getName());
    // get data async
    handler = new CalendarTaskHandlerWeek(this);
    new CalendarTaskWeek(handler).execute(creds);
    // getCalendarICS();

    // set the navigation bar
    navBar = (NavBar) findViewById(R.id.navBar1);
    navBar.setTitle(R.drawable.navbar_horaire_title);

    // set the gridview containing the day names
    final String[] day_names = getResources().getStringArray(R.array.day_names_5_days_week);

    final GridView grid = (GridView) findViewById(R.id.gridDayNames);
    grid.setAdapter(new ArrayAdapter<String>(this, R.layout.day_name, day_names));

    // set next and previous buttons
    final ImageButton btn_previous = (ImageButton) findViewById(R.id.btn_previous);
    final ImageButton btn_next = (ImageButton) findViewById(R.id.btn_next);

    btn_previous.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            currentCalendar.previousWeek();
        }
    });
    btn_next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            currentCalendar.nextWeek();
        }
    });

    // set the calendar view
    currentGridView = (NumGridViewWeek) findViewById(R.id.calendar_view);
    currentGridView.setOnCellTouchListener(mNumGridViewWeek_OnCellTouchListener);

    // assignation des session dja en mmoire
    currentGridView.setSessions(ETSMobileApp.getInstance().getSessionsFromPrefs());

    // Affiche le mois courant
    final CalendarTextView txtcalendar_title = (CalendarTextView) findViewById(R.id.calendar_title);

    // initialisation des observers
    currentCalendar = new CurrentCalendar();

    currentCalendar.addObserver(currentGridView);
    currentCalendar.addObserver(txtcalendar_title);

    // set DatePicker
    // ScheduleWeekActivity.this, 0, mDateSetListener, i, j, k);
    txtcalendar_title.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            new DatePickerFragment(new WeakReference<ScheduleWeekActivity>(ScheduleWeekActivity.this))
                    .show(getSupportFragmentManager(), "");
        }
    });
    // currentCalendar.addObserver(datePickerDialog);
    currentCalendar.setChanged();
    currentCalendar.notifyObservers(currentCalendar.getCalendar());

    lst_cours = (CalendarEventsListView) findViewById(R.id.lst_cours);
    Log.v("ScheduleActivity", "ScheduleActivity: lst_cours=" + lst_cours);
    if (currentGridView != null) {
        if (currentGridView.getCurrentCell() != null) {
            Log.v("ScheduleWeekActivity",
                    "ScheduleWeekActivity: onCreate: currentGridView.getCurrentCell()!=null");
            currentGridView.getCurrentCell().addObserver(lst_cours);
            currentGridView.getCurrentCell().setChanged();
            currentGridView.getCurrentCell().notifyObservers();
        }
    }

    navBar.setRightButtonText(R.string.Ajourdhui);
    navBar.showRightButton();
    navBar.setRightButtonAction(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (currentGridView.getCurrentCell() != null) {
                currentGridView.getCurrentCell().deleteObservers();
                currentGridView.setCurrentCell(null);
            }

            currentCalendar.setToday();
            currentCalendar.setChanged();

            if (currentGridView.getCurrentCell() != null) {
                currentGridView.getCurrentCell().addObserver(lst_cours);
                currentGridView.getCurrentCell().setChanged();
                currentGridView.getCurrentCell().notifyObservers();
            } else {
                lst_cours = (CalendarEventsListView) findViewById(R.id.lst_cours);
                lst_cours.resetAdaper();
            }
        }
    });
}