package org.andnav.osm.views.util;

import java.util.ConcurrentModificationException;
import java.util.LinkedHashMap;

import org.andnav.osm.tileprovider.OpenStreetMapTile;
import org.andnav.osm.views.util.constants.OpenStreetMapViewConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import android.graphics.Bitmap;

public class LRUMapTileCache extends LinkedHashMap<OpenStreetMapTile, Bitmap> implements OpenStreetMapViewConstants {

	private static final Logger logger = LoggerFactory.getLogger(LRUMapTileCache.class);
	
	private static final long serialVersionUID = -541142277575493335L;

	private int mCapacity;
	
	public LRUMapTileCache(final int aCapacity) {
		super(aCapacity + 2, 0.1f, true);
		mCapacity = aCapacity;
	}

	public void ensureCapacity(final int aCapacity) {
		if (aCapacity > mCapacity) {
			mCapacity = aCapacity;
		}
	}

	@Override
	public Bitmap remove(final Object aKey) {
		final Bitmap bm = super.remove(aKey);
		if (bm != null) {
			bm.recycle();
		}
		return bm;
	}

	@Override
	public void clear() {
		// remove them all individually so that they get recycled
		try {
			for (final OpenStreetMapTile key : keySet()) {
				remove(key);
			}
		} catch (final ConcurrentModificationException ignore) {
			logger.info("ConcurrentModificationException clearing tile cache");
		}

		// and then clear
		super.clear();
	}

	@Override
	protected boolean removeEldestEntry(final Entry<OpenStreetMapTile, Bitmap> aEldest) {
		return size() > mCapacity;
	}

}

@@ -170,79 +170,8 @@
 le;%0A
-import org.andnav.osm.views.util.constants.OpenStreetMapViewConstants;%0A
 impo
@@ -338,46 +338,8 @@
 map%3E
- implements OpenStreetMapViewConstants
  %7B%0A%0A
@@ -424,17 +424,16 @@
 class);%0A
-%09
 %0A%09privat
@@ -518,17 +518,16 @@
 pacity;%0A
-%09
 %0A%09public

Remove unused constants