org.openstreetmap.gui.jmapviewer
Class MemoryTileCache

java.lang.Object
  extended by org.openstreetmap.gui.jmapviewer.MemoryTileCache
All Implemented Interfaces:
TileCache

public class MemoryTileCache
extends java.lang.Object
implements TileCache

TileCache implementation that stores all Tile objects in memory up to a certain limit (getCacheSize()). If the limit is exceeded the least recently used Tile objects will be deleted.


Nested Class Summary
protected static class MemoryTileCache.CacheEntry
          Linked list element holding the Tile and links to the MemoryTileCache.CacheEntry.next and MemoryTileCache.CacheEntry.prev item in the list.
protected static class MemoryTileCache.CacheLinkedListElement
          Special implementation of a double linked list for MemoryTileCache.CacheEntry elements.
 
Field Summary
protected  int cacheSize
          Default cache size
protected  java.util.Hashtable<java.lang.String,MemoryTileCache.CacheEntry> hashtable
           
protected static java.util.logging.Logger log
           
protected  MemoryTileCache.CacheLinkedListElement lruTiles
          List of all tiles in their last recently used order
 
Constructor Summary
MemoryTileCache()
           
 
Method Summary
 void addTile(Tile tile)
          Adds a tile to the cache.
 void clear()
          Clears the cache deleting all tiles from memory
protected  MemoryTileCache.CacheEntry createCacheEntry(Tile tile)
           
 int getCacheSize()
           
 Tile getTile(TileSource source, int x, int y, int z)
          Retrieves a tile from the cache if present, otherwise null will be returned.
 int getTileCount()
           
protected  void removeEntry(MemoryTileCache.CacheEntry entry)
           
protected  void removeOldEntries()
          Removes the least recently used tiles
 void setCacheSize(int cacheSize)
          Changes the maximum number of Tile objects that this cache holds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final java.util.logging.Logger log

cacheSize

protected int cacheSize
Default cache size


hashtable

protected java.util.Hashtable<java.lang.String,MemoryTileCache.CacheEntry> hashtable

lruTiles

protected MemoryTileCache.CacheLinkedListElement lruTiles
List of all tiles in their last recently used order

Constructor Detail

MemoryTileCache

public MemoryTileCache()
Method Detail

addTile

public void addTile(Tile tile)
Description copied from interface: TileCache
Adds a tile to the cache. How long after adding a tile can be retrieved via TileCache.getTile(TileSource, int, int, int) is unspecified and depends on the implementation.

Specified by:
addTile in interface TileCache
Parameters:
tile - the tile to be added

getTile

public Tile getTile(TileSource source,
                    int x,
                    int y,
                    int z)
Description copied from interface: TileCache
Retrieves a tile from the cache if present, otherwise null will be returned.

Specified by:
getTile in interface TileCache
Parameters:
source - the tile source
x - tile number on the x axis of the tile to be retrieved
y - tile number on the y axis of the tile to be retrieved
z - zoom level of the tile to be retrieved
Returns:
the requested tile or null if the tile is not present in the cache

removeOldEntries

protected void removeOldEntries()
Removes the least recently used tiles


removeEntry

protected void removeEntry(MemoryTileCache.CacheEntry entry)

createCacheEntry

protected MemoryTileCache.CacheEntry createCacheEntry(Tile tile)

clear

public void clear()
Clears the cache deleting all tiles from memory


getTileCount

public int getTileCount()
Specified by:
getTileCount in interface TileCache
Returns:
the number of tiles hold by the cache

getCacheSize

public int getCacheSize()

setCacheSize

public void setCacheSize(int cacheSize)
Changes the maximum number of Tile objects that this cache holds.

Parameters:
cacheSize - new maximum number of tiles


JOSM