1 /* 2 ******************************************************************************* 3 * Copyright (C) 2010, International Business Machines 4 * Corporation and others. All Rights Reserved. 5 ******************************************************************************* 6 */ 7 package com.ibm.icu.impl; 8 9 /** 10 * Base class for cache implementations. 11 * To use, instantiate a subclass of a concrete implementation class, where the subclass 12 * implements the createInstance() method, and call get() with the key and the data. 13 * The get() call will use the data only if it needs to call createInstance(), 14 * otherwise the data is ignored. 15 * 16 * @param <K> Cache lookup key type 17 * @param <V> Cache instance value type 18 * @param <D> Data type for creating a new instance value 19 * 20 * @author Markus Scherer, Mark Davis 21 */ 22 public abstract class CacheBase<K, V, D> { 23 /** 24 * Retrieves an instance from the cache. Calls createInstance(key, data) if the cache 25 * does not already contain an instance with this key. 26 * Ignores data if the cache already contains an instance with this key. 27 * @param key Cache lookup key for the requested instance 28 * @param data Data for createInstance() if the instance is not already cached 29 * @return The requested instance 30 */ getInstance(K key, D data)31 public abstract V getInstance(K key, D data); 32 /** 33 * Creates an instance for the key and data. Must be overridden. 34 * @param key Cache lookup key for the requested instance 35 * @param data Data for the instance creation 36 * @return The requested instance 37 */ createInstance(K key, D data)38 protected abstract V createInstance(K key, D data); 39 } 40