Code example for ConcurrentHashMap

Methods: contains, containsKey, get, put

0
     * download image from the internet if there is no cache for the image. 
     *  
     * @param url 
     */ 
    private void downloadImage(String url) {
	if (!mImageMap.containsKey(url) || mImageMap.get(url) == null
		|| mImageMap.get(url).get() == null) {
	    if (!mImageDiskCache.hasCache(url)) {
		HttpUtil.downloadFile(url, mImageDiskCache);
	    } 
	     
	    if (mImageDiskCache.hasCache(url)) {
		Bitmap b = mImageDiskCache.getBitmapFromCache(url);
		if (b != null) {
		    if (!isFinishing() && mImageMap != null) {
			mImageMap.put(url, new SoftReference<Bitmap>(b));
			postUpdateImage(b);
		    } else { 
			b.recycle();
			b = null;
		    } 
		} 
	    } 
	} 
    } 
     
    /** 
     * display the image to the imageview. 
     *  
     * @param imageBitmap 
     */ 
    private void postUpdateImage(Bitmap imageBitmap) {
	if (imageBitmap == null) {
	    imageBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.default_image);
	} 
	ImageUpdator imageUpdator = new ImageUpdator(imageBitmap);
	runOnUiThread(imageUpdator);
    } 
     
    /** 
     * The class for updating image. 
     *  
     * @author Administrator 
     * 
     */ 
    private class ImageUpdator implements Runnable {
	private final Bitmap mImageBitmap;
	 
	public ImageUpdator(Bitmap imageBitmap) {
	    mImageBitmap = imageBitmap;
	} 
	 
	@Override 
	public void run() { 
	    updateProgressBar(false); 
	    if (mImageBitmap != null && mImageView != null && !isFinishing()) {
		mImageView.setImageBitmap(mImageBitmap);
	    } 
	     
	    if (mCurrentImageBitmap != null) {
		mCurrentImageBitmap.recycle();
		mCurrentImageBitmap = null;
	    } 
	     
	    mCurrentImageBitmap = mImageBitmap;
	} 
	 
    } 
     
    /** 
     * The handler to download image and show image. 
     *  
     * @author Administrator 
     * 
     */ 
    private class ViewHandler extends Handler {
	public ViewHandler(Looper looper) {
	    super(looper);
	} 
 
	@Override 
	public void handleMessage(Message msg) {
	    int what = msg.what;
	    switch (what) {
	    case DOWNLOAD_IMAGE_AND_SHOW:
		updateProgressBar(true); 
		String url = (String) msg.obj;
		if (mImageMap.contains(url)) {
		    Bitmap imageBitmap = null;
		    SoftReference<Bitmap> imageBitmapSoftReference = mImageMap.get(url);
		    if (imageBitmapSoftReference != null) {
			imageBitmap = imageBitmapSoftReference.get();
		    } 
		     
		    if (imageBitmap != null) {