org.jaitools.tilecache
Class BasicCacheVisitor

java.lang.Object
  extended by org.jaitools.tilecache.BasicCacheVisitor
All Implemented Interfaces:
DiskMemTileCacheVisitor

public class BasicCacheVisitor
extends Object
implements DiskMemTileCacheVisitor

A basic visitor class for DiskMemTileCache that can be used to examine cache contents.

Example of use:


 // Query the cache for tiles that belong to a given image
 // and that are currently resident in memory
 DiskMemTileCache cache = ...
 RenderedImage owner = ...

 Map filters = CollectionFactory.newMap();
 filters.put(BasicCacheVisitor.Key.OWNER, owner);
 filters.put(BasicCachevisitor.Key.RESIDENT, Boolean.TRUE);

 BasicCacheVisitor visitor = new BasicCacheVisitor();
 visitor.setFilters(filters);
 cache.accept(visitor);

 for (DiskCachedTile tile : visitor.getTiles()) {
     System.out.println(String.format("tile %d,%d", tile.getTileX(), tile.getTileY()));
 }
 

Since:
1.0
Version:
$Id$
Author:
Michael Bedward

Nested Class Summary
static class BasicCacheVisitor.Key
          Defines keys to filter the tles visited
 
Constructor Summary
BasicCacheVisitor()
           
 
Method Summary
 void clear()
          Clear collected tile data.
 void clearFilters()
          Clear all existing filter conditions
 Collection<DiskCachedTile> getTiles()
          Returns an unmodifiable collection of tiles retrieved from the cache.
 void setFilter(BasicCacheVisitor.Key key, Object value)
          Set a single filter condition.
 void setFilters(Map<BasicCacheVisitor.Key,Object> params)
          Set filter conditions.
 void visit(DiskCachedTile tile, boolean isResident)
          This method is called by the cache for each tile in turn.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicCacheVisitor

public BasicCacheVisitor()
Method Detail

setFilters

public void setFilters(Map<BasicCacheVisitor.Key,Object> params)
Set filter conditions. Any existing conditions are cleared.

Parameters:
params - a Map where each key is one of the constants defined by BasicCacheVisitor.Key and each value is the corresponding value to match tiles against

setFilter

public void setFilter(BasicCacheVisitor.Key key,
                      Object value)
Set a single filter condition. Any existing conditions are cleared

Parameters:
key - one of the constants defined by BasicCacheVisitor.Key
value - corresponding value to match tiles against

clearFilters

public void clearFilters()
Clear all existing filter conditions


getTiles

public Collection<DiskCachedTile> getTiles()
Returns an unmodifiable collection of tiles retrieved from the cache.

Returns:
tiles retrieved from the cache

visit

public void visit(DiskCachedTile tile,
                  boolean isResident)
This method is called by the cache for each tile in turn. Tiles that pass this visitor's filter conditions, if any, will be added to the visitor's tile collection.

Specified by:
visit in interface DiskMemTileCacheVisitor
Parameters:
tile - the cached tile being visited
isResident - set by the cache to indicate whether the tile is currently resident in memory

clear

public void clear()
Clear collected tile data. Useful if an instance of this class makes multiple visits to a cache.



Copyright © 2009-2013. All Rights Reserved.