Java Code Examples for java.util.WeakHashMap
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project echo2, under directory /src/webcontainer/java/nextapp/echo2/webcontainer/.
Source file: ContainerInstance.java

/** * Sets the interval between asynchronous callbacks from the client to check for queued tasks for a given <code>TaskQueue</code>. If multiple <code>TaskQueue</code>s are active, the smallest specified interval should be used. The default interval is 500ms. Application access to this method should be accessed via the <code>ContainerContext</code>. * @param taskQueue the <code>TaskQueue</code> * @param ms the number of milliseconds between asynchronous client callbacks * @see nextapp.echo2.webcontainer.ContainerContext#setTaskQueueCallbackInterval(nextapp.echo2.app.TaskQueueHandle,int) */ public void setTaskQueueCallbackInterval(TaskQueueHandle taskQueue,int ms){ if (taskQueueToCallbackIntervalMap == null) { taskQueueToCallbackIntervalMap=new WeakHashMap(); } taskQueueToCallbackIntervalMap.put(taskQueue,new Integer(ms)); }
Example 2
From project echo3, under directory /src/server-java/webcontainer/nextapp/echo/webcontainer/.
Source file: UserInstance.java

/** * Sets the interval between asynchronous callbacks from the client to check for queued tasks for a given <code>TaskQueue</code>. If multiple <code>TaskQueue</code>s are active, the smallest specified interval should be used. The default interval is 500ms. Application access to this method should be accessed via the <code>ContainerContext</code>. * @param taskQueue the <code>TaskQueue</code> * @param ms the number of milliseconds between asynchronous client callbacks * @see nextapp.echo.webcontainer.ContainerContext#setTaskQueueCallbackInterval(nextapp.echo.app.TaskQueueHandle,int) */ public void setTaskQueueCallbackInterval(TaskQueueHandle taskQueue,int ms){ if (taskQueueToCallbackIntervalMap == null) { taskQueueToCallbackIntervalMap=new WeakHashMap(); } taskQueueToCallbackIntervalMap.put(taskQueue,new Integer(ms)); }
Example 3
From project eclipse.platform.runtime, under directory /bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/.
Source file: Expressions.java

private static synchronized boolean isSubtype(Class clazz,String type){ WeakHashMap knownClassesMap=getKnownClasses(); Map nameMap=(Map)knownClassesMap.get(clazz); if (nameMap != null) { Object obj=nameMap.get(type); if (obj != null) return ((Boolean)obj).booleanValue(); } if (nameMap == null) { nameMap=new HashMap(); knownClassesMap.put(clazz,nameMap); } boolean isSubtype=uncachedIsSubtype(clazz,type); nameMap.put(type,isSubtype ? Boolean.TRUE : Boolean.FALSE); return isSubtype; }
Example 4
From project Gemini-Blueprint, under directory /core/src/test/java/org/eclipse/gemini/blueprint/internal/service/collection/.
Source file: WeakCollectionTest.java

public void testWeakHashMap(){ Map weakMap=new WeakHashMap(); for (int i=0; i < 10; i++) { weakMap.put(new Object(),null); } GCTests.assertGCed(new WeakReference(new Object())); Set entries=weakMap.entrySet(); for (Iterator iter=entries.iterator(); iter.hasNext(); ) { Map.Entry entry=(Map.Entry)iter.next(); assertNull(entry.getKey()); } }
Example 5
From project lenya, under directory /org.apache.lenya.core.administration/src/main/java/org/apache/lenya/cms/ac/usecases/.
Source file: SessionViewer.java

/** * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters() */ protected void initParameters(){ super.initParameters(); this.getSourceURL(); SessionListener sessions=new SessionListener(); WeakHashMap allSessions=sessions.getAllSessions(); List userList=new ArrayList(); Iterator userit=allSessions.entrySet().iterator(); while (userit.hasNext()) { Map.Entry entry=(Map.Entry)userit.next(); HttpSession nextsession=(HttpSession)entry.getValue(); Identity identity=(Identity)nextsession.getAttribute(IDENTITY); if (identity == null) { continue; } User user=identity.getUser(); if (user != null) { Vector history=(Vector)nextsession.getAttribute(HISTORY); String publicationID=getPublicationIDfromHistory(history); if (publicationID.equals(getPublicationIDfromURL())) { userList.add(identity.getUser()); } } } setParameter(USERS,userList); }
Example 6
From project nuxeo-jsf, under directory /nuxeo-theme-jsf/src/main/java/org/nuxeo/theme/jsf/facelets/vendor/.
Source file: DefaultFacelet.java

public DefaultFacelet(DefaultFaceletFactory factory,ExpressionFactory el,URL src,String alias,FaceletHandler root){ this.factory=factory; this.elFactory=el; this.src=src; this.root=root; this.alias=alias; this.createTime=System.currentTimeMillis(); this.refreshPeriod=this.factory.getRefreshPeriod(); this.relativePaths=new WeakHashMap(); }
Example 7
From project mp3tunes-android, under directory /src/com/mp3tunes/android/.
Source file: MP3tunesApplication.java

public void onCreate(){ super.onCreate(); instance=this; this.map=new WeakHashMap(); SharedPreferences prefs=PrefSettings.getSharedPrefs(this); if (prefs.getString(PrefSettings.KEY_CHECK_URI,null) == null) { Editor editor=prefs.edit(); editor.putBoolean(PrefSettings.KEY_ENABLED,true); editor.putLong(PrefSettings.KEY_PERIOD,24 * 60 * 60* 1000); editor.putLong(PrefSettings.KEY_CHECK_INTERVAL,3 * 24 * 60* 60* 1000L); editor.putString(PrefSettings.KEY_CHECK_URI,"http://www.binaryelysium.com/code/mp3tunes-update.xml"); editor.commit(); } System.out.println("Doing reschedule"); Intent intent=new Intent(Veecheck.getRescheduleAction(this)); sendBroadcast(intent); }
Example 8
From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/widget/.
Source file: SuggestionsAdapter.java

/** * The amount of time we delay in the filter when the user presses the delete key. */ public SuggestionsAdapter(Context context,SearchView searchView,SearchableInfo mSearchable,WeakHashMap<String,Drawable.ConstantState> outsideDrawablesCache){ super(context,R.layout.abs__search_dropdown_item_icons_2line,null,true); mSearchManager=(SearchManager)mContext.getSystemService(Context.SEARCH_SERVICE); mProviderContext=mContext; mSearchView=searchView; mOutsideDrawablesCache=outsideDrawablesCache; }
Example 9
From project aether-core, under directory /aether-impl/src/main/java/org/eclipse/aether/internal/impl/.
Source file: DataPool.java

@SuppressWarnings("unchecked") public DataPool(RepositorySystemSession session){ RepositoryCache cache=session.getCache(); if (cache != null) { artifacts=(ObjectPool<Artifact>)cache.get(session,ARTIFACT_POOL); dependencies=(ObjectPool<Dependency>)cache.get(session,DEPENDENCY_POOL); descriptors=(Map<Object,Descriptor>)cache.get(session,DESCRIPTORS); } if (artifacts == null) { artifacts=new ObjectPool<Artifact>(); if (cache != null) { cache.put(session,ARTIFACT_POOL,artifacts); } } if (dependencies == null) { dependencies=new ObjectPool<Dependency>(); if (cache != null) { cache.put(session,DEPENDENCY_POOL,dependencies); } } if (descriptors == null) { descriptors=Collections.synchronizedMap(new WeakHashMap<Object,Descriptor>(256)); if (cache != null) { cache.put(session,DESCRIPTORS,descriptors); } } }
Example 10
From project android-database-sqlcipher, under directory /src/net/sqlcipher/database/.
Source file: SQLiteDatabase.java

/** * Private constructor. See {@link #create} and {@link #openDatabase}. * @param path The full path to the database * @param factory The factory to use when creating cursors, may be NULL. * @param flags 0 or {@link #NO_LOCALIZED_COLLATORS}. If the database file already exists, mFlags will be updated appropriately. */ public SQLiteDatabase(String path,String password,CursorFactory factory,int flags,SQLiteDatabaseHook databaseHook){ if (path == null) { throw new IllegalArgumentException("path should not be null"); } mFlags=flags; mPath=path; mSlowQueryThreshold=-1; mStackTrace=new DatabaseObjectNotClosedException().fillInStackTrace(); mFactory=factory; dbopen(mPath,mFlags); if (databaseHook != null) { databaseHook.preKey(this); } execSQL("PRAGMA key = '" + password + "'"); if (databaseHook != null) { databaseHook.postKey(this); } if (SQLiteDebug.DEBUG_SQL_CACHE) { mTimeOpened=getTime(); } mPrograms=new WeakHashMap<SQLiteClosable,Object>(); try { setLocale(Locale.getDefault()); } catch ( RuntimeException e) { Log.e(TAG,"Failed to setLocale() when constructing, closing the database",e); dbclose(); if (SQLiteDebug.DEBUG_SQL_CACHE) { mTimeClosed=getTime(); } throw e; } }
Example 11
From project androidquery, under directory /src/com/androidquery/callback/.
Source file: BitmapAjaxCallback.java

@Override public final void callback(String url,Bitmap bm,AjaxStatus status){ ImageView firstView=v.get(); WeakHashMap<ImageView,BitmapAjaxCallback> ivs=queueMap.remove(url); if (ivs == null || !ivs.containsKey(firstView)) { checkCb(this,url,firstView,bm,status); } if (ivs != null) { Set<ImageView> set=ivs.keySet(); for ( ImageView view : set) { BitmapAjaxCallback cb=ivs.get(view); cb.status=status; checkCb(cb,url,view,bm,status); } } }
Example 12
From project avro, under directory /lang/java/mapred/src/main/java/org/apache/avro/mapred/.
Source file: Pair.java

/** * Get a pair schema. */ public static Schema getPairSchema(Schema key,Schema value){ Map<Schema,Schema> valueSchemas; synchronized (SCHEMA_CACHE) { valueSchemas=SCHEMA_CACHE.get(key); if (valueSchemas == null) { valueSchemas=new WeakHashMap<Schema,Schema>(); SCHEMA_CACHE.put(key,valueSchemas); } Schema result; result=valueSchemas.get(value); if (result == null) { result=makePairSchema(key,value); valueSchemas.put(value,result); } return result; } }
Example 13
/** * Return the Configurations object for a Kit. Perfrom lazy creation of a Configuration object if nothing is created. * @param kit * @return */ public static synchronized Configuration getConfig(Class<? extends DefaultSyntaxKit> kit){ if (CONFIGS == null) { CONFIGS=new WeakHashMap<Class<? extends DefaultSyntaxKit>,Configuration>(); Configuration defaultConfig=new Configuration(DefaultSyntaxKit.class); loadConfig(defaultConfig,DefaultSyntaxKit.class); CONFIGS.put(DefaultSyntaxKit.class,defaultConfig); } if (CONFIGS.containsKey(kit)) { return CONFIGS.get(kit); } else { Class superKit=kit.getSuperclass(); @SuppressWarnings("unchecked") Configuration defaults=getConfig(superKit); Configuration mine=new Configuration(kit,defaults); loadConfig(mine,kit); CONFIGS.put(kit,mine); return mine; } }
Example 14
From project jboss-reflect, under directory /src/main/java/org/jboss/beans/info/plugins/.
Source file: AbstractBeanInfoFactory.java

public BeanInfo getBeanInfo(ClassAdapter classAdapter,BeanAccessMode accessMode){ if (classAdapter == null) throw new IllegalArgumentException("Null class adapter."); if (accessMode == null) accessMode=BeanAccessMode.STANDARD; synchronized (cache) { ClassLoader cl=classAdapter.getClassLoader(); ClassInfo classInfo=classAdapter.getClassInfo(); Map<ClassInfo,Map<BeanAccessMode,BeanInfo>> classInfoMap=cache.get(cl); Map<BeanAccessMode,BeanInfo> modeMap=null; if (classInfoMap != null) { modeMap=classInfoMap.get(classInfo); if (modeMap != null) { BeanInfo info=modeMap.get(accessMode); if (info != null) return info; } } Set<ConstructorInfo> constructors=getConstructors(classInfo); Set<MethodInfo> methods=getMethods(classInfo); Set<PropertyInfo> properties; if (classInfo.isAnnotation()) properties=getAnnotationProperties(methods); else properties=getBeanProperties(methods); Set<EventInfo> events=getEvents(classInfo); BeanInfo result=createBeanInfo(classAdapter,accessMode,properties,constructors,methods,events); if (classInfoMap == null) { classInfoMap=new WeakHashMap<ClassInfo,Map<BeanAccessMode,BeanInfo>>(); cache.put(cl,classInfoMap); } if (modeMap == null) { modeMap=new WeakValueHashMap<BeanAccessMode,BeanInfo>(); classInfoMap.put(classInfo,modeMap); } modeMap.put(accessMode,result); return result; } }
Example 15
From project LateralGM, under directory /org/lateralgm/components/mdi/.
Source file: MDIMenu.java

public MDIMenu(MDIPane pane){ super(Messages.getString("MDIMenu.WINDOW")); this.pane=pane; frameButtons=new WeakHashMap<MDIFrame,FrameButton>(); pane.addContainerListener(this); cascade=addItem("MDIMenu.CASCADE",this); arrangeIcons=addItem("MDIMenu.ARRANGE_ICONS",this); closeAll=addItem("MDIMenu.CLOSE_ALL",this); minimizeAll=addItem("MDIMenu.MINIMIZE_ALL",this); addSeparator(); close=addItem("MDIMenu.CLOSE",this); closeOthers=addItem("MDIMenu.CLOSE_OTHERS",this); addSeparator(); }
Example 16
From project ohmagePhone, under directory /src/com/google/android/imageloader/.
Source file: ImageLoader.java

/** * Creates an {@link ImageLoader}. * @param taskLimit the maximum number of background tasks that may beactive at one time. * @param streamFactory a {@link URLStreamHandlerFactory} for creatingconnections to special URLs such as {@code content://} URIs.This parameter can be {@code null} if the {@link ImageLoader}only needs to load images over HTTP or if a custom {@link URLStreamHandlerFactory} has already been passed to{@link URL#setURLStreamHandlerFactory(URLStreamHandlerFactory)} * @param bitmapHandler a {@link ContentHandler} for loading images.{@link ContentHandler#getContent(URLConnection)} must eitherreturn a {@link Bitmap} or throw an {@link IOException}. This parameter can be {@code null} to use the default{@link BitmapContentHandler}. * @param prefetchHandler a {@link ContentHandler} for caching a remote URLas a file, without parsing it or loading it into memory. {@link ContentHandler#getContent(URLConnection)} should alwaysreturn {@code null}. If the URL passed to the {@link ContentHandler} is already local (for example,{@code file://}), this {@link ContentHandler} should donothing. The {@link ContentHandler} can be {@code null} ifpre-fetching is not required. * @param cacheSize the maximum size of the image cache (in bytes). * @param handler a {@link Handler} identifying the callback thread, or{@code} null for the main thread. * @throws NullPointerException if the factory is {@code null}. */ public ImageLoader(int taskLimit,URLStreamHandlerFactory streamFactory,ContentHandler bitmapHandler,ContentHandler prefetchHandler,long cacheSize,Handler handler){ if (taskLimit < 1) { throw new IllegalArgumentException("Task limit must be positive"); } if (cacheSize < 1) { throw new IllegalArgumentException("Cache size must be positive"); } mMaxTaskCount=taskLimit; mURLStreamHandlerFactory=streamFactory; mStreamHandlers=streamFactory != null ? new HashMap<String,URLStreamHandler>() : null; mBitmapContentHandler=bitmapHandler != null ? bitmapHandler : new BitmapContentHandler(); mPrefetchContentHandler=prefetchHandler; mImageViewBinding=new WeakHashMap<ImageView,String>(); mRequests=new LinkedList<ImageRequest>(); mBitmaps=Collections.synchronizedMap(new BitmapCache<String>(cacheSize)); mErrors=Collections.synchronizedMap(new LruCache<String,ImageError>()); }
Example 17
From project openwebbeans, under directory /webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/.
Source file: OpenWebBeansEjbInterceptor.java

private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE,"interceptor instance = " + this.hashCode()); } interceptedMethodMap=new WeakHashMap<Method,List<InterceptorData>>(); nonCtxInterceptedMethodMap=new WeakHashMap<Method,List<InterceptorData>>(); resolvedBeans=new HashMap<Class<?>,BaseEjbBean<?>>(); s.defaultReadObject(); this.webBeansContext=WebBeansContext.currentInstance(); if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE,"manager = {0} interceptor_instance = {1} contextual = {2} ",WebBeansLoggerFacade.args(this.webBeansContext.getBeanManagerImpl(),this,this.contextual)); } }
Example 18
From project platform_packages_apps_browser, under directory /src/com/android/browser/.
Source file: BrowserSettings.java

private BrowserSettings(Context context){ mContext=context.getApplicationContext(); mPrefs=PreferenceManager.getDefaultSharedPreferences(mContext); mAutofillHandler=new AutofillHandler(mContext); mManagedSettings=new LinkedList<WeakReference<WebSettings>>(); mCustomUserAgents=new WeakHashMap<WebSettings,String>(); mAutofillHandler.asyncLoadFromDb(); BackgroundHandler.execute(mSetup); }
Example 19
From project sojo, under directory /src/test/java/test/net/sf/sojo/conversion/.
Source file: ComplexBean2MapConversionTest.java

public void testConversionDirect() throws Exception { Converter c=new Converter(); c.addConversion(new ComplexBean2MapConversion()); Node n=new Node("Node"); Object lvResult=c.convert(n,HashMap.class); assertNotNull(lvResult); assertTrue(lvResult instanceof HashMap); HashMap<?,?> lvHashMap=(HashMap<?,?>)lvResult; assertEquals(Node.class.getName(),lvHashMap.get("class")); assertEquals("Node",lvHashMap.get("name")); assertEquals(new ArrayList<Object>(),lvHashMap.get("children")); assertNull(lvHashMap.get("abc")); lvResult=c.convert(n,WeakHashMap.class); assertNotNull(lvResult); assertTrue(lvResult instanceof WeakHashMap); WeakHashMap<?,?> lvWeakHashMap=(WeakHashMap<?,?>)lvResult; assertEquals(Node.class.getName(),lvWeakHashMap.get("class")); assertEquals("Node",lvWeakHashMap.get("name")); assertEquals(new ArrayList<Object>(),lvWeakHashMap.get("children")); assertNull(lvWeakHashMap.get("abc")); }
Example 20
From project sonatype-aether, under directory /aether-impl/src/main/java/org/sonatype/aether/impl/internal/.
Source file: DataPool.java

@SuppressWarnings("unchecked") public DataPool(RepositorySystemSession session){ RepositoryCache cache=session.getCache(); if (cache != null) { artifacts=(ObjectPool<Artifact>)cache.get(session,ARTIFACT_POOL); dependencies=(ObjectPool<Dependency>)cache.get(session,DEPENDENCY_POOL); descriptors=(Map<Object,Descriptor>)cache.get(session,DESCRIPTORS); } if (artifacts == null) { artifacts=new ObjectPool<Artifact>(); if (cache != null) { cache.put(session,ARTIFACT_POOL,artifacts); } } if (dependencies == null) { dependencies=new ObjectPool<Dependency>(); if (cache != null) { cache.put(session,DEPENDENCY_POOL,dependencies); } } if (descriptors == null) { descriptors=Collections.synchronizedMap(new WeakHashMap<Object,Descriptor>(256)); if (cache != null) { cache.put(session,DESCRIPTORS,descriptors); } } }
Example 21
From project sveditor, under directory /sveditor/plugins/net.sf.sveditor.ui/src/net/sf/sveditor/ui/svcp/.
Source file: SVDBFileDecorator.java

public SVDBFileDecorator(){ fListeners=new ArrayList<ILabelProviderListener>(); fWorkQueue=new ArrayList<Object>(); fManagedByIndex=new HashMap<String,Map<String,Boolean>>(); fProjectListeners=new WeakHashMap<SVDBIndexCollection,SVDBFileDecorator.IndexChangeListener>(); }
Example 22
From project SWOWS, under directory /swows/src/main/java/org/swows/pfunction/.
Source file: bnode.java

private void setBlankNode(Node var,List<Node> list,Node blankNode){ if (blankNodesMap == null) blankNodesMap=new WeakHashMap<Node,Map<List<Node>,Node>>(); Map<List<Node>,Node> varMap=blankNodesMap.get(var); if (varMap == null) { varMap=new HashMap<List<Node>,Node>(); blankNodesMap.put(var,varMap); } varMap.put(list,blankNode); }
Example 23
From project wicket-cdi, under directory /wicket-cdi/src/main/java/net/ftlines/wicket/cdi/.
Source file: NonContextual.java

/** * Undeploys specified bean manager from cache * @param beanManager */ public static void undeploy(BeanManager beanManager){ if (cache.containsKey(beanManager)) { synchronized (lock) { Map<BeanManager,ClassMetaCache<NonContextual<?>>> newCache=new WeakHashMap<BeanManager,ClassMetaCache<NonContextual<?>>>(cache); newCache.remove(beanManager); cache=Collections.unmodifiableMap(newCache); } } }
Example 24
From project wrml-prototype, under directory /src/main/java/org/wrml/core/runtime/.
Source file: Context.java

public Context(final Config config,final ClassLoader parent){ super(parent); _Config=config; _ModelHeap=new ModelHeap(this); _HypermediaEngines=Observables.observableMap(new HashMap<URI,HypermediaEngine>()); _Services=Observables.observableMap(new HashMap<MediaType,Service>()); _StringTransformers=new Transformers<String>(this); final Transformer<URI,String> uriToStringTransformer=CachingTransformer.create(new UriToStringTransformer(),new WeakHashMap<URI,String>(),new WeakHashMap<String,URI>()); _StringTransformers.setTransformer(URI.class,uriToStringTransformer); final Transformer<MediaType,String> mediaTypeToStringTransformer=CachingTransformer.create(new MediaTypeToStringTransformer(),new WeakHashMap<MediaType,String>(),new WeakHashMap<String,MediaType>()); _StringTransformers.setTransformer(MediaType.class,mediaTypeToStringTransformer); _SystemTransformers=new SystemTransformers(this); _TypeSystem=new TypeSystem(this); _WWW=new WebClient(this); setDefaultService(_WWW); _SystemSchemaService=new SystemSchemaService(this,_WWW); setSchemaService(_SystemSchemaService); initTransformers(); initServices(); }