blob: 7978bad54fbc4551b87991f67964c275717069ad [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (19) -->
<title>Cache (Apache SIS 1.3 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="declaration: package: org.apache.sis.util.collection, class: Cache">
<meta name="generator" content="javadoc/ClassWriterImpl">
<meta name="keywords" content="org.apache.sis.util.collection.Cache class">
<meta name="keywords" content="clear()">
<meta name="keywords" content="isEmpty()">
<meta name="keywords" content="size()">
<meta name="keywords" content="get()">
<meta name="keywords" content="getOrCreate()">
<meta name="keywords" content="computeIfAbsent()">
<meta name="keywords" content="putIfAbsent()">
<meta name="keywords" content="put()">
<meta name="keywords" content="replace()">
<meta name="keywords" content="replaceAll()">
<meta name="keywords" content="computeIfPresent()">
<meta name="keywords" content="compute()">
<meta name="keywords" content="merge()">
<meta name="keywords" content="remove()">
<meta name="keywords" content="containsKey()">
<meta name="keywords" content="peek()">
<meta name="keywords" content="lock()">
<meta name="keywords" content="keySet()">
<meta name="keywords" content="entrySet()">
<meta name="keywords" content="isKeyCollisionAllowed()">
<meta name="keywords" content="setKeyCollisionAllowed()">
<meta name="keywords" content="cost()">
<meta name="keywords" content="flush()">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../sis.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../script-dir/jquery-ui.min.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../jquery-ui.overrides.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
<script type="text/javascript" src="../../../../../script-dir/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../../../../../script-dir/jquery-ui.min.js"></script>
</head>
<body class="class-declaration-page">
<script type="text/javascript">var pathtoroot = "../../../../../";
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<div class="flex-box">
<header role="banner" class="flex-header">
<nav role="navigation">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="top-nav" id="navbar-top"><button id="navbar-toggle-button" aria-controls="navbar-top" aria-expanded="false" aria-label="Toggle navigation links"><span class="nav-bar-toggle-icon">&nbsp;</span><span class="nav-bar-toggle-icon">&nbsp;</span><span class="nav-bar-toggle-icon">&nbsp;</span></button>
<div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div>
<ul id="navbar-top-firstrow" class="nav-list" title="Navigation">
<li><a href="../../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="nav-bar-cell1-rev">Class</li>
<li><a href="class-use/Cache.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html#class">Help</a></li>
</ul>
<ul class="sub-nav-list-small">
<li>
<p>Summary:</p>
<ul>
<li><a href="#nested-class-summary">Nested</a></li>
<li>Field</li>
<li><a href="#constructor-summary">Constr</a></li>
<li><a href="#method-summary">Method</a></li>
</ul>
</li>
<li>
<p>Detail:</p>
<ul>
<li>Field</li>
<li><a href="#constructor-detail">Constr</a></li>
<li><a href="#method-detail">Method</a></li>
</ul>
</li>
</ul>
</div>
<div class="sub-nav">
<div id="navbar-sub-list">
<ul class="sub-nav-list">
<li>Summary:&nbsp;</li>
<li><a href="#nested-class-summary">Nested</a>&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor-summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method-summary">Method</a></li>
</ul>
<ul class="sub-nav-list">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor-detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method-detail">Method</a></li>
</ul>
</div>
<div class="nav-list-search"><a href="../../../../../search.html">SEARCH</a>
<input type="text" id="search-input" disabled placeholder="Search">
<input type="reset" id="reset-button" disabled value="reset">
</div>
</div>
<!-- ========= END OF TOP NAVBAR ========= -->
<span class="skip-nav" id="skip-navbar-top"></span></nav>
</header>
<div class="flex-content">
<main role="main">
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="sub-title"><span class="package-label-in-type">Package</span>&nbsp;<a href="package-summary.html">org.apache.sis.util.collection</a></div>
<h1 title="Class Cache" class="title">Class Cache&lt;K,<wbr>V&gt;</h1>
</div>
<div class="inheritance" title="Inheritance Tree"><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>
<div class="inheritance"><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">AbstractMap</a>&lt;K,<wbr>V&gt;
<div class="inheritance">Cache&lt;K,<wbr>V&gt;</div>
</div>
</div>
<section class="class-description" id="class-description">
<dl class="notes">
<dt>Type Parameters:</dt>
<dd><code>K</code> - the type of key objects.</dd>
<dd><code>V</code> - the type of value objects.</dd>
</dl>
<dl class="notes">
<dt>All Implemented Interfaces:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">Concurrent­Map</a>&lt;K,<wbr>V&gt;</code>, <code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;K,<wbr>V&gt;</code></dd>
</dl>
<hr>
<div class="type-signature"><span class="modifiers">public class </span><span class="element-name type-name-label">Cache&lt;K,<wbr>V&gt;</span>
<span class="extends-implements">extends <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">AbstractMap</a>&lt;K,<wbr>V&gt;
implements <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">ConcurrentMap</a>&lt;K,<wbr>V&gt;</span></div>
<div class="block">A concurrent map capable to locks entries for which the value is in process of being computed.
This map is intended for use as a cache, with a goal of avoiding to compute the same values twice.
This implementation is thread-safe and supports concurrency.
<code>Cache</code> is based on <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentHashMap.html" title="class or interface in java.util.concurrent" class="external-link"><code>Concurrent­Hash­Map</code></a> with the addition of three main capabilities:
<ul>
<li>Lock an entry when its value is under computation in a thread.</li>
<li>Block other threads requesting the value of that particular entry until computation is completed.</li>
<li>Retain oldest values by soft or weak references instead of strong references.</li>
</ul>
The easiest way to use this class is to invoke <a href="#computeIfAbsent(K,java.util.function.Function)"><code>compute­If­Absent(…)</code></a>
or <a href="#getOrCreate(K,java.util.concurrent.Callable)"><code>get­Or­Create(…)</code></a> with lambda functions as below:
<blockquote><pre><font color="green">private</font> <font color="green">final</font> Cache&lt;String,MyObject&gt; cache = <font color="green">new</font> Cache&lt;String,MyObject&gt;();
<font color="green">public</font> MyObject <b>getMyObject</b>(String key) {
<font color="green">return</font> cache.<b>computeIfAbsent</b>(key, (k) -&gt; <b>createMyObject</b>(k));
}</pre></blockquote>
Alternatively, one can handle explicitly the locks.
This alternative sometimes provides more flexibility, for example in exception handling.
The steps are as below:
<ol>
<li>Check if the value is already available in the map.
If it is, return it immediately and we are done.</li>
<li>Otherwise, get a lock and check again if the value is already available in the map
(because the value could have been computed by another thread between step 1 and
the obtention of the lock). If it is, release the lock and we are done.</li>
<li>Otherwise compute the value, store the result and release the lock.</li>
</ol>
Code example is shown below.
Note that the call to <a href="Cache.Handler.html#putAndUnlock(V)"><code>put­And­Unlock(…)</code></a> <strong>must</strong>
be inside the <code>finally</code> block of a <code>try</code> block beginning immediately after the call
to <a href="#lock(K)"><code>lock(…)</code></a>, no matter what the result of the computation is (including <code>null</code>).
<blockquote><pre><font color="green">private</font> <font color="green">final</font> Cache&lt;String,MyObject&gt; cache = <font color="green">new</font> Cache&lt;String,MyObject&gt;();
<font color="green">public</font> MyObject <b>getMyObject</b>(<font color="green">final</font> String key) <font color="green">throws</font> MyCheckedException {
MyObject value = cache.<b>peek</b>(key);
<font color="green">if</font> (value == <font color="green">null</font>) {
<font color="green">final</font> Cache.Handler&lt;MyObject&gt; handler = cache.<b>lock</b>(key);
<font color="green">try</font> {
value = handler.<b>peek</b>();
<font color="green">if</font> (value == <font color="green">null</font>) {
value = <b>createMyObject</b>(key);
}
} <font color="green">finally</font> {
handler.<b>putAndUnlock</b>(value);
}
}
<font color="green">return</font> value;
}</pre></blockquote>
<h2>Eviction of eldest values</h2>
<ul>
<li>The <cite>cost</cite> of a value is the value returned by <a href="#cost(V)"><code>cost(V)</code></a>. The default
implementation returns 1 in all cases, but subclasses can override this method for
more elaborated cost computation.</li>
<li>The <cite>total cost</cite> is the sum of the cost of all values held by strong
reference in this cache. The total cost does not include the cost of values held
by <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/ref/Reference.html" title="class or interface in java.lang.ref" class="external-link">weak or soft reference</a>.</li>
<li>The <cite>cost limit</cite> is the maximal value allowed for the total cost. If
the total cost exceed this value, then strong references to the eldest values are
replaced by <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/ref/Reference.html" title="class or interface in java.lang.ref" class="external-link">weak or soft references</a> until the total cost
become equals or lower than the cost limit.</li>
</ul>
The total cost is given at construction time. If the <a href="#cost(V)"><code>cost(V)</code></a> method has not been
overridden, then the total cost is the maximal amount of values to keep by strong references.
<h2>Circular dependencies</h2>
This implementation assumes that there are no circular dependencies (or cyclic graph) between
the values in the cache. For example if creating <var>A</var> implies creating <var>B</var>,
then creating <var>B</var> is not allowed to implies (directly or indirectly) the creation of
<var>A</var>. If this condition is not met, deadlock may occur randomly.</div>
<dl class="notes">
<dt>Since:</dt>
<dd>0.3</dd>
<p><font size="-1">Defined in the <code>sis-utility</code> module</font></p>
</dl>
</section>
<section class="summary">
<ul class="summary-list">
<!-- ======== NESTED CLASS SUMMARY ======== -->
<li>
<section class="nested-class-summary" id="nested-class-summary">
<h2>Nested Class Summary</h2>
<div class="caption"><span>Nested Classes</span></div>
<div class="summary-table three-column-summary">
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Class</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color"><code>static interface&nbsp;</code></div>
<div class="col-second even-row-color"><code><a href="Cache.Handler.html" class="type-name-link" title="interface in org.apache.sis.util.collection">Cache​.Handler</a>&lt;<a href="Cache.Handler.html" title="type parameter in Cache.Handler">V</a>&gt;</code></div>
<div class="col-last even-row-color">
<div class="block">The handler returned by <a href="#lock(K)"><code>lock(K)</code></a>, to be used for unlocking and storing the result.</div>
</div>
</div>
<div class="inherited-list">
<h2 id="nested-classes-inherited-from-class-java.util.AbstractMap">Nested classes/interfaces inherited from class&nbsp;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">AbstractMap</a></h2>
<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.SimpleEntry.html" title="class or interface in java.util" class="external-link">Abstract­Map​.Simple­Entry</a>&lt;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.SimpleEntry.html" title="class or interface in java.util" class="external-link">K</a>,<wbr><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.SimpleEntry.html" title="class or interface in java.util" class="external-link">V</a>&gt;, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.SimpleImmutableEntry.html" title="class or interface in java.util" class="external-link">Abstract­Map​.Simple­Immutable­Entry</a>&lt;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.SimpleImmutableEntry.html" title="class or interface in java.util" class="external-link">K</a>,<wbr><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.SimpleImmutableEntry.html" title="class or interface in java.util" class="external-link">V</a>&gt;</code></div>
<div class="inherited-list">
<h2 id="nested-classes-inherited-from-class-java.util.Map">Nested classes/interfaces inherited from interface&nbsp;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a></h2>
<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.Entry.html" title="class or interface in java.util" class="external-link">Map​.Entry</a>&lt;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.Entry.html" title="class or interface in java.util" class="external-link">K</a>,<wbr><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.Entry.html" title="class or interface in java.util" class="external-link">V</a>&gt;</code></div>
</section>
</li>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<li>
<section class="constructor-summary" id="constructor-summary">
<h2>Constructor Summary</h2>
<div class="caption"><span>Constructors</span></div>
<div class="summary-table two-column-summary">
<div class="table-header col-first">Constructor</div>
<div class="table-header col-last">Description</div>
<div class="col-constructor-name even-row-color"><code><a href="#%3Cinit%3E()" class="member-name-link">Cache</a>()</code></div>
<div class="col-last even-row-color">
<div class="block">Creates a new cache with a default initial capacity and cost limit of 100.</div>
</div>
<div class="col-constructor-name odd-row-color"><code><a href="#%3Cinit%3E(int,long,boolean)" class="member-name-link">Cache</a><wbr>(int&nbsp;initial­Capacity,
long&nbsp;cost­Limit,
boolean&nbsp;soft)</code></div>
<div class="col-last odd-row-color">
<div class="block">Creates a new cache using the given initial capacity and cost limit.</div>
</div>
</div>
</section>
</li>
<!-- ========== METHOD SUMMARY =========== -->
<li>
<section class="method-summary" id="method-summary">
<h2>Method Summary</h2>
<div id="method-summary-table">
<div class="table-tabs" role="tablist" aria-orientation="horizontal"><button id="method-summary-table-tab0" role="tab" aria-selected="true" aria-controls="method-summary-table.tabpanel" tabindex="0" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table', 3)" class="active-table-tab">All Methods</button><button id="method-summary-table-tab2" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab2', 3)" class="table-tab">Instance Methods</button><button id="method-summary-table-tab4" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab4', 3)" class="table-tab">Concrete Methods</button></div>
<div id="method-summary-table.tabpanel" role="tabpanel">
<div class="summary-table three-column-summary" aria-labelledby="method-summary-table-tab0">
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Method</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>void</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#clear()" class="member-name-link">clear</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Clears the content of this cache.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#compute(K,java.util.function.BiFunction)" class="member-name-link">compute</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/BiFunction.html" title="class or interface in java.util.function" class="external-link">Bi­Function</a>&lt;? super <a href="Cache.html" title="type parameter in Cache">K</a>,<wbr>? super <a href="Cache.html" title="type parameter in Cache">V</a>,<wbr>? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;remapping)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Replaces the value mapped to the given key by a new value computed from the old value.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#computeIfAbsent(K,java.util.function.Function)" class="member-name-link">compute­If­Absent</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/Function.html" title="class or interface in java.util.function" class="external-link">Function</a>&lt;? super <a href="Cache.html" title="type parameter in Cache">K</a>,<wbr>? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;creator)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns the value for the given key if it exists, or computes it otherwise.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#computeIfPresent(K,java.util.function.BiFunction)" class="member-name-link">compute­If­Present</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/BiFunction.html" title="class or interface in java.util.function" class="external-link">Bi­Function</a>&lt;? super <a href="Cache.html" title="type parameter in Cache">K</a>,<wbr>? super <a href="Cache.html" title="type parameter in Cache">V</a>,<wbr>? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;remapping)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Replaces the value mapped to the given key by a new value computed from the old value.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#containsKey(java.lang.Object)" class="member-name-link">contains­Key</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;key)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns <code>true</code> if this map contains the specified key.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>protected int</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#cost(V)" class="member-name-link">cost</a><wbr>(<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;value)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Computes an estimation of the cost of the given value.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Set.html" title="class or interface in java.util" class="external-link">Set</a>&lt;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.Entry.html" title="class or interface in java.util" class="external-link">Map​.Entry</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;&gt;</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#entrySet()" class="member-name-link">entry­Set</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns the set of entries in this cache.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#flush()" class="member-name-link">flush</a>()</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Forces the removal of all garbage collected values in the map.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#get(java.lang.Object)" class="member-name-link">get</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;key)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns the value mapped to the given key in the cache, potentially waiting for computation to complete.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#getOrCreate(K,java.util.concurrent.Callable)" class="member-name-link">get­Or­Create</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/Callable.html" title="class or interface in java.util.concurrent" class="external-link">Callable</a>&lt;? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;creator)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns the value for the given key if it exists, or computes it otherwise.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#isEmpty()" class="member-name-link">is­Empty</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns <code>true</code> if this cache is empty.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#isKeyCollisionAllowed()" class="member-name-link">is­Key­Collision­Allowed</a>()</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns <code>true</code> if different values may be assigned to the same key.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Set.html" title="class or interface in java.util" class="external-link">Set</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>&gt;</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#keySet()" class="member-name-link">key­Set</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns the set of keys in this cache.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.Handler.html" title="interface in org.apache.sis.util.collection">Cache​.Handler</a>&lt;<a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#lock(K)" class="member-name-link">lock</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Gets a lock for the entry at the given key and returns a handler to be used by the caller
for unlocking and storing the result.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#merge(K,V,java.util.function.BiFunction)" class="member-name-link">merge</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;value,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/BiFunction.html" title="class or interface in java.util.function" class="external-link">Bi­Function</a>&lt;? super <a href="Cache.html" title="type parameter in Cache">V</a>,<wbr>? super <a href="Cache.html" title="type parameter in Cache">V</a>,<wbr>? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;remapping)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Maps the given value to the given key if no mapping existed before this method call,
or computes a new value otherwise.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#peek(K)" class="member-name-link">peek</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">If a value is already cached for the given key, returns it.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#put(K,V)" class="member-name-link">put</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;value)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Puts the given value in cache and immediately returns the old value.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#putIfAbsent(K,V)" class="member-name-link">put­If­Absent</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;value)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">If no value is already mapped and no value is under computation for the given key, puts the given value
in the cache.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#remove(java.lang.Object)" class="member-name-link">remove</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;key)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Removes the value mapped to the given key in the cache.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#remove(java.lang.Object,java.lang.Object)" class="member-name-link">remove</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;key,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;old­Value)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">If the given key is mapped to the given old value, removes that value.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="Cache.html" title="type parameter in Cache">V</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#replace(K,V)" class="member-name-link">replace</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;value)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">If the given key is mapped to any value, replaces that value with the given new value.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#replace(K,V,V)" class="member-name-link">replace</a><wbr>(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;old­Value,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;new­Value)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">If the given key is mapped to the given old value, replaces that value with the given new value.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>void</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#replaceAll(java.util.function.BiFunction)" class="member-name-link">replace­All</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/BiFunction.html" title="class or interface in java.util.function" class="external-link">Bi­Function</a>&lt;? super <a href="Cache.html" title="type parameter in Cache">K</a>,<wbr>? super <a href="Cache.html" title="type parameter in Cache">V</a>,<wbr>? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;remapping)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Iterates over all entries in the cache and replaces their value with the one provided by the given function.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>void</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#setKeyCollisionAllowed(boolean)" class="member-name-link">set­Key­Collision­Allowed</a><wbr>(boolean&nbsp;allowed)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">If set to <code>true</code>, different values may be assigned to the same key.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>int</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#size()" class="member-name-link">size</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns the number of elements in this cache.</div>
</div>
</div>
</div>
</div>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-AbstractMap">Methods inherited from class&nbsp;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">AbstractMap</a></h3>
<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#clone()" title="class or interface in java.util" class="external-link">clone</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#containsValue(java.lang.Object)" title="class or interface in java.util" class="external-link">contains­Value</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#equals(java.lang.Object)" title="class or interface in java.util" class="external-link">equals</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#hashCode()" title="class or interface in java.util" class="external-link">hash­Code</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#putAll(java.util.Map)" title="class or interface in java.util" class="external-link">put­All</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#toString()" title="class or interface in java.util" class="external-link">to­String</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#values()" title="class or interface in java.util" class="external-link">values</a></code></div>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-Object">Methods inherited from class&nbsp;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a></h3>
<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#finalize()" title="class or interface in java.lang" class="external-link">finalize</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#getClass()" title="class or interface in java.lang" class="external-link">get­Class</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#notify()" title="class or interface in java.lang" class="external-link">notify</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#notifyAll()" title="class or interface in java.lang" class="external-link">notify­All</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#wait()" title="class or interface in java.lang" class="external-link">wait</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#wait(long)" title="class or interface in java.lang" class="external-link">wait</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#wait(long,int)" title="class or interface in java.lang" class="external-link">wait</a></code></div>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-ConcurrentMap">Methods inherited from interface&nbsp;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">ConcurrentMap</a></h3>
<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#forEach(java.util.function.BiConsumer)" title="class or interface in java.util.concurrent" class="external-link">for­Each</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#getOrDefault(java.lang.Object,V)" title="class or interface in java.util.concurrent" class="external-link">get­Or­Default</a></code></div>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-Map">Methods inherited from interface&nbsp;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a></h3>
<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#containsValue(java.lang.Object)" title="class or interface in java.util" class="external-link">contains­Value</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#equals(java.lang.Object)" title="class or interface in java.util" class="external-link">equals</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#hashCode()" title="class or interface in java.util" class="external-link">hash­Code</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#putAll(java.util.Map)" title="class or interface in java.util" class="external-link">put­All</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#values()" title="class or interface in java.util" class="external-link">values</a></code></div>
</section>
</li>
</ul>
</section>
<section class="details">
<ul class="details-list">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<li>
<section class="constructor-details" id="constructor-detail">
<h2>Constructor Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="&lt;init&gt;()">
<h3>Cache</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="element-name">Cache</span>()</div>
<div class="block">Creates a new cache with a default initial capacity and cost limit of 100.
The oldest objects will be hold by <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/ref/WeakReference.html" title="class or interface in java.lang.ref" class="external-link">weak references</a>.</div>
</section>
</li>
<li>
<section class="detail" id="&lt;init&gt;(int,long,boolean)">
<h3>Cache</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="element-name">Cache</span><wbr><span class="parameters">(int&nbsp;initialCapacity,
long&nbsp;costLimit,
boolean&nbsp;soft)</span></div>
<div class="block">Creates a new cache using the given initial capacity and cost limit. The initial capacity
is the expected number of values to be stored in this cache. More values are allowed, but
a little bit of CPU time may be saved if the expected capacity is known before the cache
is created.
<p>The <cite>cost limit</cite> is the maximal value of the <cite>total cost</cite> (the sum
of the <a href="#cost(V)">cost</a> of all values) before to replace eldest strong references by
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/ref/Reference.html" title="class or interface in java.lang.ref" class="external-link">weak or soft references</a>.</p></div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>initial­Capacity</code> - the initial capacity.</dd>
<dd><code>cost­Limit</code> - the maximum cost of objects to keep by strong reference.</dd>
<dd><code>soft</code> - if <code>true</code>, use <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/ref/SoftReference.html" title="class or interface in java.lang.ref" class="external-link"><code>Soft­Reference</code></a> instead of <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/ref/WeakReference.html" title="class or interface in java.lang.ref" class="external-link"><code>Weak­Reference</code></a>.</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>
<!-- ============ METHOD DETAIL ========== -->
<li>
<section class="method-details" id="method-detail">
<h2>Method Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="clear()">
<h3>clear</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">clear</span>()</div>
<div class="block">Clears the content of this cache.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#clear()" title="class or interface in java.util" class="external-link">clear</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Overrides:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#clear()" title="class or interface in java.util" class="external-link">clear</a></code>&nbsp;in class&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">Abstract­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="isEmpty()">
<h3>isEmpty</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">isEmpty</span>()</div>
<div class="block">Returns <code>true</code> if this cache is empty.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#isEmpty()" title="class or interface in java.util" class="external-link">is­Empty</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Overrides:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#isEmpty()" title="class or interface in java.util" class="external-link">is­Empty</a></code>&nbsp;in class&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">Abstract­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Returns:</dt>
<dd><code>true</code> if this cache do not contains any element.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="size()">
<h3>size</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">int</span>&nbsp;<span class="element-name">size</span>()</div>
<div class="block">Returns the number of elements in this cache. The count includes values keep by strong,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/ref/SoftReference.html" title="class or interface in java.lang.ref" class="external-link">soft</a> or <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/ref/WeakReference.html" title="class or interface in java.lang.ref" class="external-link">weak</a> references, and the
values under computation at the time this method is invoked.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#size()" title="class or interface in java.util" class="external-link">size</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Overrides:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#size()" title="class or interface in java.util" class="external-link">size</a></code>&nbsp;in class&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">Abstract­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Returns:</dt>
<dd>the number of elements currently cached.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="get(java.lang.Object)">
<h3>get</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">get</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;key)</span></div>
<div class="block">Returns the value mapped to the given key in the cache, potentially waiting for computation to complete.
This method is similar to <a href="#peek(K)"><code>peek(Object)</code></a> except that it blocks if the value is currently under
computation in another thread.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#get(java.lang.Object)" title="class or interface in java.util" class="external-link">get</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Overrides:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#get(java.lang.Object)" title="class or interface in java.util" class="external-link">get</a></code>&nbsp;in class&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">Abstract­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - the key of the value to get.</dd>
<dt>Returns:</dt>
<dd>the value mapped to the given key, or <code>null</code> if none.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="#peek(K)"><code>peek(Object)</code></a></li>
<li><a href="#containsKey(java.lang.Object)"><code>contains­Key(Object)</code></a></li>
<li><a href="#computeIfAbsent(K,java.util.function.Function)"><code>compute­If­Absent(Object, Function)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="getOrCreate(K,java.util.concurrent.Callable)">
<h3 id="getOrCreate(java.lang.Object,java.util.concurrent.Callable)">getOrCreate</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">getOrCreate</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/Callable.html" title="class or interface in java.util.concurrent" class="external-link">Callable</a>&lt;? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;creator)</span>
throws <span class="exceptions"><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Exception.html" title="class or interface in java.lang" class="external-link">Exception</a></span></div>
<div class="block">Returns the value for the given key if it exists, or computes it otherwise.
If a value already exists in the cache, then it is returned immediately.
Otherwise the <code>creator​.call()</code> method is invoked and its result is saved in this cache for future reuse.
<div class="note"><b>Example:</b>
the following example shows how this method can be used.
In particular, it shows how to propagate <code>My­Checked­Exception</code>:
<blockquote><pre><font color="green">private</font> <font color="green">final</font> Cache&lt;String,MyObject&gt; cache = <font color="green">new</font> Cache&lt;String,MyObject&gt;();
<font color="green">public</font> MyObject <b>getMyObject</b>(<font color="green">final</font> String key) <font color="green">throws</font> MyCheckedException {
<font color="green">try</font> {
<font color="green">return</font> cache.<b>getOrCreate</b>(key, <font color="green">new</font> Callable&lt;MyObject&gt;() {
<font color="green">public</font> MyObject <b>call</b>() <font color="green">throws</font> MyCheckedException {
<font color="green">return</font> <b>createMyObject</b>(key);
}
});
} <font color="green">catch</font> (MyCheckedException | RuntimeException e) {
<font color="green">throw</font> e;
} <font color="green">catch</font> (Exception e) {
<font color="green">throw</font> <font color="green">new</font> <b>UndeclaredThrowableException</b>(e);
}
}</pre></blockquote>
</div>
This method is similar to <a href="#computeIfAbsent(K,java.util.function.Function)"><code>compute­If­Absent(Object, Function)</code></a> except that it can propagate
checked exceptions. If the <code>creator</code> function does not throw any checked exception, then
invoking <code>compute­If­Absent(…)</code> is simpler.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>key</code> - the key for which to get the cached or created value.</dd>
<dd><code>creator</code> - a method for creating a value, to be invoked only if no value are cached for the given key.</dd>
<dt>Returns:</dt>
<dd>the value for the given key, which may have been created as a result of this method call.</dd>
<dt>Throws:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Exception.html" title="class or interface in java.lang" class="external-link">Exception</a></code> - if an exception occurred during the execution of <code>creator​.call()</code>.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="#get(java.lang.Object)"><code>get(Object)</code></a></li>
<li><a href="#peek(K)"><code>peek(Object)</code></a></li>
<li><a href="#computeIfAbsent(K,java.util.function.Function)"><code>compute­If­Absent(Object, Function)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="computeIfAbsent(K,java.util.function.Function)">
<h3 id="computeIfAbsent(java.lang.Object,java.util.function.Function)">computeIfAbsent</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">computeIfAbsent</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/Function.html" title="class or interface in java.util.function" class="external-link">Function</a>&lt;? super <a href="Cache.html" title="type parameter in Cache">K</a>,<wbr>? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;creator)</span></div>
<div class="block">Returns the value for the given key if it exists, or computes it otherwise.
If a value already exists in the cache, then it is returned immediately.
Otherwise the <code>creator​.apply(Object)</code> method is invoked and its result
is saved in this cache for future reuse.
<div class="note"><b>Example:</b>
below is the same code than <a href="#getOrCreate(K,java.util.concurrent.Callable)"><code>get­Or­Create(Object, Callable)</code></a> example,
but without the need for any checked exception handling:
<blockquote><pre><font color="green">private</font> <font color="green">final</font> Cache&lt;String,MyObject&gt; cache = <font color="green">new</font> Cache&lt;String,MyObject&gt;();
<font color="green">public</font> MyObject <b>getMyObject</b>(<font color="green">final</font> String key) {
<font color="green">return</font> cache.<b>computeIfAbsent</b>(key, (k) -&gt; <b>createMyObject</b>(k));
}</pre></blockquote>
</div>
This method is similar to <a href="#getOrCreate(K,java.util.concurrent.Callable)"><code>get­Or­Create(Object, Callable)</code></a>, but without checked exceptions.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#computeIfAbsent(K,java.util.function.Function)" title="class or interface in java.util.concurrent" class="external-link">compute­If­Absent</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">Concurrent­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#computeIfAbsent(K,java.util.function.Function)" title="class or interface in java.util" class="external-link">compute­If­Absent</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - the key for which to get the cached or created value.</dd>
<dd><code>creator</code> - a method for creating a value, to be invoked only if no value are cached for the given key.</dd>
<dt>Returns:</dt>
<dd>the value already mapped to the key, or the newly computed value.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="#peek(K)"><code>peek(Object)</code></a></li>
<li><a href="#containsKey(java.lang.Object)"><code>contains­Key(Object)</code></a></li>
<li><a href="#getOrCreate(K,java.util.concurrent.Callable)"><code>get­Or­Create(Object, Callable)</code></a></li>
<li><a href="#computeIfPresent(K,java.util.function.BiFunction)"><code>compute­If­Present(Object, Bi­Function)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="putIfAbsent(K,V)">
<h3 id="putIfAbsent(java.lang.Object,java.lang.Object)">putIfAbsent</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">putIfAbsent</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;value)</span></div>
<div class="block">If no value is already mapped and no value is under computation for the given key, puts the given value
in the cache. Otherwise returns the current value (potentially blocking until the computation finishes).
A null <code>value</code> argument is equivalent to a no-op. Otherwise a <code>null</code> return value means that
the given <code>value</code> has been stored in the <code>Cache</code>.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#putIfAbsent(K,V)" title="class or interface in java.util.concurrent" class="external-link">put­If­Absent</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">Concurrent­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#putIfAbsent(K,V)" title="class or interface in java.util" class="external-link">put­If­Absent</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - the key to associate with a value.</dd>
<dd><code>value</code> - the value to associate with the given key if no value already exists, or <code>null</code>.</dd>
<dt>Returns:</dt>
<dd>the existing value mapped to the given key, or <code>null</code> if none existed before this method call.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="#get(java.lang.Object)"><code>get(Object)</code></a></li>
<li><a href="#computeIfAbsent(K,java.util.function.Function)"><code>compute­If­Absent(Object, Function)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="put(K,V)">
<h3 id="put(java.lang.Object,java.lang.Object)">put</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">put</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;value)</span></div>
<div class="block">Puts the given value in cache and immediately returns the old value.
A null <code>value</code> argument removes the entry. If a different value is under computation in another thread,
then the other thread may fail with an <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/IllegalStateException.html" title="class or interface in java.lang" class="external-link"><code>Illegal­State­Exception</code></a> unless <a href="#isKeyCollisionAllowed()"><code>is­Key­Collision­Allowed()</code></a>
returns <code>true</code>. For more safety, consider using <a href="#putIfAbsent(K,V)"><code>put­If­Absent(…)</code></a> instead.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#put(K,V)" title="class or interface in java.util" class="external-link">put</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Overrides:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#put(K,V)" title="class or interface in java.util" class="external-link">put</a></code>&nbsp;in class&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">Abstract­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - the key to associate with a value.</dd>
<dd><code>value</code> - the value to associate with the given key, or <code>null</code> for removing the mapping.</dd>
<dt>Returns:</dt>
<dd>the value previously mapped to the given key, or <code>null</code> if no value existed before this
method call or if the value was under computation in another thread.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="#get(java.lang.Object)"><code>get(Object)</code></a></li>
<li><a href="#putIfAbsent(K,V)"><code>put­If­Absent(Object, Object)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="replace(K,V)">
<h3 id="replace(java.lang.Object,java.lang.Object)">replace</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">replace</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;value)</span></div>
<div class="block">If the given key is mapped to any value, replaces that value with the given new value.
Otherwise does nothing. A null <code>value</code> argument removes the entry.
If a different value is under computation in another thread, then the other thread may fail with
an <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/IllegalStateException.html" title="class or interface in java.lang" class="external-link"><code>Illegal­State­Exception</code></a> unless <a href="#isKeyCollisionAllowed()"><code>is­Key­Collision­Allowed()</code></a> returns <code>true</code>.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#replace(K,V)" title="class or interface in java.util.concurrent" class="external-link">replace</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">Concurrent­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#replace(K,V)" title="class or interface in java.util" class="external-link">replace</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - key of the value to replace.</dd>
<dd><code>value</code> - the new value to use in replacement of the previous one, or <code>null</code> for removing the mapping.</dd>
<dt>Returns:</dt>
<dd>the value previously mapped to the given key, or <code>null</code> if no value existed before this
method call or if the value was under computation in another thread.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="#replace(K,V,V)"><code>replace(Object, Object, Object)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="replace(K,V,V)">
<h3 id="replace(java.lang.Object,java.lang.Object,java.lang.Object)">replace</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">replace</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;oldValue,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;newValue)</span></div>
<div class="block">If the given key is mapped to the given old value, replaces that value with the given new value.
Otherwise does nothing. A null <code>value</code> argument removes the entry if the condition matches.
If a value is under computation in another thread, then this method unconditionally returns <code>false</code>.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#replace(K,V,V)" title="class or interface in java.util.concurrent" class="external-link">replace</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">Concurrent­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#replace(K,V,V)" title="class or interface in java.util" class="external-link">replace</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - key of the value to replace.</dd>
<dd><code>old­Value</code> - previous value expected to be mapped to the given key.</dd>
<dd><code>new­Value</code> - the new value to put if the condition matches, or <code>null</code> for removing the mapping.</dd>
<dt>Returns:</dt>
<dd><code>true</code> if the value has been replaced, <code>false</code> otherwise.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="replaceAll(java.util.function.BiFunction)">
<h3>replaceAll</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">replaceAll</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/BiFunction.html" title="class or interface in java.util.function" class="external-link">BiFunction</a>&lt;? super <a href="Cache.html" title="type parameter in Cache">K</a>,<wbr>? super <a href="Cache.html" title="type parameter in Cache">V</a>,<wbr>? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;remapping)</span></div>
<div class="block">Iterates over all entries in the cache and replaces their value with the one provided by the given function.
If the function throws an exception, the iteration is stopped and the exception is propagated. If any value
is under computation in other threads, then the iteration will block on that entry until its computation is
completed.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#replaceAll(java.util.function.BiFunction)" title="class or interface in java.util.concurrent" class="external-link">replace­All</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">Concurrent­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#replaceAll(java.util.function.BiFunction)" title="class or interface in java.util" class="external-link">replace­All</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>remapping</code> - the function computing new values from the old ones.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="computeIfPresent(K,java.util.function.BiFunction)">
<h3 id="computeIfPresent(java.lang.Object,java.util.function.BiFunction)">computeIfPresent</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">computeIfPresent</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/BiFunction.html" title="class or interface in java.util.function" class="external-link">BiFunction</a>&lt;? super <a href="Cache.html" title="type parameter in Cache">K</a>,<wbr>? super <a href="Cache.html" title="type parameter in Cache">V</a>,<wbr>? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;remapping)</span></div>
<div class="block">Replaces the value mapped to the given key by a new value computed from the old value.
If a value for the given key is under computation in another thread, then this method
blocks until that computation is completed. This is equivalent to the work performed
by <a href="#replaceAll(java.util.function.BiFunction)"><code>replace­All(…)</code></a> but on a single entry.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#computeIfPresent(K,java.util.function.BiFunction)" title="class or interface in java.util.concurrent" class="external-link">compute­If­Present</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">Concurrent­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#computeIfPresent(K,java.util.function.BiFunction)" title="class or interface in java.util" class="external-link">compute­If­Present</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - key of the value to replace.</dd>
<dd><code>remapping</code> - the function computing new values from the old ones.</dd>
<dt>Returns:</dt>
<dd>the new value associated with the given key.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="#computeIfAbsent(K,java.util.function.Function)"><code>compute­If­Absent(Object, Function)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="compute(K,java.util.function.BiFunction)">
<h3 id="compute(java.lang.Object,java.util.function.BiFunction)">compute</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">compute</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/BiFunction.html" title="class or interface in java.util.function" class="external-link">BiFunction</a>&lt;? super <a href="Cache.html" title="type parameter in Cache">K</a>,<wbr>? super <a href="Cache.html" title="type parameter in Cache">V</a>,<wbr>? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;remapping)</span></div>
<div class="block">Replaces the value mapped to the given key by a new value computed from the old value.
If there is no value for the given key, then the "old value" is taken as <code>null</code>.
If a value for the given key is under computation in another thread, then this method
blocks until that computation is completed. This method is equivalent to
<a href="#computeIfPresent(K,java.util.function.BiFunction)"><code>compute­If­Present(…)</code></a> except that a new value will be computed
even if no value existed for the key before this method call.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#compute(K,java.util.function.BiFunction)" title="class or interface in java.util.concurrent" class="external-link">compute</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">Concurrent­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#compute(K,java.util.function.BiFunction)" title="class or interface in java.util" class="external-link">compute</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - key of the value to replace.</dd>
<dd><code>remapping</code> - the function computing new values from the old ones, or from a <code>null</code> value.</dd>
<dt>Returns:</dt>
<dd>the new value associated with the given key.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="#computeIfAbsent(K,java.util.function.Function)"><code>compute­If­Absent(Object, Function)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="merge(K,V,java.util.function.BiFunction)">
<h3 id="merge(java.lang.Object,java.lang.Object,java.util.function.BiFunction)">merge</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">merge</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key,
<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;value,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/BiFunction.html" title="class or interface in java.util.function" class="external-link">BiFunction</a>&lt;? super <a href="Cache.html" title="type parameter in Cache">V</a>,<wbr>? super <a href="Cache.html" title="type parameter in Cache">V</a>,<wbr>? extends <a href="Cache.html" title="type parameter in Cache">V</a>&gt;&nbsp;remapping)</span></div>
<div class="block">Maps the given value to the given key if no mapping existed before this method call,
or computes a new value otherwise. If a value for the given key is under computation
in another thread, then this method blocks until that computation is completed.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#merge(K,V,java.util.function.BiFunction)" title="class or interface in java.util.concurrent" class="external-link">merge</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">Concurrent­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#merge(K,V,java.util.function.BiFunction)" title="class or interface in java.util" class="external-link">merge</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - key of the value to replace.</dd>
<dd><code>value</code> - the value to associate with the given key if no value already exists, or <code>null</code>.</dd>
<dd><code>remapping</code> - the function computing a new value by merging the exiting value
with the <code>value</code> argument given to this method.</dd>
<dt>Returns:</dt>
<dd>the new value associated with the given key.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="remove(java.lang.Object)">
<h3>remove</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">remove</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;key)</span></div>
<div class="block">Removes the value mapped to the given key in the cache. If a value is under computation in another thread,
then the other thread may fail with an <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/IllegalStateException.html" title="class or interface in java.lang" class="external-link"><code>Illegal­State­Exception</code></a> unless <a href="#isKeyCollisionAllowed()"><code>is­Key­Collision­Allowed()</code></a>
returns <code>true</code>. For more safety, consider using <a href="#remove(java.lang.Object,java.lang.Object)"><code>remove(Object, Object)</code></a> instead.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#remove(java.lang.Object)" title="class or interface in java.util" class="external-link">remove</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Overrides:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#remove(java.lang.Object)" title="class or interface in java.util" class="external-link">remove</a></code>&nbsp;in class&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">Abstract­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - the key of the value to removed.</dd>
<dt>Returns:</dt>
<dd>the value previously mapped to the given key, or <code>null</code> if no value existed before this
method call or if the value was under computation in another thread.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="#get(java.lang.Object)"><code>get(Object)</code></a></li>
<li><a href="#remove(java.lang.Object,java.lang.Object)"><code>remove(Object, Object)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="remove(java.lang.Object,java.lang.Object)">
<h3>remove</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">remove</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;key,
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;oldValue)</span></div>
<div class="block">If the given key is mapped to the given old value, removes that value. Otherwise does nothing.
If a value is under computation in another thread, then this method unconditionally returns <code>false</code>.</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html#remove(java.lang.Object,java.lang.Object)" title="class or interface in java.util.concurrent" class="external-link">remove</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentMap.html" title="class or interface in java.util.concurrent" class="external-link">Concurrent­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#remove(java.lang.Object,java.lang.Object)" title="class or interface in java.util" class="external-link">remove</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - key of the value to remove.</dd>
<dd><code>old­Value</code> - previous value expected to be mapped to the given key.</dd>
<dt>Returns:</dt>
<dd><code>true</code> if the value has been removed, <code>false</code> otherwise.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list">
<li><a href="#get(java.lang.Object)"><code>get(Object)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="containsKey(java.lang.Object)">
<h3>containsKey</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">containsKey</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>&nbsp;key)</span></div>
<div class="block">Returns <code>true</code> if this map contains the specified key.
If the value is under computation in another thread, this method returns <code>true</code>
without waiting for the computation result. This behavior is consistent with other
<code>Map</code> methods in the following ways:
<ul>
<li><a href="#get(java.lang.Object)"><code>get(Object)</code></a> blocks until the computation is completed.</li>
<li><a href="#put(K,V)"><code>put(Object, Object)</code></a> returns <code>null</code> for values under computation,
i.e. behaves as if keys are temporarily mapped to the <code>null</code> value until
the computation is completed.</li>
</ul></div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#containsKey(java.lang.Object)" title="class or interface in java.util" class="external-link">contains­Key</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Overrides:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#containsKey(java.lang.Object)" title="class or interface in java.util" class="external-link">contains­Key</a></code>&nbsp;in class&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">Abstract­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Parameters:</dt>
<dd><code>key</code> - the key to check for existence.</dd>
<dt>Returns:</dt>
<dd><code>true</code> if the given key is mapped to an existing value or a value under computation.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list">
<li><a href="#get(java.lang.Object)"><code>get(Object)</code></a></li>
<li><a href="#peek(K)"><code>peek(Object)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="peek(K)">
<h3 id="peek(java.lang.Object)">peek</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.html" title="type parameter in Cache">V</a></span>&nbsp;<span class="element-name">peek</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key)</span></div>
<div class="block">If a value is already cached for the given key, returns it. Otherwise returns <code>null</code>.
This method is similar to <a href="#get(java.lang.Object)"><code>get(Object)</code></a> except that it doesn't block if the value is
in process of being computed in another thread; it returns <code>null</code> in such case.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>key</code> - the key for which to get the cached value.</dd>
<dt>Returns:</dt>
<dd>the cached value for the given key, or <code>null</code> if there is none.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list">
<li><a href="#get(java.lang.Object)"><code>get(Object)</code></a></li>
<li><a href="#lock(K)"><code>lock(Object)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="lock(K)">
<h3 id="lock(java.lang.Object)">lock</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="Cache.Handler.html" title="interface in org.apache.sis.util.collection">Cache.Handler</a>&lt;<a href="Cache.html" title="type parameter in Cache">V</a>&gt;</span>&nbsp;<span class="element-name">lock</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">K</a>&nbsp;key)</span></div>
<div class="block">Gets a lock for the entry at the given key and returns a handler to be used by the caller
for unlocking and storing the result. This method <strong>must</strong> be used together
with a <a href="Cache.Handler.html#putAndUnlock(V)"><code>put­And­Unlock</code></a> call in <code>try</code><code>catch</code>
blocks as in the example below:
<blockquote><pre>Cache.Handler handler = cache.<b>lock</b>();
<font color="green">try</font> {
<i><font color="gray">// Compute the result...</font></i>
} <font color="green">finally</font> {
handler.<b>putAndUnlock</b>(result);
}</pre></blockquote></div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>key</code> - the key for the entry to lock.</dd>
<dt>Returns:</dt>
<dd>a handler to use for unlocking and storing the result.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="keySet()">
<h3>keySet</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Set.html" title="class or interface in java.util" class="external-link">Set</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>&gt;</span>&nbsp;<span class="element-name">keySet</span>()</div>
<div class="block">Returns the set of keys in this cache. The returned set is subjects to the same caution
than the ones documented in the <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentHashMap.html#keySet()" title="class or interface in java.util.concurrent" class="external-link"><code>Concurrent­Hash­Map​.key­Set()</code></a> method.
<p>If some elements are removed from the key set, then <a href="#flush()"><code>flush()</code></a> should be invoked after removals.
This is not done automatically by the returned set. For safety, the <a href="#remove(java.lang.Object)"><code>remove(Object)</code></a> methods defined
in the <code>Cache</code> class should be used instead.</p></div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#keySet()" title="class or interface in java.util" class="external-link">key­Set</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Overrides:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#keySet()" title="class or interface in java.util" class="external-link">key­Set</a></code>&nbsp;in class&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">Abstract­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Returns:</dt>
<dd>the set of keys in this cache.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list">
<li><a href="#flush()"><code>flush()</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="entrySet()">
<h3>entrySet</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Set.html" title="class or interface in java.util" class="external-link">Set</a>&lt;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.Entry.html" title="class or interface in java.util" class="external-link">Map.Entry</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;&gt;</span>&nbsp;<span class="element-name">entrySet</span>()</div>
<div class="block">Returns the set of entries in this cache. The returned set is subjects to the same caution
than the ones documented in the <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/concurrent/ConcurrentHashMap.html#entrySet()" title="class or interface in java.util.concurrent" class="external-link"><code>Concurrent­Hash­Map​.entry­Set()</code></a> method, except that
it does not support removal of elements (including through the <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Iterator.html#remove()" title="class or interface in java.util" class="external-link"><code>Iterator​.remove()</code></a>
method call).</div>
<dl class="notes">
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#entrySet()" title="class or interface in java.util" class="external-link">entry­Set</a></code>&nbsp;in interface&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html" title="class or interface in java.util" class="external-link">Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Specified by:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html#entrySet()" title="class or interface in java.util" class="external-link">entry­Set</a></code>&nbsp;in class&nbsp;<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/AbstractMap.html" title="class or interface in java.util" class="external-link">Abstract­Map</a>&lt;<a href="Cache.html" title="type parameter in Cache">K</a>,<wbr><a href="Cache.html" title="type parameter in Cache">V</a>&gt;</code></dd>
<dt>Returns:</dt>
<dd>a view of the entries contained in this map.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="isKeyCollisionAllowed()">
<h3>isKeyCollisionAllowed</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">isKeyCollisionAllowed</span>()</div>
<div class="block">Returns <code>true</code> if different values may be assigned to the same key.
The default value is <code>false</code>.</div>
<dl class="notes">
<dt>Returns:</dt>
<dd><code>true</code> if key collisions are allowed.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="setKeyCollisionAllowed(boolean)">
<h3>setKeyCollisionAllowed</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">setKeyCollisionAllowed</span><wbr><span class="parameters">(boolean&nbsp;allowed)</span></div>
<div class="block">If set to <code>true</code>, different values may be assigned to the same key. This is usually an
error, so the default <code>Cache</code> behavior is to thrown an <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/IllegalStateException.html" title="class or interface in java.lang" class="external-link"><code>Illegal­State­Exception</code></a>
in such cases, typically when <a href="Cache.Handler.html#putAndUnlock(V)"><code>Cache​.Handler​.put­And­Unlock(Object)</code></a> is invoked. However, in
some cases we may want to relax this check. For example, the EPSG database sometimes assigns
the same key to different kinds of objects.
<p>If key collisions are allowed and two threads invoke <a href="#lock(K)"><code>lock(Object)</code></a> concurrently
for the same key, then the value to be stored in the map will be the one computed by the
first thread who got the lock. The value computed by any other concurrent thread will be
ignored by this <code>Cache</code> class. However, those threads still return their computed
values to their callers.</p>
<p>This property can also be set in order to allow some recursivity. If during the creation
of an object, the program asks to this <code>Cache</code> for the same object (using the same key),
then the default <code>Cache</code> implementation will consider this situation as a key collision
unless this property has been set to <code>true</code>.</p></div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>allowed</code> - <code>true</code> if key collisions should be allowed.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="cost(V)">
<h3 id="cost(java.lang.Object)">cost</h3>
<div class="member-signature"><span class="modifiers">protected</span>&nbsp;<span class="return-type">int</span>&nbsp;<span class="element-name">cost</span><wbr><span class="parameters">(<a href="Cache.html" title="type parameter in Cache">V</a>&nbsp;value)</span></div>
<div class="block">Computes an estimation of the cost of the given value. The default implementation returns 1
in all cases. Subclasses should override this method if they have some easy way to measure
the relative cost of value objects.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>value</code> - the object for which to get an estimation of its cost.</dd>
<dt>Returns:</dt>
<dd>the estimated cost of the given object.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.instrument/java/lang/instrument/Instrumentation.html#getObjectSize(java.lang.Object)" title="class or interface in java.lang.instrument" class="external-link"><code>Instrumentation​.get­Object­Size(Object)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="flush()">
<h3>flush</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">flush</span>()</div>
<div class="block">Forces the removal of all garbage collected values in the map.
This method should not need to be invoked when using <code>Cache</code> API.
It is provided as a debugging tools when suspecting a memory leak.</div>
<dl class="notes">
<dt>Returns:</dt>
<dd><code>true</code> if some entries have been removed as a result of this method call.</dd>
<dt>Since:</dt>
<dd>1.3</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list">
<li><a href="#keySet()"><code>key­Set()</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>
</ul>
</section>
<!-- ========= END OF CLASS DATA ========= -->
</main>
<footer role="contentinfo">
<hr>
<p class="legal-copy"><small>Copyright &#169; 2010&#x2013;2022 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p>
</footer>
</div>
</div>
</body>
</html>