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