List of usage examples for org.apache.commons.collections.map ReferenceMap ReferenceMap
public ReferenceMap(int keyType, int valueType, boolean purgeValues)
ReferenceMap
that will use the specified types of references. From source file:com.google.gwt.dev.javac.TypeOracleMediatorTestBase.java
/** * Tests which variant of AbstractRefrenceMap we want to store the map for * parameterizedTypes, arrayTypes, and wildCardTypes in TypeOracle. Note: this * test is manual because gc can be unreliable. *//*from w ww. j a v a 2 s . c o m*/ @SuppressWarnings("unchecked") public void manualTestAbstractRefrenceMap() { /* * with a HARD -> WEAK map, verify that the entry remains if there is no * reference to key, but is deleted when the reference to value is gone */ Map<Integer, Integer> simpleMap = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK, true); Integer bar = new Integer(42); simpleMap.put(new Integer(32), bar); Runtime.getRuntime().gc(); assertEquals(1, simpleMap.size()); bar = null; Runtime.getRuntime().gc(); assertEquals(0, simpleMap.size()); /* * with a WEAK -> WEAK map, verify that the entry is gone if there are no * references to either the key or the value. */ simpleMap = new ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK, true); Map<Integer, Integer> reverseMap = new ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK, true); Integer foo = new Integer(32); bar = new Integer(42); simpleMap.put(foo, bar); reverseMap.put(bar, foo); Runtime.getRuntime().gc(); assertEquals(1, simpleMap.size()); assertEquals(1, reverseMap.size()); bar = null; Runtime.getRuntime().gc(); assertEquals(0, simpleMap.size()); assertEquals(0, reverseMap.size()); }
From source file:org.apache.myfaces.ext202patch.application.viewstate.SerializedViewCollection.java
/** * @return old serialized views map//from w w w.j av a 2s . c o m */ @SuppressWarnings("unchecked") protected Map<Object, Object> getOldSerializedViewsMap() { FacesContext context = FacesContext.getCurrentInstance(); if (_oldSerializedViews == null && context != null) { String cacheMode = getCacheOldViewsInSessionMode(context); if (ServerSideStateCacheImpl.CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK.equals(cacheMode)) { _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK, true); } else if (ServerSideStateCacheImpl.CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK.equals(cacheMode)) { _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK, true); } else if (ServerSideStateCacheImpl.CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT.equals(cacheMode)) { _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT, true); } else if (ServerSideStateCacheImpl.CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT.equals(cacheMode)) { _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT); } } return _oldSerializedViews; }
From source file:org.seasar.mayaa.impl.engine.PageImpl.java
protected Map getBeginRenderListeners() { synchronized (this) { if (_beginRenderListeners == null) { _beginRenderListeners = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK, true);/*from w w w. ja v a 2 s .c o m*/ } } return _beginRenderListeners; }