FileDocCategorySizeDatePackage
LazyMapExample.javaAPI DocExample2201Wed May 18 09:38:58 BST 2005com.discursive.jccook.collections.lazy

LazyMapExample

public class LazyMapExample extends Object

Fields Summary
Map
stockQuotes
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		LazyMapExample example = new LazyMapExample();
		example.start();
	
public voidstart()

		
		StockQuoteTransformer sqTransformer = new StockQuoteTransformer();
		sqTransformer.setQuoteURL( new URL("http://quotes.company.com") );
		sqTransformer.setTimeout( 500 );
		
		stockQuotes = new LRUMap( 5 );
		stockQuotes = LazyMap.decorate( stockQuotes, sqTransformer );
		
		// Now use some of the entries in the cache
		Float cscoPrice  = (Float) stockQuotes.get( "CSCO" );
		Float msPrice = (Float) stockQuotes.get( "MSFT" );
		Float tscPrice = (Float) stockQuotes.get( "TSC" );
		Float luPrice = (Float) stockQuotes.get( "LU" );
		Float pPrice = (Float) stockQuotes.get( "P" );
		Float msPrice2 = (Float) stockQuotes.get( "MSFT" );
		
		// Add another price to the Map, this should kick out the LRU item.
		stockQuotes.put( "AA",			new Float( 203.20 ) );
		
		// CSCO was the first price requested, it is therefor the
		// least recently used.
		if( !stockQuotes.containsKey("CSCO") ) {
			System.out.println( "As expected CSCO was discarded" );
		}